Dana Vrajitoru
B583/C490 Game Programming and Design

Homework 5

Due Date: Thursday, October 6, 2011.

In this homework we'll add a few more features to the shooter game. Download the following images and import them to the library under the class names Rocket1Bmp and Rocket2Bmp:
rocket1.png
rocket2.png

Ex. 1. Object animation. In the class Rocket add a variable called rocketFrame and turn the rocketSprite variable into an array of 4 sprites. The first of them (for 0) should be identical to the sprite we created for the rocket before. The second and fourth sprites should be based on the image rocket1.png and the third one on rocket2.png. Make all the sprites invisible except for the first one.

Modify the function placeRocket to set the x and y coordinates of all the rocket sprites with these new values.

Add an animation timer to the rocket class and make it cycle through the sprites. In the callback function for this timer, make the sprite with the index equal to rocketFrame invisible, then increment the frame number in a cyclic way (go back to 0 when you reach 4), and make the sprite with the index equal to the new frame number visible.

Ex. 2. Multiple scenes. From the Insert menu, add a new Scene. In the Actions panel you should now see the second scene listed. Cut the entire code from Scene 1, Frame 1, and paste it into Scene 2.

In the stage area in Scene 1, add a button and label it Play. Give the instance name to this button playBtn. Then in the code area for Scene 1, add the following code:

stop();

playBtn.addEventListener(MouseEvent.MOUSE_DOWN, switchToPlayScene);

function switchToPlayScene(event:MouseEvent):void
{
	gotoAndStop(1, "Scene 2");
}

Add a title to the game in Scene 1 and whatever else you want as decoration to this introduction panel. Add another button labeled Instructions. Create another scene containing some text with the instructins for the game and a button labeled OK and make the button send the execution back to Scene 1. This means that you need to have 3 scenes total in the game.

Ex. 3. Levels. In the Rocket class add a variable for a number of spare lives and initialize it as 1 in the constructor. Display this information in a text box at the top right of the stage with the label Lives in front of it. Modify the collision detection such that when the rocket collides with a bomb the game is lost only when the number of lives is 0, and otherwise the number of lives is decremented by 1.

Add another variable in the class for the level number, initialize it as 0 in the constructor, and display its content at the top in the center. Add a function in this class called nextLevel that increments the level number, adds an additional spare life, and does something to mark the event (like either display something, or play a sound of your choice). Reset the countDown variable in this function to a value that increments by 5 with the level number, and display it properly.

In the class Bombs, add a variable for the level number, initialized as 0 in the constructor. Add a function called nextLevel that resets all the bombs and add 1 or two additional to the array, with a randomized speed that increases slightly with the level number. You can use the function push to add elements to the array so that you don't have to reallocate it. Don't forget to increment the bomb counter. Then reinitialize all the bombs randomly, both the ones active before, and the new ones.

Back to the class Rocket, add a call to the function nextLevel from the bombs class in the nextLevel function for the rocket class. Then replace the condition where the game is won with a call to the function nextLevel, unless the leve number is equal to a given cap (like 5).

Turn in: the source file .fla, the compiled version .swf, and all the resource files and classes that you create and modify.