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

2016/6/1

At World Edge

ssenese19 ssenese19

2016/6/1

#
Hi! Any suggestions at how to properly code a game so that an object hits the edge of the world and bounces back? I can't seem to locate anything in my Greenfoot textbook that would be compatible with my game. Thanks! (High School COMPSCI Student)
danpost danpost

2016/6/1

#
ssenese19 wrote...
Hi! Any suggestions at how to properly code a game so that an object hits the edge of the world and bounces back? I can't seem to locate anything in my Greenfoot textbook that would be compatible with my game. Thanks! (High School COMPSCI Student)
What code are you using for the object you want to have bounce off the edges?
ssenese19 ssenese19

2016/6/1

#
I'm trying to have a Ladybug object move about the screen, and when it hits the edge bounce back into the world. I'm pretty new to Java, so sorry if I'm not explaining quite well! @danpost
danpost danpost

2016/6/1

#
ssenese19 wrote...
I'm trying to have a Ladybug object move about the screen, and when it hits the edge bounce back into the world. I'm pretty new to Java, so sorry if I'm not explaining quite well! @danpost
In order to be sure to give a suggestion that is compatible with your game, you will need to post a copy of the code within the Ladybug class.
ssenese19 ssenese19

2016/6/1

#
public void act() { move(4); is atWorldEdge(turn 90); } This is what I was thinking...I know it's basic code, but sadly I'm not the most proficient. Thanks for the help! @danpost
danpost danpost

2016/6/1

#
Well, in order for that to compile (so you could see what behavior you have achieved), the line would need to be changed to this:
1
if (atWorldEdge()) turn(90);
You need to login to post a reply.