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

2014/12/10

How do I make an object keep moving at the world's edge?

pmerrill21 pmerrill21

2014/12/10

#
I am making a frogger like video game on greenfoot, and I have a car that bounces off one wall and heads to the other but once it reaches the other wall it stops instead of going back an forth between the walls, what should I do? here is my code. public void act() { if(canSee(Frogger.class)) { eat(Frogger.class); Greenfoot.playSound("au.wv"); } else{ move(7); } if(atWorldEdge()){ setRotation(180); } } }
danpost danpost

2014/12/10

#
The line 'setRotation(180)' is one directional. It will never set the rotation back to zero.
pmerrill21 pmerrill21

2014/12/10

#
How would I be able to make the car go back and forth?
danpost wrote...
The line 'setRotation(180)' is one directional. It will never set the rotation back to zero.
danpost danpost

2014/12/10

#
pmerrill21 wrote...
How would I be able to make the car go back and forth?
danpost wrote...
The line 'setRotation(180)' is one directional. It will never set the rotation back to zero.
Either use:
turn(180);
// or
setRotation(getRotation()+180);
You need to login to post a reply.