Presentation is loading. Please wait.

Presentation is loading. Please wait.

Greenfoot Asteroids Mrs. C. Furman August 16, 2010.

Similar presentations


Presentation on theme: "Greenfoot Asteroids Mrs. C. Furman August 16, 2010."— Presentation transcript:

1 Greenfoot Asteroids Mrs. C. Furman August 16, 2010

2 Open Asteroids Open Greenfoot.
Open Scenario, “asteroids1” in the chapter01 folder in book scenarios.

3 Class Diagram In Greenfoot, you always have a World class.
Space is a specific class made for this scenario World Classes

4 Inheritance In greenfoot you always a more specific class under World.
The arrow between the class represents an is-a relationship. Space is-a World. Space is a subclass of World.

5 More on World When we open a scenario, greenfoot automatically creates an object of the World subclass, in this case Space. That is why the black screen automatically pops up.

6 Actor Classes Under the World classes is the set of Actor classes.
How many subclasses of Mover are there? What are the subclasses of Actor?

7 Subclass Bullet, Rocket, and Asteroid are subclasses of Mover
Explosion and Mover are subclasses of Actor While Bullet, Rocket and Asteroid are all subclasses of Mover as well as Actor, but are NOT subclasses of Explosion

8 Subclass and Superclass
Superclasses – these classes are less specific Subclasses – these classes inherit the traits of the superclass, and then expands on them. Subclasses are BIGGER than Superclasses.

9 Other Classes Vector – helper class
We can not place objects of it into the World.

10 Playing with Asteroids
We can only create objects of classes that do not have subclasses. Which classes can we create objects for? Place objects into the World, then click run. Use the arrow keys to move your spaceship and space bar to fire shots.

11 Exercise 1 After you’ve played the game for a little bit. Lets tweak it! Invoke the setGunReloadTime method and set the reload time to 5. Then play again.

12 Exercise 2 Stop the execution by pressing pause.
Find out how many shots you have fired. Invoke a Rocket method.

13 Exercise 3 You will notice that the rocket moves a bit as soon as you place it into the World. What is its initial speed?

14 Exercise 4 Asteroids have an inherent stability. Each time they get hit by a bullet, their stability decreases. When it reaches zero, they break up. What is their initial stability value after you create them?

15 Exercise 4B By how much does the stability decrease from a single hit by a bullet? Just shoot an asteroid once, and then check the stability again.

16 Constructors Asteroids have 2 constructor methods
Constructors are used to set up the object. new Asteroid() – called a default constructor. Sets it to a default size new Asteroid(int size) – allows us to set the size of the Asteroid by passing an integer.

17 Exercise 5 Make a very big asteroid. Make a very small asteroid.

18 Variables In Java, we often want to store values.
We see this in our gun speed. We used setGunReloadTime and passed a value in order to be saved by the variable speed. These values are stored in variables.

19 Variable names… Identifiers
When we name a variable we need to use a “proper identifier”. Here are the rules for proper identifiers: Must start with a letter. As a convention, it starts with a lowercase letter Must contain only numbers, letter or underscores Must not be a keyword. Like new.

20 Java is Case Sensitive Java is what we call case sensitive. Which means that it distinguishes between upper and lower case letters differently.

21 Assignment Statements
We can assign values to our variables with assignment statements. Variable has to be on the left, value you are giving to the variable is on the right. variable = 8; Variable Name Value that is being given to the variable Assignment Operator

22 Source Code Behavior of each Object is defined by its class.
Source code – the code that specifies all the details about a class and its objects. Select Open editor for the Rocket class, or double click on the Rocket class to open the source code.

23 Rocket Source Code We can change the reload speed on all Rockets in the source code. Change getReloadTime to 5. Recompile.


Download ppt "Greenfoot Asteroids Mrs. C. Furman August 16, 2010."

Similar presentations


Ads by Google