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

Report as inappropriate.

Dallas123
Dallas123 presents ...

2018/11/5

Asteroids Game

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.

9.18

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.

9.19
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.

4373 views / 15 in the last 7 days

Tags: with-source

open in greenfoot
Your browser is ignoring the <APPLET> tag.

No Comments

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

Who likes this?

No votes yet.