Skip to main content

MovementManager

Fields and Properties

  • Instance: Singleton instance.
  • gameEnded: Boolean to check if the game has ended or not.
  • movingEntities: A list storing entities that are currently moving.

Methods

Update()

Iterates through the list of moving entities and updates their positions based on linear interpolation between the start and target positions over time.

AddEntity(Entity entity)

Adds an entity to the movingEntities list to track its movement.

RemoveEntity(Entity entity)

Removes an entity from the movingEntities list, stopping its movement tracking.

HandleGameStart()

Clears the movingEntities list and sets gameEnded to false, called at the start of the game.

HandleGameEnd()

Sets gameEnded to true and clears the movingEntities list, called when the game ends.

Suggestions

Performance

  1. Batch Updates: Consider batch updating entities based on some categorization (e.g., type or proximity to player) to improve performance.

Code Optimization

  1. Reusability: If other classes also require movement tracking or linear interpolation, consider making this class more generic or implementing these functionalities as utility methods.

Potential Refactoring

  1. Movement Finish Callback: You could implement a callback or event that gets triggered when an entity reaches its destination. This would provide a more decoupled way to handle what happens next.

Additional Features

  1. Pathfinding: Currently, the class appears to move entities linearly between two points. Consider integrating more complex pathfinding algorithms if your game requires it.

  2. Speed Variability: You might consider adding a feature where the speed can be dynamically changed, which would require recalculating the "current movement time."

  3. Pause and Resume: You may need functionalities to pause and resume entity movements, especially if your game has different states like paused, playing, etc.

Feel free to elaborate more on what you're looking for in terms of optimization or other functionalities.