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

Overview

ProjectileConfigs serves as a configuration class that defines the properties of different projectile types in the game. This class is used as the base configuration for the loadConfigs method in the ProjectileFactory class, allowing projectiles to be customized with different attributes like speed, size, animations, and physics properties. It currently defines two types of projectiles: a dragon projectile and a kitsune projectile.

Structures

  1. ProjectileConfigs
  • Contains two pre-configured projectile objects: dragonProjectile and kitsuneProjectile, both of which are instances of the nested BaseProjectileConfig class.
  1. BaseProjectileConfig
  • A nested class within ProjectileConfigs that extends BaseEntityConfig.
  • It serves as a blueprint for defining common attributes and behaviors for projectiles.
BaseProjectileConfig Members
  1. Layer (short):
  • Specifies the physics layer to which the projectile belongs.
  • Default value is set to PhysicsLayer.PLAYER, meaning the projectile will interact with the player layer.
  1. speed (Vector2):
  • Defines the speed of the projectile in the x and y directions.
  • Default value is new Vector2(10f, 10f).
  1. scaleX (float) and scaleY (float):
  • Control the scaling factor for the width (scaleX) and height (scaleY) of the projectile.
  • Default values are both 0.5f, meaning the projectile will appear at half its original size in both dimensions.
  1. animations (ProjectileAnimations[]):
  • An array of animations that the projectile can play. Each entry in the array defines a specific animation for the projectile.
  • Default is an empty array (new ProjectileAnimations[0]), meaning no animations are defined unless explicitly added.
  1. isDirectional (boolean):
  • Indicates whether the projectile should display directional animations (e.g., different animations when moving left or right).
  • The default value is false.
ProjectileAnimations Members
  1. name (String):
  • The name of the animation, which corresponds to the animation identifier in the texture atlas.
  1. frameDuration (float):
  • Defines the duration (in seconds) of each frame in the animation.
  1. playMode (Animation.PlayMode):
  • Specifies how the animation should be played. This can be a continuous loop, a single playthrough, etc.

Usage in ProjectileFactory

The ProjectileConfigs class is loaded by the ProjectileFactory's loadConfigs method to create customized projectile entities in the game. The factory uses this configuration to set various properties (like speed, scale, animations, etc.) when creating different projectile types such as the dragon projectile and kitsune projectile. This ensures that all projectiles share a common base configuration, while still allowing for unique behaviors and appearances based on the specific projectile type.

The loaded JSON file should look like this:

"dragonProjectile": {
    "health": 0,
    "baseAttack": 5,
    "isDirectional": true,
    "speed": {
      "x": 10,
      "y": 10
    },
    "Layer": 2,
    "scaleX": 0.5,
    "scaleY": 0.5,
    "animations": [
      {"name": "fire_attack_left", "frameDuration": 0.1, "playMode": "LOOP"},
      {"name": "fire_attack_right", "frameDuration": 0.1, "playMode": "LOOP"}
    ]
  }

This structure also allows for easy expansion, as additional projectile types or configurations can be added by defining more BaseProjectileConfig instances in the future.