I've been playing around with my code trying to make the ball in my program move though to be specific the scenario is a ball maze game where I have to make it so the ball moves 1 square at a time until I reach the goal block at the end however the ball must not move off the maze.
So I wanted to know what do i have to change/add in the following code to make it so my ball can move one space at a time in the directions left,right,up and down with the following code:
public void key(){
int leftChange=0;
int rightChange=0;
int upChange=0;
int downChange=0;
if (Greenfoot.isKeyDown("left")){
if (canMove(leftChange, 0)==true)
setLocation(getX()+leftChange, getY()) ;
}
if (Greenfoot.isKeyDown("right")){
if (canMove(rightChange, 0)==true)
setLocation(getX()+rightChange, getY()) ;
}
if (Greenfoot.isKeyDown("up")){
if (canMove(0, upChange)==true)
setLocation(getX(), getY()+upChange) ;
}
if (Greenfoot.isKeyDown("down")){
if (canMove(0, downChange)==true)
setLocation(getX(), getY()+downChange) ;
}
}
Again I would appreciate the help very much ^_^.