This site requires JavaScript, please enable it in your browser!
Greenfoot back
ZiweZhang
ZiweZhang wrote ...

2018/3/6

getoneobjectatoffset

ZiweZhang ZiweZhang

2018/3/6

#
How can I use getoneobjectatoffset with a variable instead of a class?
Vercility Vercility

2018/3/6

#
You cant Wth should that do?
ZiweZhang ZiweZhang

2018/3/6

#
I have 2 houses and 2 players and both need to go to one house to complete the level
ZiweZhang ZiweZhang

2018/3/6

#
i can send my game if you want to look at it
Super_Hippo Super_Hippo

2018/3/6

#
//Player class
private int ID;
public Player(int id)
{
    ID = id;
}

public void act()
{
    //move
    House h = getOneIntersectingObject(House.class);
    if (h != null)
    {
        if (h.getID() == ID) //correct house
        {
            //....
        }
    }
}

public int getID()
{
    return ID;
}
//House class
private int ID;
public House(int id)
{
    ID = id;
}

public int getID()
{
    return ID;
}
//in World subclass when you create the players and houses
addObject(new Player(0), 100, 100);
addObject(new Player(1), 200, 200);
addObject(new House(0), 200, 100);
addObject(new House(1), 100, 200);
//x and y values are examples
ZiweZhang ZiweZhang

2018/3/6

#
thank you
You need to login to post a reply.