Implementing the Factory pattern in Godot
Alright, now that we have an idea of what the Factory pattern is, it’s time to put it into practice. In this section, we will have another round of role-playing with our fictional studio’s game designer. This time around, we will create a class in which we can set PackedScene
and a container node found in the Level
node hierarchy and it will create the object in the game world.
So, our game designer implemented a cool new object called Heart
, which recovers one life of the player, but they want to be able to make this object appear in the game as a drop from the LootCrate
objects. They also want to be able to make Diamond
objects drop from the Bumping Pig enemy as well as the Heart
objects. Here’s their briefing:
Hello there,
I noticed that the game is currently lacking some incentives to make the players more aggressive toward the enemies. If we don’t give anything in return for defeating an enemy, the...