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
ProjectileConfigs
- Contains two pre-configured projectile objects:
dragonProjectile
andkitsuneProjectile
, both of which are instances of the nestedBaseProjectileConfig
class.
BaseProjectileConfig
- A nested class within
ProjectileConfigs
that extendsBaseEntityConfig
. - It serves as a blueprint for defining common attributes and behaviors for projectiles.
BaseProjectileConfig
Members
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.
speed (Vector2)
:
- Defines the speed of the projectile in the x and y directions.
- Default value is new Vector2(10f, 10f).
scaleX (float)
andscaleY (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.
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.
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
name (String)
:
- The name of the animation, which corresponds to the animation identifier in the texture atlas.
frameDuration (float)
:
- Defines the duration (in seconds) of each frame in the animation.
playMode (Animation.PlayMode)
:
- Specifies how the animation should be played. This can be a continuous loop, a single playthrough, etc.
ProjectileFactory
Usage in 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.