Creating collectibles
Now, let’s create some collectibles for our hero to pick up. We’ll create two different collectibles:
- A health potion, which will replenish the health of the character
- A coin, which will add one gold to the player’s money
We’ll start off by creating a base collectible, from which we can easily implement the two different behaviors we want the two collectibles to have.
Creating the base collectible scene
The base scene and class that we will build to inherit each specific collectible is very important; it should cover the use case of all other collectibles that we want to create. So let’s start:
- Create a new scene called
collectible.tscn
in a new folder,parts/collectibles
. - Set up the scene as shown in Figure 9.18:
- Make the root node a Node2D and call it
Collectible
. - Add an Area2D node and a Sprite2D as direct children.
- Add a CollisionShape2D to the area.
- Make the root node a Node2D and call it
Figure...