Greenfoot: Balloons

BalloonWorld

What does this line do: 'Counter counter = new Counter("Score: ");'  ?

What are the screen settings for BalloonWorld?

Where is the value of y=0 on the screen? What is the maximum value of y and how is this calculated?

What is the condition for stopping a game?

In BalloonWorld, what does the setPaintOrder method do?

Give the code for making a random number. What range of random numbers does (100) produce?

Where is the getRandomNumber function kept? How is it accessed in code like BalloonWorld? (Use the API guide to help answer this.)

Under what condition is a new balloon added to the game? How do you increase or decrease the number of balloons? What effect does this have on the game?

Give the line of code for adding a new balloon to the Greenfoot screen. What does 'new Balloon()' refer to? What does '600' refer to? (Note that in classes of type Actor you will need getWorld().addObject.)

What does this line do: counter.add(20) ?

Change the scoring system to 1 point per balloon.

What type of Java objects are ScoreBoard, Bomb and Dart?

Add a new bomb and change the position of all the bombs to the top right of the screen.

Extension:

What type of object is 'counter'? Check the Helper classes page for your answer. (The Counter class is available at the Helper classes page and can be copied directly into a new subclass of Actor. A counter can then be created from the constructor and methods supplied. Note that the call in BalloonWorld to the Counter constructor includes a parameter "Score: ", which is picked up by the parameter 'String prefix' in the constructor declaration. You don't need to understand Counter fully but studying it will do no harm.)

How is the score updated when a balloon is popped?

How would you add a ScoreBoard to another application?

Actors

The Balloon

What does this line do: setLocation(getX(), getY() - 1); ?

What condition causes the game to finish?

Write out the line that closes the game.

Give an example of how a sound can be played.

Extension:

How is a score of popped balloons kept?

Which object is removed by the line getWorld().removeObject(this); ?

The Dart

Dart makes use of the Greenfoot and mouseInfo classes. The Greenfoot class includes:

These return Boolean values for use in if statements.

These methods are often called from an Actor's act method using the parameter this. The parameter could also be the World object (checks if the mouse action took place where there were no actors) or null, which just checks whether the action happened regardless of whether the mouse was over an actor.

The mouseInfo class returns information about the mouse such as its x and y coordinates, how many times a button was pressed and which button was pressed.

What does this line do: "MouseInfo mouse = Greenfoot.getMouseInfo();" ?

Explain the line "setLocation(mouse.getX(), mouse.getY() );"

What does this line do: "if (Greenfoot.mouseClicked(null)) { " ?

What does this line do: "Balloon balloon = (Balloon) getOneObjectAtOffset(x,y, Balloon.class);" ?

The Bomb

Describe the behaviour of a bomb: what does it do? (In simple game terms)

What does the first if statement do inside Bomb.act?

What does the second if statement do inside Bomb.act?

What makes a bomb go explode? How is this coded?

What causes a bomb to return unexploded to its original location?

The Counter

Counter is based on a helper class that has been modified.

Where is the counter for a game created and how is it created?

How is the counter updated when a balloon is popped?

The ScoreBoard

Summarise how a score board is made for the game. How is a basic score board made? How is it filled in?

The Explosion

This too is based on a helper class. There is a video tutorial about explosions on the Greenfoot web site.

Own Scenario 2: Mouse Actions

Use the Using Mouse Input video  to help you with this exercise.

Write a scenario where an object follows the mouse. When the mouse is pressed over the object it should change to another image and when the button is released it should change back to the original image.

Own Scenario 3: More Mouse Actions

Use the Using Mouse Input video  to help you with this exercise.

Create a new scenario that includes an object that moves when you move the mouse over it and duplicates when you click the background.

The new object should be placed at a random location (use getRandomNumber, getWorld.addObject). Use the API guide to help you.

The code relating to moving the object should be placed in the act method for that object while the code for creating the new objects should be placed in the act method of the background. Note that in the Frog object you need to write the getWorld prefix in front of getWidth, getHeight and addObject because you are working in an Actor class. In the World method the getWorld prefix is not required because you are working in the World class where they are defined.

Adjust the code so that the new object is added at the point that the mouse was clicked (use getMouseInfo to give access to mouse.getX and mouse.getY).

What does this line do:

MouseInfo mouse = Greenfoot.getMouseInfo();

How do we add a new object at the point where the mouse was clicked:

addObject (new frog(), mouse.getX(), mouse.getY());

Own Scenario 4: Asteroids

Change the direction of the balloons so they start at the top of the screen and move downwards. This is a matter of changing a minus to a plus and one number.

Change the symbol of the balloon to something more suited to 'Asteroids'.

Add a new symbol along the bottom of the screen that moves left and right with keyboard input. Create a new class and add a line to the BalloonWorld code to make one appear at the bottom of the screen.

Write code that fires a missile from the symbol at the bottom of the screen in response to a key press.

Find a way to limit the number of missiles that can be fired.

Write code that detects a collision between the missile and the ex-balloons and awards points.

Devise a way of making the game harder as it progresses.

Devise a way of finishing the game.