Giving Your Character Shooting Properties
Total Page:16
File Type:pdf, Size:1020Kb
GAME MAKER TUTORIAL #6 Giving your character shooting properties
1) Open your previously made Platform game. 2) Create a bullet spite with the sprite that is available from Wiki (calling it ‘spr_bullet’). Make this into an object (‘obj_bullet’). 3) You need to set your character up to fire a bullet. In order to do this, your character needs a variable to know which way it is facing. Go to your character’s Object Properties > Create > Set Variable Action from the Control tab. Set the Variable as ‘facing’ and Value as ‘0’. The direction the character is facing will be remembered in angles (right being 0 degrees, up 90 degrees, left 180 degrees and down 270 degrees). When we fire the bullet we will tell it to move at the facing angle.
We need to set the facing angle when your character changes direction. We will do this on your keyboard right and left events. To set facing direction: 4) On your character’s left keyboard event, use the Set variable action from the control tab. Set Variable as ‘facing’ and Value as ‘180’. Complete the same steps for your right keyboard event, but make the Value ‘0’.
To fire a bullet 5) Now we have set the facing direction, you can use the angle to aim the bullet. Go to Add Event > Key Press > Space. From the main1 tab, use the Create moving action. Set the Object as obj_bullet, X & Y as ‘0’, speed as ‘15’, direction as ‘facing’ and tick relative.
6) Test your game now. You should find that your character fires bullets when you press the space button.
7) You will need to add a Collision event with the wall that causes the bullet to destroy. You can also now add targets to shoot at to gain points.