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

Report as inappropriate.

Borf presents ...


Answers to Questions for asteroids

In our asteroids game, we have added comments to help you in completing exercises 9.18, 9.19, 9.20, 9.21, and 9.22.


The createStars() method accomplishes every needed to fill the background with stars. For the amount of stars you wrote when calling the method, it will create ovals with varying colors at random points across the game, all of which will be different sizes.

int color = 120 - Greenfoot.getRandomNumber(100);

This variable is used to generate random number values to be used in the RGB values of the oval we created in 9.18. Using the same variable for the red, blue, and green values alike creates a grey shade, but using random numbers will make the brightness vary.

9.20 -the checkKeys() method handles keyboard input. This includes any movements that you control involving the rocket.

9.21 - The if statement that makes the rocket turn left when you press on the left key is saying that when you press the left key on the keyboard, the rocket will turn left 5 degrees in every act cycle.

9.22 - The Rocket will turn right when you press the right arrow key on the keyboard.

1080 views / 457 in the last 7 days

Tags: None

Your browser does not support the canvas tag.

No Comments

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.