Skip to main content

Movables

Written by: Akram Taghavi-Burris | © Copyright 2024
Status

In game development, various methods exist for implementing the movement of game objects. While different types of objects, such as platforms, enemies, and NPCs, may have unique movement characteristics, establishing common principles and control mechanisms is crucial. These shared systems streamline the management of different movements, ensuring consistency and flexibility throughout the game. Common Principles of Movement

  1. Consistency: All moving objects should adhere to a standard for controlling speed and direction.
  2. Reusability: Movement logic should be modular, allowing for easy application across various object types.
  3. Flexibility: Implementing an adaptable movement system accommodates changing game mechanics.

Movement System Architecture

The movement system will be constructed using several key components, including interfaces, abstract classes, concrete classes, and a controller. This modular approach allows for flexibility and reusability across different game objects. We have chosen to name this system "Movables" instead of "Movement" to emphasize the objects themselves that can be moved. This aligns with our naming convention, where interfaces are denoted by adjectives (e.g., IMovable) and classes by nouns (e.g., MovableObjectBase). This naming distinction helps clarify the purpose of each component within the system.

Here's a brief overview of each component:

  1. Interface - IMovable: This interface will define the essential properties and methods required for any object that can move. By establishing a standard contract, we ensure that all implementing classes adhere to the same movement principles.

  2. Abstract Class - MovableObjectBase: Acting as an intermediary between the interface and specific implementations, this abstract class will encapsulate shared logic and functionality. It allows derived classes to inherit common behaviors while enabling customization for unique movement types.

  3. Concrete Classes - Custom Mover: These classes will implement specific behaviors for various game objects, such as players, enemies, and platforms. Each concrete class will build upon the MovableObjectBase and provide tailored movement logic.

  4. Controller - MovablesController: This component manages the interaction between user inputs and the movement behaviors of game objects. It ensures that movement is responsive and aligned with game mechanics, facilitating a seamless experience for players.

  5. Test Component - MovablesControllerTEST: This component is designed to test the MovablesController, allowing us to verify that the methods are functioning correctly within the editor environment. It provides a framework for testing various movement scenarios, ensuring that user input is accurately translated into movement behaviors and that any issues can be quickly identified and addressed.

  6. Observer Pattern - Boundary Management: This class establishes the foundation for boundary classes, which will be extended to restrict objects within various boundary types, such as screen boundaries. It implements the Observer Pattern to notify subscribed classes when a boundary has been hit, ensuring that game objects remain within the designated limits.

  7. Component - Random Direction Changer: The RandomDirectionChanger randomly reverses a game object's direction based on a specified percentage chance, evaluated at regular intervals. When the condition is met, it invokes the ReverseDirection method implemented in the MovableObjectBase. To access this method, the RandomDirectionChanger will reference the MovableObjectBase component.

Movement as a System

By treating movement as a system, we can:

  • Achieve Consistency: Establish common principles and mechanics that all moving objects will follow, ensuring a unified experience across different game elements.
  • Enhance Reusability: Create modular components that can be easily adapted or extended for various object types, reducing redundancy and improving efficiency.
  • Promote Flexibility: Develop an adaptable framework that accommodates diverse movement behaviors and can evolve with the game's mechanics.

This structured approach not only streamlines the development process but also lays the groundwork for more complex interactions and behaviors in the game world.