hey guys, for a game I program in need to make my objects move only 1 cell in a cross. therefore i want to use the getNeighbours method to check if there are other objects in this cells and if not the object can move there. my problem is that i use the mouseDrag methods to move my objects and i have no idea how i can limit the movement to 1 cell in each direction.
my movement code looks like this
the wechsel.spieler and wechsel.phase are for the turns of the players.
hope you can help me and if u need more to help me, just ask
public void bewegen2()
{
if(Greenfoot.mouseDragged(this) && wechsel.spieler == 2 && wechsel.phase ==2 )
{
MouseInfo info = Greenfoot.getMouseInfo();
setLocation(info.getX(), info.getY());
}
if(Greenfoot.mouseDragEnded(this) && wechsel.spieler == 2 && wechsel.phase == 2 )
{
MouseInfo info = Greenfoot.getMouseInfo();
setLocation(info.getX(), info.getY());
wechsel.spieler = 1 ;
}
}
