I'm trying to make a game where if you touch the orange you're speed goes up a little and then goes back to normal. But when I made it, the speed goes up, but it doesn't go down after a little. Can you help me? here's my code
public class Player extends Actor
{
int speed = 2;
int repeat = 0;
/**
* Act - do whatever the Player wants to do. This method is called whenever the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("right")) {
setLocation(getX()+speed,getY());
setRotation(0);
}
if (Greenfoot.isKeyDown("left")) {
setLocation(getX()-speed,getY());
setRotation(180);
}
if (Greenfoot.isKeyDown("up")) {
setLocation(getX(),getY()-speed);
setRotation(-90);
}
if (Greenfoot.isKeyDown("down")) {
setLocation(getX(),getY()+speed);
setRotation(90);
}
if (isTouching(Orange.class)) {
if (repeat<50) {
speed=3;
repeat++;
}
else {
speed=2;
repeat=0;
}
}
}
}
