I love real-time strategy games. I was first introduced to the genre by the 2004 version of Axis and Allies made by Timegate Studios. Since then, I ha

How I Created Abstract Classes in Godot

submited by
Style Pass
2024-11-07 14:30:04

I love real-time strategy games. I was first introduced to the genre by the 2004 version of Axis and Allies made by Timegate Studios. Since then, I have tried to build custom maps, and now I want to build my own game. I chose to work in Godot as an excuse to continue learning the engine after trying it out for smaller projects.

To start, I need to have a “Unit” class. This class represents basic properties a moveable game piece needs to function. That includes things like how to move around the map, if the piece is selected, what team the unit is on, etc. I then extended this class to make a variety of sub-units. Each class needs to know its own unit type so game events can interact with it properly. Eventually Unit will be an abstract class and all sub-units will extend Unit.

In the actual game, there is pathfinding logic, variables that hold what team the unit is on, and more. This information is not relevant to the structure of the base class or its derived classes, so they are omitted. Notice that the Unit class is not an abstract class yet. It will need to be made abstract after it is extended.

Leave a Comment