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

2013/5/27

CODE Help

FCG FCG

2013/5/27

#
How can I make my "airplane" class to follow my 'player" while the airplane is in the air dropping bombs randomly , but wait 5 seconds before next bomb and have a maximum wait time of 10 seconds.
MaxAlbert MaxAlbert

2013/5/27

#
To have your airplane follow your player you could set up a public variable of the players coordinates and every act method move the plane to those coordinates (or some distance around those coordinates). For the bomb dropping you are going to have to use a method called Greenfoot.getRandomNumber(6); which returns a random number between 0 and 5 (because 5 is one less than what you pass to the method in this case 6) and all you have to do is add 5 to the random number you get and wait that long before you have the plane drop the next bomb.
MaxAlbert MaxAlbert

2013/5/27

#
*drops
FCG FCG

2013/5/27

#
MaxAlbert wrote...
To have your airplane follow your player you could set up a public variable of the players coordinates and every act method move the plane to those coordinates (or some distance around those coordinates). For the bomb dropping you are going to have to use a method called Greenfoot.getRandomNumber(6); which returns a random number between 0 and 5 (because 5 is one less than what you pass to the method in this case 6) and all you have to do is add 5 to the random number you get and wait that long before you have the plane drop the next bomb.
Could you write some of the code, I'm not that good.
danpost danpost

2013/5/27

#
FCG, you are going to have to learn to write some of the code yourself. At least give something a try and if you have trouble, post what you have tried and explain what you want to happen as compared to what is happening as it is currently coded. Much can be learned from the Greenfoot and Java tutorials alone.
You need to login to post a reply.