Lesson 6

Lesson 6
Game Physics
Objectives:
1. Students will adapt a game to meet customer expectations
2. Students will create game interactions dealing with sprite replacement & random motion
3. Students will program an object to launch in a specific direction
Situation:
The Ugly Furniture Company (UFO) likes the prototype game you developed, but wants to see more
realistic movement and photon-launching options in the final game. The largest concern is to see if
the larger meteors can split into smaller meteor instead of simply being destroyed. It also wants to
see an increase in the randomness of the meteor movement. This is your chance to build the client a
better game & show off your skills.
How to begin:
1. Launch the Game Maker software and open your meteor game. (LastName_Meteors.gmk)
2. Save the game as LastName_Meteor_Upgrade in your video game folder. File > Save As…
Random Meteor Movement
3. Open Object Properties for OBJ_Meteor_LG
4. Select the existing Create Event
5. Double click on the existing Start moving in a direction action to edit it.
6. Click all of the direction buttons, except the stop direction. Click OK twice.
7. Repeat steps 3 – 6 for the medium and small meteors.
8. Test play the game to see how the meteors are moving & Save your work
Testing Control
Even if you are a great gamer, you probably did not last very long. Your UFO is a sitting duck for
those random meters. To correct this, later in the build you will give the player more control for those
random meteors. For now, you will just make some minor alterations to help you test the game.
9. Open the Room Properties for the Game (room0).
10. Move the UFO to the middle of the room so you can see the meteors traveling up from the
bottom.
11. In the Settings tab, enter 5 in the Speed: text box. This will slow down the action so you can
better see the interaction.
12. Test play the game & then save your progress.
Physics Collisions
You probably survived a little longer this time, there are still several changes needed before you have
much of a chance of doing well. Before you tackle some of these gameplay issues, make the meteor
movements seem a bit more realistic. You will program the meteors to bounce off of each other, but
think how that might actually happen in space. Apply the concept of momentum. Objects with more
mass have more momentum than objects with less mass, if both objects are traveling at the same
speed. This will need to be simulated in the game.
13. Start by programming this logic statement:
IF the large meteor collides with the medium meteor, THEN the medium meteor will bounce.
14. Open the Object Properties for OBJ_Meteor_LG.
15. Add an event for a collision with a medium meteor. Drag Bounce from the Move tab & drop it
into the actions column
16. In the Bounce dialog box, click the Other radio button so the medium meteor will do the
bouncing. Select Not Precisely & All Objects. Click OK.
17. Copy the action you just created.
18. Add an event for a collision with the small meteor and paste the actions to that event.
19. Test play the game & Save your progress.
Probability
You should have seen the medium & small meteors bouncing off the large meteors. But, what
happens when the large meteors hit each other? Right now, they do not bounce. In real life, these
massive objects probably would not bounce too well since they have the same momentum. Most
likely, they would crack into smaller pieces. You should try to simulate this real-life physics in the
game. The size of the pieces into which the large meteors break might be big or small. So, you will
also need to program the large meteors to randomly break up into small or medium size meteors
when large meteors collide with each other.
20. Open the Object Properties for OBJ_Meteor_LG.
21. Add a new event Collision with Large Meteor.
22. Drag & Drop Destroy Instance into the Actions column for this event. Select: Self.
23. Drag & Drop Create Random from Main 1 tab into the actions column. This dialog box allows
you to select several objects that will be randomly created when the event occurs.
24. Click the Self radio button to apply the action to the large meteor.
25. Select the medium meteor for Object 1, Object 2, and Object 3. Select the small meteor for
Object 4.
26. Enter 0 for the X & Y values and check the Relative box.
Conservation of Matter
Due to conservation of matter, the large meteor would not break up into only one smaller piece. It
would break up into multiple smaller pieces. To simulate this in the game, more than one smaller
part will need to be randomly generated for each large meteor collision.
27. For the existing event for a collision between large meteors, add another Create Instance of a
random object action. Select Self.
28. In Object 1: select the medium meteor. In Object 2: select the small meteor. In Object 3: select
the large meteor. In Object 4: No Object to balance the random event.
29. Set the action to occur at (0,0) relative to the collision. Click OK.
Now, there is an even chance (25% for each) that the action will create a small, medium, or large
meteor or nothing at all. While this means that sometimes a collision will produce a smaller mass
than the original object had, sometimes a larger mass will be produced. During gameplay, these
occurrences will balance out for a good simulation or reality. The player will not be able to notice the
inconsistency.
Seeing the Split
To better see the large meteors split and so as not to run out of lives in just a few seconds, you will
now modify the Game Frame room so you can watch what happens to the meteors.
30. Right click on the Game Frame room (room 0) in the resource tree & select Duplicate from the
shortcut menu.
31. In Room Properties dialog box click the Objects tab. Right click on the UFO to remove it from
the room. Without the UFO, you will not lose lives & can simply watch the meteors.
32. Remove all of the medium & small meteors, leaving only the large.
33. Remove the planets from the room also. You will have to go into the Object properties to make
them visible again temporarily.
34. Choose the Large Meteor in the object tab & add 10 total large meteors to the room.
35. In the resource tree, drag the new room above the Title Frame (room 1).
36. Test play the game & observe the meteors. Save your progress.
Notice how the large meteors smash up and push the smaller meteors around. This look much more
realistic than before.
More Collisions
In the game, the small and medium meteors also collide. You now need to program them to react
realistically, just as you did for the large meteors.
41. Program this logic statement for the OBJ_Meteor_Med object.
IF the medium meteor collides with a small meteor, THEN the small meteor bounces. The
bounce should be precise & against all objects.
42. Edit the room you created earlier, deleting all of the large meteors and adding 5 each of the
medium & small.
43. Test play the game & save your progress.
Final Collisions
The last set of collisions is for small-to-small & medium-to-medium. These are programmed in a
similar manner as the other collisions you just added.
44. Program this logic statement for the OBJ_Meteor_Med object:
IF the medium meteor collides with a medium meteor, THEN destroy the other medium meteor
& create 2 small meteors at that location.
45. Program this logic statement for the OBJ_Meteor_Sm object:
IF the small meteor collides with another small meteor, THEN both meteors bounce.
Hint: you need 2 actions.
46. Test play the see the interactions. Save you work.
UFO Movement
Now that the meteors have more realistic actions & reactions, the UFO needs to be addressed. The
player needs to have better control over the movement, not being limited to just left & right
movements. First, you are done using the test room you created earlier & select Delete.
47. Open Object Properties for OBJ_UFO.
48. Click Add Event > Key Press > <Up>
49. Drag & drop Speed Vertical from the Move tab into the Actions: column. Set vertical speed to -4
& make sure that the Self radio button is selected.
50. Add an event for pressing the down arrow & set the speed to 4.
You also need to modify the existing Outside Room event. This event has an action set to wrap
the UFO horizontally whenever the player leaves the left or right side of the screen.
51. Select the Outside Room event. Double click the Wrap horizontally when outside action to edit
it. Click in the Direction: text box & select In both directions. Click OK twice.
52. Test play the game & try moving the UFO around the screen avoiding the meteors.
53. Save your work.
Splitting Meteors with Photons
To add more realism to the game, you will program the meteors to split when hit by a photon. You
will first program the large meteor to break into 2 small meteors and one medium meteor. Then, you
will program the medium meteor to break into 2 small meteors.
54. Open Object Properties for the OBJ_Photon object.
55. Select the event for a collision with the large meteor to display the actions. Notice the block of
code you created in the last lesson.
56. Drag the Create Instance (Main 1) & drop it at the bottom of the block of code. Make sure the
action is within the block of code.
57. In the Create Instance dialog box, clock the Self radio button, click in the Object: text box &
select the small meteor in he shortcut menu. Check Relative & enter 0 in the X: & Y:. Click OK
58. Copy the Create instance of object OBJ_Meteor_Sm action & paste it 2 times at the bottom of
the block of code. Make sure the pasted actions are within the block of code.
59. Double-click on one of the pasted actions to open the Create Instance dialog box to edit the
action.
60. Click in the Object: text box & select the medium meteor from the shortcut menu. Click OK.
61. Using similar steps, program the medium meteor to split into 2 small meteors. You can save
time by copying the action from the event for a collision with the large meteor.
62. Test play the game. Test how the meteors split when you shoot them with a photon.
63. Save your work.
Blasting Direction
The final change requested by the client is that the UFO can launch photons in more than one
direction. To do this, you will program 4 keys to launch photons, each in a different direction. The
first thing you need to do is delete the current programming for launching a photon.
64. Open the Object Properties dialog box for the OBJ_Photon object.
65. Select the Create event to display the actions.
66. Select the Set the vertical speed action & press the Delete key to remove the action.
67. Click OK to close the Object Properties.
68. Open the Object Properties dialog box for OBJ_UFO object.
69. Select the Press <Space> event. Click Delete at the bottom of the Events: column. Click Yes to
confirm.
70. Click Add Event > Key Press >Letters > A. When the player presses [A] on the keyboard, the
UFO will launch a photon to the left.
71. Drag Create Moving (Main 1) & drop it into the Actions: column. Click the Self radio
button. Object: select the photon. Check the relative box & enter 0 for X: & Y:. Enter
40 in the Speed: text box. Direction: 180. Click OK.
a. Directions are in degrees just like on a protractor. To the right is 0°, up is 90°, to the left
is 180°, and down is 270°
72. Using similar steps, program the [D] key to launch a photon to the right, the [W] key to launch a
photon upward, and the [S] key to launch a photon downward. To save time, copy the action you
just created, paste it into a new event, and edit the direction.
73. Test play the game. Make sure the new photon directions work. Save your progress.
Tuning
You have addressed all of the client’s concerns. Now, you need to finalize the first level of this
prototype.
74. Edit room0 so the UFO is in the center & there are 4 large meteors, 2 medium meteors, & 1 small
meteor placed around the edges of the room. Also, delete the 3 planets you created to randomly
spawn meteors; these are no longer needed.
75. Change to room speed to 3.
76. Update the information for the Title & Help screens to reflect the changes made to this game.
77. Save your work.
78. If you are finished early, create a level 2 that is more challenging.
Do this by: File > Save As… > Last name_meteors_xtracredit. Modify level 1 in that game.