Projectile Structure - UQcsse3200/2024-studio-1 GitHub Wiki

Projectile Component

ProjectileComponent manages the behavior and properties of projectiles in the game. Each projectile is instantiated when a weapon is fired and carries specific attributes, such as damage, speed, and special effects.

Key Methods:

  • update(): Updates the projectile's position and checks for collisions with other entities or environment obstacles.
  • activate(): Marks the projectile as active, allowing it to start moving toward its target.
  • collide(Entity target): Handles the logic when the projectile collides with another entity, applying damage and effects as necessary.

Projectile Factory

ProjectileFactory is responsible for creating instances of projectiles with specific configurations.

Key Methods:

  • Entity createProjectile(ProjectileConfig stats, Vector2 direction): Creates a new Entity with projectile components configured based on the provided ProjectileConfig and direction.

Updated Methods:

  • loadConfigs(): Loads the projectile configuration from the projectiles.json file. This file contains detailed properties for each type of projectile, such as speed, health, attack stats, and animations. This is a static method called during the initialization of the factory. It allows the factory to access predefined projectile properties throughout the class.
  • create(String specification, Vector2 direction, Vector2 parentPosition): Factory method that returns a projectile entity based on the given specification, which can be "dragonProjectile", "kitsuneProjectile1", or "kitsuneProjectile2". The method uses the respective helper methods to create specific projectiles.
  • createAnimator(String atlasPath, ProjectileConfigs.BaseProjectileConfig.ProjectileAnimations[] animations): Helper method to generate an AnimationRenderComponent by loading animations from a texture atlas. Each projectile has its own atlas containing animation frames for its movement or attack actions.
  • Updated createProjectile: This method constructs a new projectile entity with a set of predefined components. It handles adding components for physics, combat stats, movement, hitboxes, and animations. It also configures the entity's size and collider based on the projectile's configuration.

Spawn Mechanic

ProjectileSpawner handles the spawning of projectiles in the game when a weapon is fired.

Key Methods:

  • spawnProjectile(Weapon weapon, Vector2 position, Vector2 direction): Spawns a projectile at the specified position in the direction of the weapon fire.