game maker - shooting

1
GameMaker: Shooting Firstly you will need to add a sprite and create an object to be the bullet, we will call it objBullet. Next, add the Event that will fire the bullet, I have used the Keyboard<Space> event. The Action is: Create a Moving Instance. To have the bullet start at your object, select x:0, y:0 and tick the relative box Set the speed and set direction to direction. This will have the bullet go the way you are moving. Advanced – 1 Of course, if you are standing still , GameMaker sets your direction to 0, meaning right. So anytime you stop, you can only shoot to the right. In order to have the bullet go the way your were last moving (in other words the way you are “facing” we need to do a bit more work. Firstly, set up a variable in the Create event and call it facing . Set the initial value to 0, meaning that we are facing to the right when the game starts. Next, each time you change direction (i.e. press left, right, up or down) you set the variable facing to the appropriate value as shown in the table. Finally, when you shoot, set the direction of the bullet to facing . Now you will still shoot in the last direction you were going, even when you stop. Advanced – 2: Using the mouse Another alternative is to use the mouse to control shooting. In your main character, select the Mouse Event: Global Left Pressed. The action is now to just create an instance of the bullet object at x:0 y:0, relative. In the create event of the bullet object, use the Move Towards action. Set the x to mouse_x and y to mouse_y. These are 2 variables that GameMaker already has defined for us to use. Don't forget to set the speed. You might want to explore the difference between Global Left Pressed and Global Left button; How might you change weapons during a game? You might also want to restrict the player to only having one bullet on screen at a time. Or you might want to give them limited ammo and have them collect more around the game. Direction Value Right 0 Left 180 Up 90 Down 270

Upload: andrew-pate

Post on 07-Apr-2015

401 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Game Maker - Shooting

GameMaker: Shooting Firstly you will need to add a sprite and create an object to be the bullet, we will call it objBullet. 

Next, add the Event that will fire the bullet, I have used the Keyboard‐<Space> event. 

The Action is: Create a Moving Instance. 

To have the bullet start at your object, select x:0, y:0 and tick the relative box 

Set the speed and set direction to direction. This will have the bullet go the way you are moving. 

 

Advanced – 1 Of course, if you are standing still , GameMaker sets your direction to 0, meaning right. So anytime you stop, you can only shoot to the right. 

In order to have the bullet go the way your were last moving (in other words the way you are “facing” we need to do a bit more work. 

Firstly, set up a variable in the Create event and call it facing. Set the initial value to 0, meaning that we are facing to the right when the game starts. 

Next, each time you change direction (i.e. press left, right, up or down) you set the variable facing to the appropriate value as shown in the table. 

Finally, when you shoot, set the direction of the bullet to facing. Now you will still shoot in the last direction you were going, even when you stop. 

Advanced – 2: Using the mouse Another alternative is to use the mouse to control shooting. 

In your main character, select the Mouse Event: Global Left Pressed. 

The action is now to just create an instance of the bullet object at x:0 y:0, relative. 

In the create event of the bullet object, use the Move Towards action. Set the x to mouse_x and y to mouse_y. These are 2 variables that GameMaker already has defined for us to use. Don't forget to set the speed. 

You might want to explore the difference between Global Left Pressed and Global Left button; How might you change weapons during a game? 

You might also want to restrict the player to only having one bullet on screen at a time. 

Or you might want to give them limited ammo and have them collect more around the game. 

 

Direction  ValueRight  0Left  180Up  90Down  270