Creating Enemies with Abstract Classes

Daniel Ercilio Del Rosario Guerra
2 min readJun 17, 2021

When we’re making games we want to add variety into our projects, so the players can feel a better game experience. Let’s put ourselves into an example, imagine you’re the programmer and your designers told you to create different enemies with different behaviours.

Instead of creating a lot of classes with the same data, we should use one class as BASE and start creating from there.

Enemy Base Class Example

This is basic example on how you can create a Base Class. This will vary on the project you’re working on.

Inside the BaseEnemy class we define to abstract voids: Walk and Attack. Using the abstract keyboard we’re saying to the compiler that these methos are going to be on any child class.

Implementing the Abstract Class

Imagine the game designer told us to implement vampires into the game.

Once we create a Vampire class and make it inherit from BaseEnemy we can start extending this enemy entity until we reach the behaviour we want.

--

--