34
GAME:IT Helicopter Objectives: Review skills in making directional sprites Create objects that shoot and destroy for points Create random enemies on the scene as game challenges

Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

GAME:ITHelicopter

Objectives: • Review skills in making directional sprites• Create objects that shoot and destroy for

points• Create random enemies on the scene as

game challenges

Page 2: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

The first step is to upload the Helicopter images from a strip.

1) Click on Resources > Create Sprite2) Name it spr_helicopter3) Click Edit Sprite

Page 3: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

1) Click File > Create from Strip and select the helicopter.png file

Page 4: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

1) In the Loading a strip image pop-up box, enter the following:

Number of images: 3Images per row: 3

Image width: 64Image height: 64

Click OK

This creates the 3sub-images that willbe used for the animation

Page 5: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

1. Click the Show Preview check box to view the animation

1. Click the green check mark icon to save the changes

Page 6: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

7. Right click on the sprite helicopter and find the duplicate function.

Now we will program the animated helicopters that face the direction of the arrow keys located on the side number pad.

Page 7: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

8. Rename the sprite spr_helicopter_right—the picture is not currently facing right-----------------that is the next set of directions.

Page 8: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

11. Select the Rotate function

10. Click on the Transform menu

9. Click on the Edit Sprite button pulling up the Sprite Editor

Page 9: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

12. Set the angle to 90 degrees (is the helicopter facing right?)

13. Make sure this “Applies to all images in the sprite”

14. Click OK

Page 10: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

15. Click the check mark to save

16. Click the OK button to save

Page 11: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Repeat the procedure to create your left (180 degrees) and down sprite (270 degrees).

Make sure, at this point, to rename the original sprite spr_helicopter_up

Page 12: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Center all the helicopter sprites along with the bullet sprite.

Note: If you want the Bullets looking like they are coming more from the front of the helicopter you can change the origin.

spr_helicopter_up would be X=33 Y=20

spr_helicopter_315 would be X=40 Y=42

spr_helicopter_225 would be X=21 Y=39

spr_helicopter_135 would be X=23 Y=20

spr_helicopter_45 would be X=42 Y=24

spr_helicopter_right would be X=45 Y=33

spr_helicopter_left would be X=20 Y=30

spr_helicopter_down would be X=30 Y=46

Page 13: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Programming the NEW sprites to turn to correct direction1) Create an obj_helicopter

2) Create all these events (we will use the number keypad to control the helicopter (include a <no key> event).

Page 14: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Select the Change Spite action from the Main 1 folderStarting with the 8 key (up):

Select spr_helicopter_up as the image, enter 0-2 subimage, and speed 1

Note: Specifying subimage 0-2 creates the animation. The computer is continually displaying subimage 0, subimage 1, subimage 2 ….

(helicopter blades in different locations)

Page 15: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

The second action is to actually create the movement and direction with the Move Fixed action.

Select the Up arrow key and a Speed of 8

Page 16: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Using that programming as an example, create a helicopter that flies and points in the 7 other directions (using the numeric keypad)

3

8 9

4 6

1 2

7

And the 5 key will be used for . . . . . firing

You will also need to create 4 more sprites at 1, 3, 7, and 9 positions.

Page 17: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Part 2: Programming the ability to shoot (in all directions).

Add a create event. Add action Set Variable. Call it “angle_of_bullet”. The sprite helicopter is facing up so the initial value should be 90 (degrees).

Page 18: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

90

45135

180 0

225

270

315

In Game Maker the program interprets degrees like the figure below.

Page 19: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

In the case of number 1 on the keypad, the direction of the helicopter is facing 225 degrees, so the variable angle_of_bullet needs to be set at 225 degrees.

Set all the keypads (EXCLUDING #5) to their proper degrees

Page 20: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Call up the #5 key—this is our trigger.

The key action is called Create Moving. This will create an obj_bullet at the center of the sprite. It will be heading in the direction of “angle_of_bullet” at a speed of 10.

Since we don’t have any type of delay, the bullets come out as a stream of bullets.

Page 21: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Many of the objects you will program will have bullets coming out, not at the center, but at the edges.

Page 22: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

When the bullet comes from 0,0—it’s easy to program—it always stays at 0,0. But when you have 2 bullets, and the helicopter is facing up—one bullet comes from -10 (x),0 (y) and one bullet comes from +10 (x), 0 (y).

-10,0 +10,00,0

Page 23: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

But when the helicopter is facing right—one bullet comes from 0 (x), -10 (y) and one bullet comes from 0 (x), +10 (y)—x and y are switched.

Page 24: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

And what about the 45 degree shots. . .

0,0

?,?

?,?

y= 16*-sin((obj_helicopter.angle_of_bullet+270)*pi/180)

x= 16*cos((obj_helicopter.angle_of_bullet+270)*pi/180)

x= 16*cos((obj_helicopter.angle_of_bullet+90)*pi/180)

y= 16*-sin((obj_helicopter.angle_of_bullet+90)*pi/180)

ALL can be solved with a formula:

Bullet 1

Bullet 2

That’s why it’s important to take math classes (trigonometry)

Page 25: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Finished Product

Page 26: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Part 3: Something to shoot at?

How about random Hot Air Balloons?

Page 27: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Create a spr_balloon and then an obj_balloon.

To program balloons appearing at random points along the top of the screen:

1) An object controller needs to be created (obj_controller_balloon). No sprite will be assigned to this object.

2) Add a Create EVENT and a Create Instance action to create a balloon somewhere off the top of the screen: x=random(room_width), y= -16

Page 28: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Set an alarm (Alarm 0) action to go off after 50 steps.

Then add an Alarm 0 Event.

Page 29: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

And when the Alarm goes off—what happens?

2) Reset the alarm for another, in this case, 100 steps.

It will do 2 things: 1) Create a new instance of obj_balloon (same x,y coordinates as the previous Create instance).

Page 30: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

How are the actual balloons programmed?

1) Create EVENT: Set Vertical Speed to 1.

Page 31: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

2) Step EVENT (always checking): Check Variable to see if y is larger than room_height (the +32 allows the balloon to completely float off the screen before it does the next item)

Jump to Position action (where it restarts at a random spot at the top of the room, using the same x and y coordinates).

Page 32: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

3) The last EVENT—if the balloon Collides with a bullet—what do you want to happen?

It could just disappear (destroy instance of self (balloon) and a 2nd destroy instance (other—the bullet)).

Why not obj_bullet —it will destroy ALL bullets on the screen.

Page 33: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

But why just have the balloon disappear? Why not have it explode?

Design your own explosion sprite with multiple images (see below for an example)

Program the game so when the obj_balloon collides with obj_bullet it changes into the explosion sprite.

We also need to program the obj_explosion so the animation ends and the instance is destroyed. Do this with an Other Event and select Animation End and then a Destroy Instance action.

Save this game as Game8_yourname and play and test. If it plays correctly, move onto the assignment.

Page 34: Helicopter - Bardstown City Schools 8 Lesson.pdf · Center all the helicopter sprites along with the bullet sprite. Note: If you want the Bullets looking like they are coming more

Your Assignment is to create a game in which you protect your island from any wayward hot air balloonists and thus save the President!

The President of the United States has come to stay on your tropical island. Terrorists (hot air balloonists) want to destroy your island.

Program balloons to be coming from at least 3 different sides of the screen (each balloon will be a different color combination). They will reset randomly if not destroyed.

If a balloon touches the island, the island disintegrates into a massive explosion and the game ends.

Helicopter must fly and fire in all 8 directions.

Make sure to put the controller in the room!!!!

Requirements: