GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create - - PowerPoint PPT Presentation

game it junior
SMART_READER_LITE
LIVE PREVIEW

GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create - - PowerPoint PPT Presentation

GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game All games need sprites (which are just pictures) that, in of themselves, do nothing. They are the elements


slide-1
SLIDE 1

GAME:IT Junior

Bouncing Ball

Objectives:

  • Create Sprites
  • Create Sounds
  • Create Objects
  • Create Room
  • Program simple game
slide-2
SLIDE 2

All games need sprites (which are just pictures) that, in of themselves, do nothing. They are the elements that make up the game parts. The sprites are later turned into objects (which can be programmed). Backgrounds are just that—they are what you see in the background. Backgrounds are colors, or textures, or even pictures. The backgrounds are later used as part of the rooms. Sounds are files (usually .wav files) that add another dimension to the

  • games. They are used directly in the programming.

Rooms are the “playing fields” for the games. If you want to change the “playing field”, you change the room. Rooms can be changed to different sizes and detail.

slide-3
SLIDE 3

When starting a new game, typically you create the sprites & backgrounds first.

The objects are then created from the sprites. Objects are important because they can be programmed to do things (sprites cannot). Rooms are created next because objects and backgrounds are needed to create the rooms. When the room is set up, programming the events and actions of the objects can take place and be tested for errors.

Creating a New Game Where do I start?

If you know what sounds you are using, they can be created before programming starts or added later to enhance the game.

slide-4
SLIDE 4

Your first game will demonstrate a few of the elements of Game Maker. The game will involve a ball bouncing around the room and making a sound when it hits the wall.

slide-5
SLIDE 5

Your finished game will have (1) a smiley faced ball, (2) a red border, and (3) a lime green background.

slide-6
SLIDE 6

The first step is to create your wall and ball “sprites”

  • 1. Click the Create a Sprite icon
  • 3. You can either create your own sprite or load a sprite from a file. In

this game, you are going to load a pre-existing sprite, so click the Load Sprite button.

  • 2. Enter the name of the sprite—in this case—spr_ball.

IT IS IMPORTANT TO NAME THINGS AS INSTRUCTED

slide-7
SLIDE 7
  • 4. Find the folder that contains your Game 1 Resources and select the ball

image and click Open. ***GET THIS FILE PATH FROM YOUR TEACHER***

  • 5. Once the ball is loaded, click the OK button to save this sprite.
  • 6. Now follow the same steps to create the wall sprite, naming it spr_wall
slide-8
SLIDE 8

Next you are going to create a sound 7. Click on the Create a Sound icon 8. Name the sound snd_beep 9. Click the Browse Folder icon to load the beep.wav file from the Game 1 Resources folder

  • 10. Click “OK”

to save

slide-9
SLIDE 9

By the way . . . .

Why is it important to carefully label sprites, sound, backgrounds, rooms, and objects?

It’s just GOOD programming—it saves time later in searching for mistakes or making changes to your game. It only takes a few seconds to type in something that could cause minutes/hours of frustration. NAME EVERYTHING EXACTLY AS INSTRUCTED IN OUR LESSONS What are good examples? Spr_ball, spr_wall, snd_beep, bckgd_desert, obj_plane

What are BAD examples?

Spr01, sound1, background, plane (is it a sprite or object?)

slide-10
SLIDE 10

Next, you will create objects.

But I don’t understand—we created sprites -- they look the same?

The difference is sprites are just pictures, but objects can be programmed in Game Maker. How to create objects:

11. Select the Create an Object icon 12. Name the Object

  • bj_ball

13. You need to assign a sprite to the object. Do this by clicking the list icon, and select spr_ball from the list of available sprites

slide-11
SLIDE 11

The objects have additional attributes that need to be discussed – visible & solid

?

What is visible?

Most items in your games will be visible but

  • ccasionally you will need special objects to be

invisible (like walls and floors). Even though an

  • bject is invisible, they can still be programmed

for other objects to collide with for points or to bounce off of. You will learn more about this as we go through the lessons

What is solid?

Solid means you can collide with or bounce off

  • f an object. If an object is not solid, other
  • bjects can pass right through.

?

14. Make sure both Visible and Solid are

  • checked. Click “OK” to finish creating

the ball object. 15. Follow the same steps to create the wall object – name it obj_wall and assign it the spr_wall.

slide-12
SLIDE 12

Next—we create our first “room”

16. Click the Create a Room icon 17. Select the Backgrounds tab 18. Select a color by clicking in the color area to select the background color from the pop-up menu. 19. Click OK to save that color

slide-13
SLIDE 13

To add objects to the room:

  • 20. First, we need to make sure the Snap is set to X = 16 and Y =16.
  • 21. Next, select the objects tab
  • 22. Click the list icon and choose obj_ball from the submenu that appears and

place the ball somewhere in the middle of the room by clicking your left mouse where you wish to place the ball.

slide-14
SLIDE 14

23. Next, click the List Icon again and select the obj_wall. Click into each square around the perimeter of the room to add the wall. Left mouse adds (or moves) the object. HINT: Click the Left Mouse and drag while hold down the Shift + Ctrl keys can add multiple objects quickly. *Just be very careful where you drag.* NOTE: There is a visual that shows which object will be placed when clicking into the room

