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

2014/5/8

How would I code this?

iSuckAtGreenfoot iSuckAtGreenfoot

2014/5/8

#
I basically need to code the following scenario: Store an assigned image of pizza into a variable. I must then make a bunch of said pizza's fall from the sky at the same time but at different speeds (from one to 3). As they fall they must rotate a bit (more like a wiggle). Once they hit the ground they dissapear from the screen. I don't even know where to begin so if someone is bored at work or just looking for something to do any kind of help with the coding would be greatly appreciated.
danpost danpost

2014/5/8

#
Create a subclass of Actor called Pizza. Add a static field to hold a GreenfootImage object that is to be the image of all the Pizza objects. Add another field, not static this time, to hold an int value that is to be the speed of a Pizza object ('static' goes for all and not 'static' goes for each). Have the Pizza constructor block set that value of the int field (for its speed) to a random number between 1 and 3 and set the image of the Pizza object to the image saved in the image field. Add an act method whose code (1) moves the object down the screen using the value of the int speed; (2) adds a random turn; and (3) checks its y value and compares it with the last y row at the bottom of the screen; and if they are the same value, it removes itself from the world. In the world class act method: If no Pizza objects are in the world, iterate through a loop to add a bunch of Pizza objects at a random x coordinate and a low y coordinate (or zero) into the world.
You need to login to post a reply.