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

2014/7/9

I'm have problems making a flower blink

meganw21 meganw21

2014/7/9

#
I need to write code to make a flower blink continuously. And I also need a way to make a crab slow down to "smell" the flower when it goes by it.
sengst sengst

2014/7/9

#
To make the flower blink continuously you can use an if statement and a variable. For instance: int timeTillBlink = 0; if ( timeTillBlink >= 10 ) { blink(); // does whatever blink does. timeTillBlink = 10; // resets timeTillBlink to ten or whatever number you would like. } else timeTillBlink--; // ( same as timeTillBlink = timeTillBlink - 1 ) delays the blink process by ___ number of act cycles. To have the crab slow down, you can also use an if statement: int time2moveOn = 5; if ( isTouching( flower.class ) & time2moveOn > 0 ) // time2moveOn will stop the crab from smelling the flower { smell(); // can do something to show it smelled the flower, not needed. time2moveOn--; // starts counting down for the crab to continue. } else move( speed ); // move the crab if not next to a flower. you can define speed. Of course you can have the flower blink less often by making timeTillBlink larger and have the crab move on faster by making time2moveOn less. I hope this helps!
dhollan8 dhollan8

2014/7/10

#
I am getting an error message on the if (timeTillBlink>=10) Illegal start of type
dhollan8 dhollan8

2014/7/10

#
Never mind, I figured it out.
sengst sengst

2014/7/13

#
Ok, great!
You need to login to post a reply.