top of page

How I Used Design Patterns in Arcane Lands (Part II)

Strategy pattern

Building on a “Character” model, which will be inherited by Enemy and Player classes, I use the Strategy pattern to define different movement and shooting controllers.

The image below shows how this is done. The ICharacterMovement interface, used by the Character model, contains a reference to a IMovementController interface. This then allows different character to have different classes that implement IMovementController. For example, the PlayerMovementController would move the character based on the user’s touch inputs; Meanwhile, the EnemyMovementController may target the nearest player and circle around it.

This pattern makes character movement much more flexible than having the naive approach of type-checking the class with many if-else statements and applying movements accordingly.

Furthermore, the Strategy Pattern also applies the concept of Frameworks. In this situation, _PhysicsProcess() is triggered on every frame, and the movement controller’s role is then particularly to return a velocity, which the _PhysicsProcess uses to apply the movement (with Translate()) and update the animation of the character. Additionally, the pattern directs encapsulation such that the movement controller has clear responsibilities in its interface.

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page