slide-15
SLIDE 15

If you place something in the wrong spot, right click on that object and select delete from the menu that appears.

slide-16
SLIDE 16

Time to Program!

The actual programming occurs in the OBJECTS we have created:

  • bj_ball and obj_wall.

With the room set up and the objects in the room, what do we want the ball to do? A) Bounce off the walls B) Make a “beep” when it hits the wall. In this case, all the programming takes place in the obj_ball.

slide-17
SLIDE 17
  • 24. Open the Object Properties window for obj_ball by

double clicking it in the side menu.

  • 25. Click on the “Add Event” button
slide-18
SLIDE 18

Create Event

This event happens when an instance of the object is first created, and is the very first thing that happens within an instance placed in the room. This event is the ideal place to initialize variables, start Timelines, set paths etc... and do anything else that generally only needs to be done once or only when an instance first appears in the room.

Destroy Event:

This event is the very last event to be executed when an instance is destroyed. It is often overlooked when adding behaviors to objects, but it can be very useful, for example by creating explosion or particle effects when an enemy is killed, or for re-spawning a new instance of the object in another part of the room, or even for adding points onto a score.

What are EVENTS?

Events are discreet moments in the game loop where things are made to happen based on what you have programmed for them. Here is a description of the different events:

slide-19
SLIDE 19

Alarm(s):

The alarm event is split into 12 sub events, one for each of the possible alarms that can be set in an instance. But what is an alarm? It’s a special event that does nothing unless the alarm has been previously set, and then it will wait until that alarm has counted down to 0 before running the actions or code that you have added into it. Example: Object changes direction every 30 steps. FYI: An Action must reset the alarm.

slide-20
SLIDE 20

Step Event:

GameMaker:Studio splits time into steps with the room speed defining how many of these steps happen per second. A step is basically the loop that runs constantly with all the events being checked and triggered as necessary while the game runs, so the Step Event is an event that is checked every single step of the game while the instance exists. For most things the standard step event will be fine to use, but sometimes you want a bit more control over what code runs and at what time, so for that you are provided with the begin and end step events.

slide-21
SLIDE 21

Collision Event:

When 2 objects collide, you want these actions to occur. Example: When bomb collides with plane— create an explosion sprite.

Keyboard Event:

When a player presses a certain key on the keyboard, the actions will occur. You get the action in every step as long as the key is depressed. There is a <no key> event and an <any key> event.

slide-22
SLIDE 22

Mouse Event:

This would occur when the mouse cursor touches the object. You can select left, right or middle buttons.

Other Events:

Miscellaneous collection of “special” purpose events. Check the Help Documents for an description of each of them.

slide-23
SLIDE 23

Draw Event:

This event is the one that governs what you see on the screen when you run your game, and is split into three separate "sub-events" - the Draw Event, the Draw GUI and Resize Event.

Key Press:

Only happens once at key press (not continuously).

Key Release:

Only happens once at key release (not continuously).

For more info on all Events, check out the Help Documentation included with Game Maker: Studio.

slide-24
SLIDE 24
  • 26. Select the “Create” event from the Add Events menu.
  • 27. Select “Move Fixed” from the actions menu (Move tab) and

drag it into the Actions panel. This will open the Move Fixed window and allow you to set the following variables:

  • Select the 4

corners of the directions

  • Enter 5 as the

speed.

  • Leave the relative

button unchecked. 28. Click “OK” to save.

slide-25
SLIDE 25
  • 29. Next, click Add Event to select another event.
  • 30. Choose Collision. Assign the collision to obj_wall by

selecting it from the pop-up menu.

slide-26
SLIDE 26
  • 31. When the ball collides with
  • bj_wall you want it to

bounce off the wall, so select the Bounce action and drag it into the action section.

  • 32. Enter the following

variables

  • Applies to: Self
  • Precise: precisely (select

from submenu)

  • Against: solid objects

(select from submenu)

  • 33. Click “OK” to save
slide-27
SLIDE 27
  • 34. Still in the Collision with obj_wall Event, find Play Sound in the Main 1 folder

and drag it to the Actions panel.

  • 35. Enter the following variables:
  • Sound: snd_beep (select from submenu)
  • Loop: false (select from submenu) – false means it will only play once.
  • 36. Click OK to save
slide-28
SLIDE 28

Now it’s time to test your game!

  • 37. Click the Run Game icon to test and play your game.

If your game was programmed correctly, the game will run successfully. If not, you will see error messages that will help you make corrections.

slide-29
SLIDE 29

Save the Game as Game1_yourname

Assignments:

  • A. Modify the game so that the when you click your left

mouse on the ball, the ball disappears. Save it as Game1A_yourname

  • B. Modify the game so that the when you click your left

mouse on the ball, the ball changes direction and increases speed (hint: relative button). Save it as Game1B_yourname

  • C. Modify the game so that the when you click your left

mouse on the ball, the ball changes direction and increases speed and if you right click on the ball, it will change direction and slow down. Save it as Game1C_yourname