Hello,
I am making a game in which a little character has to go to the left or to the right and avoid little balls. The character is actually not moving, but the ground underneath is. When the edge of the ground reaches the side of the screen, it stops moving even if the arrow key is pressed. When the ground is moving, the balls are also moving faster or slower to move with the ground as reference. My problem is that when the ground has reached the side of the screen and is not moving anymore, the balls should move normally again, but if the arrow key is pressed, they move as they should when the ground is moving (except the ground is not moving anymore here). Hoy can I make them move normally in that situation when the ground doesn't move but the arrow key is pressed?
Here is my code in the ball class:
Thanks in advance :)
if(Greenfoot.isKeyDown("right")){ if(groundLoc <= (600 - groundWidth / 2)){ this.setLocation(this.getX() + speedX, this.getY() + speedY); } else{ this.setLocation(this.getX() + speedX - 5, this.getY() + speedY); } } if(Greenfoot.isKeyDown("left")){ if(groundLoc >= (groundWidth / 2)){ this.setLocation(this.getX() + speedX, this.getY() + speedY); } else{ this.setLocation(this.getX() + speedX + 5, this.getY() + speedY); } } this.setLocation(this.getX() + speedX, this.getY() + speedY);