Top Down Shooter - Part 6
This tutorial explains to you how to create a Top-Down Shooter game in GDevelop. If you are a beginner or you have never used GDevelop before, this might be a great place to begin.
In this tutorial, you will learn how to :
- Make a limited Bullet number
- Make a Bullet magazine using variables
- Change variables
- Make an Ammo for reloading
Series
You are reading Part 6 of the Top-Down Shooter Tutorial. If you haven't read Part 5, then you can read it by selecting it down below.
This tutorial will help you to begin to use GDevelop. You will create a top-down shootergame where the player shoots and kills the enemy. Note that you can read the Getting Started page to get an overview of the software. It explains the main concepts and describes the interface of GDevelop.
Previously
In Part 5 we learned how to make an obstacle for our Enemy. we also learned how to animate our Player and optimize our game by deleting unnecessary objects. Today, we are going to make a limited amount of Bullets using the variable we are also going to make Magazines and an Enemy spawner.
Step 1. Limited Bullet
To make a limited amount of Bullets, we need to make a variable for our Gun. To make a variable:
- Right-click over Gun
- Click on Edit object variable
- Click on Add a new variable
- Name it Ammo
- Give it a default value, I will give it 10.
- Click on OK
We now made a variable. Now, we need to make that whenever we have Bullets, the Player will shoot or will not shoot.
- Now, create a new Event
- Add a new condition
- Select Gun
- Select Value of an Object's Variable
- Write Ammo in variable name textbox
- Choose > as the Operating Sign
- Write 0 in the value
- Click on OK
- Now, drag that Event where you have included actions to shoot Bullets and place it inside this new Event
This will forbid the Player to shoot when they don't have enough Bullets. But to reduce the Bullets amount when we shoot, we should do this:
- In the Events where we shoot, add a new action
- Select Gun
- Select Value of an Object's Variable
- Write Ammo in the name textbox
- Choose - as the Operator sign
- In the value, write 1
- Click on OK
Step 2. Write our Bullet amount
To display anything in form of Text, we need a Text object. To add a Text object:
- Click on Add a new object
- Select Text
- Rename it to "AmmoText"
- Now drag it to our scene
- Change its Layers to UI
- Now go to Events tab
- Add a new action
- Select AmmoText
- Select Change the Text
- Choose = as Operator sign
- In the value, write "Ammo " + Gun.VariableString(Ammo)
- Click on OK
This will display our Bullets amount on the screen.
Step 3. Make a Ammo
We have limited the number of Bullets the Player can shoot, reduce the number of Bullets while shooting but we also have to give Bullets to the Player. To do that, we need to add one more object. And to do so:
- Click on Add a new object
- Select Sprite
- Name it Ammo
- Double click on it to open Object Editor
- Click on Add a new animation
- Click on Add
- Select "Ammo-1.png" asset
- Click on OK
Now, we should give Bullets to our Player when he touches the Ammo. To do that:
- Go to the Events tab
- Add a new Event
- Add a new condition
- Select Player
- Select Collision
- In the Object, write Magazine
- Click on OK
- Now, add a new action
- Select Gun
- Select Value of an Object variable
- Write Ammo in the Name textbox
- Choose + as Operator sign
- Write 10 in the value (this will add 10 Bullets)
- Click on OK
Now, this will add 10 Bullets whenever we touch the Ammo
Conclusion
So, this is our last Part and we learned how to limit the number of Bullets and reload in collision with Ammo.