Lesson 5 Objectives

advertisement
Lesson 5
Objectives

Students will describe how object movement is achieved in a game.

Students will be able to create animated sprites and moving targets.

Students will create a custom sprite.

Students will be able to program an object to launch and destroy an enemy object.
Situation
The Awesome Game Company has hired you as an intern for its 2D game development
division. In order to be assigned higher-level tasks, you must first learn how object movement is
created in a game. After learning about this, you will be assigned a game build.
How to Begin
1. Read the passage below.
2. Complete the review questions.
3. Turn in all materials.
4. Complete the game build.
Reading Materials
Object movement in a game is created in one of three different ways: transportation,
animation, and spawning. The next sections discuss each of these methods in detail. Answer the
review questions at the end of the reading materials.
Transportation
In the Click Ball game you created earlier, the ball was made to move arid bounce on the walls.
This form of movement is transportation. In the simplest of definitions, transportation is the
moving of an object from one location to another. As part of the transportation movement
attribute set, which is a collection of characteristics or features, the designer can manipulate
characteristics such as direction, speed, acceleration, and deceleration.
Transportation attributes are easy to understand, as you can see these applied every day in
the real world. If you watch a car pass in front of you as you stand on a street corner, the car has
a direction attribute that determines how it moves from a position on your left to a new position
on your right. In this example, the direction attribute is "moving right." So you can see that
direction determines the path the object will travel. Look at Figure 5-1. This is the dialog boo
you used to set the direction for the ball in the Click Ball game you created earlier. Game Maker
uses nine-position direction attributes (including the middle "no movement" option).
The car described above also displays a speed attribute. In engineering and physics, speed
is referred to as velocity. Roth words have the same meaning, and speed is used more
frequently in game programming. Speed is how fast something is moving. If the driver is obeying
a speed limit of 50 miles per hour, the car would have a speed attribute of 50. To calculate
speed, use the formula: speed = distance time. In this example, the car is traveling at a speed of
50 miles per hour. To find out how many miles the car will travel in one hour, use the formula: 50
mph = X miles I hour. Solve the equation for X, which in this case is equal to 50.
Speed can change as the object is moving. The instantaneous speed is the exact speed
the car is moving at the exact moment or instant you are observing it If you are driving along in
your car and a slow-moving bus gets in front of you, you will need to slow down. Your
instantaneous speed might drop to 40 miles per hour until you can pass the bus. You may even
speed up a bit to 60 miles per hour as you pass the bus. During your trip, your instantaneous speed
will change as you drive through traffic and around coolers. In the end, you may still have traveled 50
miles in one hour, meaning your average speed was 50 mph, but your instantaneous speed will have
varied along the 50-mile journey. To change the instantaneous speed of the car, the driver must push
down the accelerator pedal to speed up or push down the brake pedal to slow down. To speed up,
the car must accelerate. To slow down, the car must decelerate.
A stopped car has no speed, or an instantaneous speed of zero. If the driver presses down the
accelerator, the car begins to move. Suppose the speed is observed two seconds later and the
instantaneous speed is 20 miles per hour. Applying the accelerator allowed the car to accelerate
from 0 mph to 20 mph in two seconds. This means the car has accelerated, or a positive change in
instantaneous speed has been applied. In other words, the speed of the car is getting faster.
Mathematically, acceleration is calculated using the formula: acceleration = distance + (time)'. If the
driver applies the brakes, the car will slow down. Slowing down, or changing the instantaneous
speed in the negative direction, is deceleration.
In game design, it is typical to apply the formulas for direction, speed, and acceleration using the
virtual distances in the game. The game room can be broken down into a grid, as you saw in the
Click Ball game build. The regular spacing of the grid acts like real-life units of measurement. In the
real world, a meter is 100 centimeters. In the virtual world, one division in a one-meter grid might be
10 pixels. Just as the virtual world reduced the size of the real-world room, the time intervals most
also be accurately reduced to scale. In most games, time intervals are milliseconds (.001 seconds).
Game Maker can also change the room speed to adjust by milliseconds. It typically uses a 1/20th of
a second as one step. You learned about steps in the Click Ball game build. Speed is calculated by
how many pixels an object moves in each step. If you set an object to move at a speed of eight, it
will move eight pixels every 1/20th of a second. In Game Maker, the standard room size is 640
pixels wide. If an object moves at eight pixels per step, it would take 80 steps (four seconds) to move
from one side of the screen to the other.
Animation
An animation is a series of images played in quick succession, each with a small change that
give the illusion of movement. This is similar to a flipbook animation where you draw a series of
pictures in the corner of a notepad and then flip the pages to see the figure move. Game Make has
some built-in animation features you can use or you can create custom animations on your own
and import them.
To animate a sprite is to make it move. To accomplish sprite animation, the designer needs to
create several animation frames to make up the entire animation. On each frame, the sprite has
moved or changed a small amount from the previous frame. For example, if you need a sprite to
walk, you need to create animation frames for each pose as the character's arms and legs
articulate. Articulation is the bending and positioning of movable parts. A human character may
have articulated legs, arms, fingers, head, lips, eyelids, and so on
If an object is transported and animated, it is considered an active animation. An example of an
active animation is a walking animation with articulated movement synchronized to the transportation
(movement). Synchronizing is linking the timing of events. In this case, the footstep animation
distance must correspond (link) to the transportation distance the object is moved. It the character
does not move a distance your brain interprets it should based on the footstep animation, the
overall animation will look odd. Using your fingers like legs, make your hand "walk" on your desk. To
do so, you must synchronize the animation of your fingers to match the transportation of your arm.
Spawning
The final object movement option is spawning. Spawning is the creation of an object within the
game. An object can be randomly created or teleported. An obstacle object, like a flying meteor,
might be randomly spawned to make the game challenging for the player, since the objects must
be avoided. With a teleported object, the object is moved from one point within the game to
another point. This might occur between levels or could be just an added feature to jump from
one spot
in the game to another. It is like a magic doorway that takes the player to another place within the game.
In the classic game of Pac-Man, when the characters leave the right side of the room they are teleported
to the left side of the room. This specific teleportation feature is called wrapping.
In addition to wrapping, the player can teleport in many other ways. The most common application of
teleporting is when the player dies and is re-spawned or re-created at a checkpoint. A checkpoint
is a saved point within a game that allows the player to teleport back to that point if damaged or
destroyed. Without a checkpoint, a player would have to restart from the beginning of the game each
time the character is damaged or destroyed. The checkpoint allows the player to stay interested in the
game and avoid the frustration of having to redo sections of the game already mastered.
Review Questions and Activities
Vocabulary Questions
Write a definition for each of the terms listed below.
1. Transportation: __________________________________________________________________
2. Attribute set: ____________________________________________________________________
3. Direction: ______________________________________________________________________
4. Instantaneous speed: _____________________________________________________________
5. Accelerate: _____________________________________________________________________
6. Decelerate: _____________________________________________________________________
7. Animation: _____________________________________________________________________
8. Articulation: _____________________________________________________________________
9. Active animation: ________________________________________________________________
10. Synchronizing: _________________________________________________________________
11. Spawning: ____________________________________________________________________
12. Teleported: ___________________________________________________________________
13. Wrapping: ____________________________________________________________________
14. Checkpoint: ___________________________________________________________________
15. Given a rate of 50 mph, how far would a car travel in 2 hours? ___________________________
16. What is the velocity of a car that drove 345 miles in 5 hours & 45 minutes? _________________
17. If you drove a car & maintained an instantaneous speed of 40 mph for 20 minutes, 50 mph for 30
minutes, & 60 mph for 10 minutes, how far would you have traveled in 1 hour? __________________
18. Explain how to calculate the average speed of the car in question 17. ______________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
19. How many milliseconds are in 1 step (1/20th of a second)? _______________________________
20. If your trip from home to school were part of a game, list 3 ways you would move the player to
school. __________________________________________________________________________
Situation
The Awesome Game Company needs to make a simple 2D game for a client named Ugly
Furniture Organization (UFO). The client loves to make fun of the company name and the
UFO acronym. The company wants a UFO-themed game to lure customers to its website.
Your job is to create an entertaining game that uses a UFO launching projectiles to destroy
meteors.
How to Begin
This lesson builds on the skills you learned in earlier lessons. If needed, refer to earlier
lessons if you do not remember how to do certain tasks. All future lessons build on the skills
learned in previous lessons.
1. Launch Game Maker
2. Create a new room (room0) and set its background color to black.
3. Save the game as LastName_Meteors in your video game design folder.
4. Create a new sprite named SPR_UFO. Load the ufo.gif or ufo2.gif image file located in the
Resources folder > Sprites on my teacher website.
5. Create a new sprite named SPR_Meteor LG. Load the meteor_LG.gif image file located
in the same folder as the UFO.
Animating the Meteor
6. Open the Sprite Properties dialog box for the SPR_Meteor LG sprite.
7. Click the Edit Sprite button to open the Sprite Editor.
8. Select Animation>Rotation Sequence>Clockwise from the Sprite Editor pull-down menu.
The Animation Rotate dialog box is displayed.
Clockwise direction is circular movement from the top, to the right, bottom, left, and back
to the top, like the hands of a clock moving forward. Counterclockwise direction is the
opposite, like the hands of a clock moving backward.
9. In the Animate Rotate dialog box, enter 5 the Number of frames: text box and 360 in the
Degrees (0-360): text box. This will automatically create a total of five frames, each frame one
step in an animation that rotates the meteor clockwise in a full circle. There are 360 degrees in
a circle.
10. Click the OK button to see the created frames, Figure 5-2.
11. Check the Show Preview check box in the Sprite Editor.
12. The meteor is spinning too fast. Enter 6 in the Speed: text box to slow it down. This is the
preview speed only.
13. Click the OK, save changes button (green check mark) to close the Sprite Editor.
14. Using similar steps to create sprites with the following attributes.
Sprite Name
Image File
Animation Rotation
# of Frames
Animation Speed
SPR_Meteor_Med Meteor_med.gif
Counterclockwise
8
7
SPR_Meteor_Sm
Clockwise
10
9
Meteor_sm.gif
15. Save your work.
Custom Sprite
You are now going to draw your own sprite using the Sprite Editor.
16. Create a sprite named SPR_Photon.
17. In the Sprite Properties dialog box, click the Edit Sprite button to open the Sprite Editor
18. Click the Create a New Sprite button.
19. In the Create a New Sprite dialog box, set the canvas size to 32 x 32. Click OK.
20. Double-click on the word Image 0 to open the Image Editor.
21. Left-click on the yellow color swatch in the color palette to set the Left: color.
22. In the menu bar go to Image > Transparency, enter 255.
Opacity is a measure of how transparent (see-through) and object is. A setting of 255 means the
object is completely opaque, or not fully transparent. A setting of 0 means the object is fully
transparent, or invisible. A setting of 128 means the object is midway between fully opaque and
fully transparent.
23. Select View > Zoom In from the drop down menu.
24. Click the Draw an Ellipse button. The shape area appears below the tools. The 3
buttons in this area determine how the color will be applied. The top button creates
a shape that contains an outline and no fill. The middle button creates a shape with
an outline and a fill. The bottom button creates a shape that has fill with no outline.
Choose the top button.
25. Draw a circle in the middle of the canvas. If you hold down the shift key as you drag, a circle is
created.
26. Left-click on the red color swatch in the color palette to set the Left: color.
27. Click the Fill an Area button, then click inside the circle to make the center red.
28. Click the Close the Image, saving changes made button (green check mark).
That is the basic image of the photon sprite. The photon will be the object launched
at the meteors to destroy them. To make the photon more interesting, you will
animate it to start out full-size & then shrink until it disappears to simulate losing power.
29. In the Sprite Editor, choose Animations > Shrink>Center from drop-down menu. Center is
selected so the photon will shrink to its center.
30. In the Animation Shrink dialog box, Enter 20 in the Number of frames: text box. Click OK to
create the frames, Figure 5-4.
32. Enter 10 in the Speed: text box.
33. Check Show Preview. Notice the yellow outline looks like a sparkle as the photon disappears.
34. Click OK, save changes button (green check mark) to save the animation.
35. Click OK in the Sprite Editor to finish editing this sprite.
36. Save your work.
Game Objects
37. Using the skills learned earlier, create the following objects.
Object Name
Sprite Name
Visible
Solid
OBJ_UFO
SPR_UFO
Yes
No
OBJ_Meteor_LG
SPR_Meteor_LG
Yes
No
OBJ_Meteor_Med
SPR_Meteor_Med
Yes
No
OBJ_Meteor_Sm
SPR_Meteor_Sm
Yes
No
OBJ_Photon
SPR_Photon
Yes
No
38. Save your work.
Player
The UFO object will be the player’s avatar (representation of the player in the game). The
UFO (player) will launch photons to destroy the falling meteors.
39. Open the Room Properties dialog box for room0.
40. Place the UFO object at the bottom-center of the room.
41. Place two instances of each meteor object near the top of the room. Don’t overlap the objects.
42. Open the Object Properties dialog box for the OBJ_UFO object.
You need to program the UFO object to launch a photon. The logic statement is:
IF the player presses the space bar, THEN launch a photon from the UFO object in an
upward direction.
43.Click the Add Event button >Choose the Event to Add > Key Press (not Keyboard button)
<Space>
44. Drag & drop the Create Instance button from the Main 1 tab into the Actions column, Figure 5-5.
45. Click the Self radio button. This applies the action to the UFO object.
46. Click in the Object: text box & select OBJ_Photon, Figure 5-6.
47. In the X: & Y: text boxes, enter 0.
48. Check Relative. Remember relative means “from where it was before”. This will program the
photon to appear zero pixels to the right and zero pixels down from where the UFO was before. In
other words, the photon will appear at the exact location of the UFO.
49.Click the OK button.
50. Click OK.
51. Save your work.
Launching Objects
52. Open the Object Properties dialog box for OBJ_Photon object.
53. Click Add Event > Choose the Event to Add > Create
54. Drag the Speed Vertical from the Move tab & drop it into the Actions: column.
55. Click Self
56. Now, you are going to set the speed for the photon. In the Vert. Speed text box, enter -8, Figure
5-7. A negative value will move the object upward. Remember, in Game Maker the positive &
negative Y directions are reverse from math class.
57. Click OK.
58. Save your work.
Outside the Room
In a virtual world, objects can exist even if the player cannot see them. You have likely played
many games that allow you to walk around and see things that exist outside of the current scope
or visible play area. This can help make a great game, but can also slow down gameplay, as the
computer must keep track of all objects. One way to help solve this problem is to destroy objects
when they are not visible in the play area. In the Meteors game, you will create the programming
to destroy any instance of the photon object when it leaves the room. Other wise, the computer
will track the instance as it travels upward forever.
59. Display Object Properties for OBJ_Photon object.
60. Click Add Event > Other > Outside Room
61. Drag > Destroy Instance from the Main 1 tab drop it into the Actions: column, Figure 5-8.
62. Ensure the Self radio button is on. Click OK.
63. Click OK.
64. Save your Work.
Tuning
Test play your game. In the following steps you will fix those issues with your game.
65. Open the Room Properties for room0
66. Click the Settings tab.
67. In the Speed: text box, enter 10.
Origin Point
68. Open the Sprite Properties dialog box for SPR_Photon.
69. In the Origin area, click Center, Figure 5-9.
70. Click OK
71. Open the Sprite Properties box for SPR_UFO.
72. Click the Center button.
73. Move the cursor to the intersecting lines (crosshairs) on the preview. Then, click & drag the
crosshairs to the top-center of the UFO point, Figure 5-10.
74. Click OK.
75. Test the game and notice the changes you have made. You still need to fix the photon so it
stops pulsing.
76. Save your work.
Fixing the Photon
77. Program the OBJ_Photon object with this logic statement:
IF the animation ends, THEN destroy the instance (Animation ends is under Other in Events).
78. Edit the vertical speed action for the Create event > Change speed to -20. This will make the
photon fade out near the top of the room.
79. Test play the game.
80. Save your work.
Player Movement
In this section, you will program the player to move. Later you will make the meteors move.
81. Open the Object Properties dialog box for OBJ_UFO object.
82. Program this logic statement:
IF the player presses the right arrow keyboard key, THEN set the horizontal speed to 15.
Note: do not use relative. You would keep adding speed.
83. Program this logic statement for the OBJ_UFO:
IF the player presses the left arrow keyboard key, THEN set the horizontal speed to -15.
84. Test the game. You should be able to move left & right. You can also go off the screen. You
will fix this later.
85. Save your work.
Movement Wrap
86. Open the Object Properties for OBJ_UFO object.
87. Click Add Event > Other >Outside Room.
88. Drag the Wrap Screen button from the Move tab & drop it in the Actions: column. Make sure the
Self radio button is on & Horizontal in the Direction: text box. Click OK & OK again.
89. Test the game & Save your work when finished.
Exploring the Meteors
The photons are supposed to make the meteors explode when they hit, but they do not. That is
because you have not programmed it to yet.
90. Add a new sprite named SPR_Explode. Load the explode.gif image file located in the
resources folder on my teacher web site.
91. Move the origin to the center of the image. Click OK.
92. Create a new object named OBJ_Explode & attach SPR_Explode sprite to it.
93. Program this logic statement for the object:
IF the animation ends, THEN destroy the instance.
94. Click OK.
Photon Collisions
95. Open the Object Properties dialog box for OBJ_Photon.
96. Click Add Event >Collision & choose OBJ_Meteor_LG.
97. Drag & drop Create Instance from the Main 1 tab into the Actions: column.
98. Click the Object radio button & select OBJ_Meteor_LG, Figure 5-11. This applies the creation
to that object.
99. Click in the object Object: text box & select OBJ_Explode.
100. Enter 0 in the X: & Y: text boxes. Check Relative. This will create the explosion object in the
exact location of the large meteor. Click OK twice.
101. Test Play the game & then save your work.
The explosion is in the wrong place. To fix this, set the origin of the large meteor so the
animation will look correct. You will also need to set the origin of the medium & small
meteors, as you will later program these objects to explode, too. Note: the explosion
occurs on both larger meteors when you only hit one. You will fix this bug later. In the next
section, you will fix the bug of the meteor not being destroyed when it is hit.
Blocks of Code
A block of code is actions set to take place when an event condition is met. In this game the
photon & meteor should both be destroyed at the same time when the explosion appears.
102. Open the Object Properties dialog box for OBJ_Photon object
103. Select the existing collision event (collision w/ OBJ_Meteor_LG) to show the actions already
programmed for this event.
104. Click the Control tab & locate the Start Block button. Drag & drop it into the
Actions: column above the existing action.
105. Below the create action, add a destroy-instance action to destroy the photon.
106. Below the destroy-instance action you just added, add another destroy-instance action to
destroy the larger meteor.
107. Click the Control tab & locate the End Block button. Drag & Drop into the
Actions: column below the last action.
108. Test play the game and then save your work.
Debugging
The game has a flaw because all large meteors are destroyed whenever on is hit w/ a photon. You
will now fix that issue.
109. Open the Object Properties dialog box for OBJ_Photon object.
110. Select the existing collision event. One of the actions in this block of code needs to be edited.
Double-click on the 2nd Destroy Instance action.
111. Click the Other radio button, Figure 5-13. Click OK.
112. The explosion is still created on both instances of the large meteor when only one is hit with a
photon. Now, edit the create-instance action in the same manner as you edited the destroyinstance action. See step 110.
113. Test play the game & then save your work.
To avoid this type of error in Game Maker, use the Self & Other options. Avoid using the Object
option. The Object option always applies the action to all objects in the game of that type.
Copying & Pasting Actions
You need to program the explosion for the medium & small meteors. You can copy & paste the
programming from the large meteor. This will save a lot of programming time.
114. Double click on OBJ_Photon in the resource tree on the left of the screen.
115. Select the existing collision event. This is the block of code you need to copy. Select the Start
of Block action. Hold down the Shift key & click the end of block action, Figure 5-14.
116. Right click on the blue highlighted area & Copy.
117. Click Add Event > Collision > OBJ_Meteor_Med. This creates an event for the collision
between the photon & medium meteor.
118. In the Actions: column for the new event, right click > Paste.
119. Repeat the steps 117 -118 for the small meteor.
120. Test play the game & then Save your work.
Scoring
Next you will add the scoring & make the meteors move.
121. Double click on the OBJ_Photon object in the resource tree. Select the event for the collision
w/ the large meteor.
122. Below the block of code, add a set score action to increase the score by 5 points relative to
the previous score.
123. Repeat for the medium meteor & the small meteor.
124. Test play the game & then save your work.
Lives
Now you will add lives object to the game. This will limit the player to a set number of lives to
make the game more challenging & interesting.
125. Open the Object Properties for the OBJ_UFO object.
126. Click Add Event > Create. Drag & Drop the Score Caption button from the Score tab into the
Actions: column. Click Show lives: > Show, Figure 5-15. This will display lives in the title bar
of the game window. Click OK.
127. Drag Set Lives from Score tab into the Actions: column. New Lives: 3. Don’t
check the Relative check box. Click OK.
The player will start with 3 lives. Now, you will program to remove a life when the
UFO collides with a meteor. Logic Statement: IF the UFO collides with a large
meteor, THEN subtract 1 from the total number of lives.
128. Drag & Drop Set Lives into the Actions: column. New Lives: -1 & check the relative check box.
Click OK.
129. Drag the Destroy Instance from the Main 1 tab & drop into Actions: column. Click the Other
radio button (to destroy the object other than the UFO). Click Ok.
130. Repeat for the medium & small meteor collisions.
Add to the room a new instance of the large, medium, & small meteors in the path of the UFO.
Test play the game & drive the UFO into each meteor to test the lives function.
High Score Table
Next, you need to program what happens when the number of player lives reaches zero.
Here, you will program the game to end and display a high score table.
131. Open the Object Properties for OBJ_UFO object.
132. Select the collision event for a collision with the large meteor to show the action.
133. Drag & Drop the Start Block button from the Control tab in the Actions: column.
Figure 5-16.
134. Drag the Test Lives from the Score tab & drop it below the Start of a block action.
135. In the Test Lives dialog box, enter 0 in the value: text box. Click in Operation: & enter
Equal to. Click Ok.
136. Drag & Drop End Game from Main 2 tab into the Actions: column.
137. Drag & Drop Show Highscore from the Score tab into the Actions: column. Next, you will
change the font, background, & colors in the high scores table to the options of your choice.
Click OK. See Figure 5-17.
138. Drag the highscore table action above the End the Game action. This is necessary or the
game will end before the high score table is displayed.
139. Drag & Drop the End Block button from the Control tab into the Actions: column.
140. Select from the Start of a Block to the End of a Block & copy the code. Paste the code into the
collision with the medium & small meteors.
141. The Block of Code just pasted needs to be under any other code in the actions: column.
142. Test Play your game & Save your progress.
The game ends as soon as you hit a meteor. This is a bug that must be fixed, & you will do
so in the next section.
Block Qualifiers
A block of code can be given a qualifier. A qualifier is the condition that must be met before the
block of code will execute. You added a qualifier of testing the number of lives to see if it equals
zero. If this qualifier is True, then the block of programming will execute. If the qualifier is False,
then the block of programming will not execute. However, the qualifier is within the block of
code. In Game Maker, the qualifier is placed before the Start of a block line.
143. To fix this bug, drag the If Lives are equal to 0 action above the Start of a block line. Do this
for each collision between the UFO & all the meteor.
144. Test play the game and then save your work.
Adding Challenge
While building & testing the game interactions, the meteors did not move, so everything was easy to
test. Now that the game interactions are working properly, you can add some challenge to the
game by having the meteors move. The meteors will travel from the top & move down toward
the UFO.
145. For each meteor object, add a create event with Movement Fixed action for
down, down-left, & down-right, Figure 5-18.
146. Set the speed of the large meteor to 5, medium meteor to 10, & small meteor to 12.
147. Test play the game & Save your progress.
More Meteors
During he game, the meteors should be continuously generated in a random fashion. While
there are many ways to do this, you will use a very simple method so you can practice more
skills. To start, you need to create some launching points for the meteors. To do that, you will
use objects that randomly launch meteors.
148. Create 3 new sprites: SPR_Planet1, SPR_Planet2, SPR_Planet3. Then, create objects for
each of the new sprites. Names: OBJ_Planet1, OBJ_Planet2, OBJ_Planet3.
149. Place Planet 1 in the top-left corner of the room, the Planet 2 in the top center, & the Planet 3
in the top-right corner.
150. Save your work.
Movement Paths
What you are going to do is move these new objects across the top of the screen & program
each collision to generate a meteor. By changing the speed & path of each object, the collision
will occur at random intervals & make a great challenge. First, you need to create a path.
151. Click Create a Path button on the toolbar. The Path Properties dialog box is
displayed, Figure 5-19.
152. In Name: type Path_Planet1
153. Click at the origin (0,0), which is the top-left corner of the grid.
154. Notice the coordinate display at the bottom of the dialog box displays the location of the cursor.
These X & Y values will change as you move the mouse.
155. Randomly click on the grid to create an irregular path along the top of the grid.
As you click to set nodes, Game Maker creates a path script & displays it in the window below
the Name: text box. Below the path script, you can manually enter the X, Y & speed values (sp:)
for each node of your path.
156. Manually add a node at (50,100) with a speed setting of 20. Notice how the node moves as you
enter values.
157. Look at Connection Kind at the bottom left of the dialog box. Currently, the Straight lines radio
button is on, meaning the path is made up of straight-line segments.
158. Click the Smooth curve radio button. Notice how the path is now a squiggly, curved line. Also
notice how several of the nodes do not touch the curved line. The position of each node still
affects the curvature of the path.
159. Uncheck the Closed check box. Notice how the path is no longer a continuous loop. This
check box allows you to choose if you want the path to form a loop or end at a point other than
the beginning point.
160. Precision: determine how much pull each node had on the curved path. Enter 1 & notice the
path segments become more like straight segments. The higher the value, the more curvature
the path segments have.
Now you should have an understanding of the features of a path. What you have drawn so
far was used just to demonstrate these features. You will now clear this path & drag a
correct path for the object.
161. Click the Clear the Path button. Then, click Yes.
162. Maximize the Path Properties to display the entire grid of the room.
163. Locate the first node at the Origin (0,0) using the X: & Y: text boxes & Sp: 20.
Click Add.
164. For the 2nd node to (640,32) by entering these values in the X: & Y: text boxes & Speed of 40.
Click Add.
165. Add a 3rd node at (400,0) with a speed of 30.
166. Add a 4th node at (200,16) with a speed of 10.
167. Make sure the path is closed so the object will return to the starting point.
168. Click Close the form, saving the changes (green check mark) to save the path.
169. Open the Object Properties for the OBJ_Planet1 object.
170. Add Create event.
171. Drag the Set Path from the Move tab & drop it into the Actions: column.
Figure 5-20.
172. Apply the path to Planet 1 (Self).
173. Click in the Path: box & choose the Path_Planet1 from the shortcut menu.
174. Enter 30 in the Speed: box.
175. Click in the At end: box & select Continue from start from the shortcut menu.
176. Click in the Relative: box & select Absolute from he shortcut menu.
177. Click OK to close the Set Path box.
178. Test play the game & then save your progress.
More Paths
179. Create a new path named Path_Planet2.
180. Place the 1st node at (320,0) which will start the path at the top-center of the screen.
181. Create a randomly jagged path. All nodes should have a Y coordinate of either 0 or 64 & an X
coordinate between 0 & 640. Set the speed to 100 for all nodes. See Figure 5-21 for an
example.
182. Add the path to the Planet2 object using the same settings as the Planet1 except set the speed
at 40.
183. Create a path named Path_Planet3 for Planet3 with the 1st node at (640,0).
184. Create a randomly jagged path. All nodes should have a Y coordinate between 0 & 96 & X
coordinate between 0 & 640.
185. Set this path to a smooth curve. When the path is curved, it moves inward from the nodes.
186. Click on the 1st node in the path script. This selects the node & turns it red on the grid, which
helps you to keep track of the nodes.
187. Drag the selected node to the right & up so the path is closer to the coordinate (640,0).
188. Add the path to the Planet3 object with the same settings as the other Planets, but set the
speed to 10.
189. Test the game to see how the 3 objects move along the paths created.
190. If needed, edit each path to create more opportunities for the objects to collide. To edit a path,
double-click on it in the resource tree to open the Path Properties. Then, drag nodes to change
the shape of the path.
191. Save your work.
Randomness
192. For Planet1, program this logic statement: IF Planet1 collides with Planet2, THEN create a large
meteor at Planet1’s position. Use the collide event & create instance action. Figure 5-22.
193. For Planet1, program this logic statement: IF Planet1 collides with Planet3, THEN create a
medium meteor at Planet1 position.
194. For the Planet2, program this logic statement: IF Planet2 collides with Planet3, THEN create a
small meteor at Planet2’s position.
195. Test play the game & save your progress.
More Challenging
To make the game more challenging & exciting, you can have the meteors wrap around the screen.
196. For the OBJ_Meteor_LG object, create and outside the room event and make the Meteor Wrap
the Screen from the Move tab.
197. Repeat for all sizes of meteors. Then, Test play & save your work.
Tuning
198. Edit the Planet objects & uncheck the Visible check box. This will make the objects invisible
during game play.
199. Create a title page in a new room using the same method that you did in the Click Ball game.
Include: the name of the game, your name as video game designer, instructions for the game, &
a play button.
200. Create a help page that is activated when the player presses the [H] key. Include Questions
that the player might have while playing the game. Include what keys the player will use during
game play.
a. Create a sprite called SPR_H. Do not load a sprite because you do not want
anything on your screen.
b. Create an Object (OBJ_H) for that sprite. Then, Add Event > Keyboard > H. Add
Display a Message (Main 2 tab). Type the following into the text box: Help Page# #To
play the game:# #Right & Left arrow keys Moves the UFO #Spacebar Fires photons#
#Scoring:# #Large Meteors 5 points #Medium Meteors 10 points #Small Meteors 15
points # #Collision w/ a meteor results in lost of life. # (Be sure to include the #
because that tells Game Maker to start a new line.)
c. Add the object to the title screen room. Remember that you will not be able to see
anything. Test your game.
201. Create sounds for launching the photon, exploding meteors, & for when a live is lost. Minimum
of 3 sound effects.
202. Save the game. Make sure it is saved as Your Last Name_Meteors
Download