-
Notifications
You must be signed in to change notification settings - Fork 4
Projectile Factory
The projectile entity is created to ensure that other entities such as mobs and towers are able to defend/attack each other. So, the 'ProjectileFactory' class was implemented. Within this class, the animations as well as speed and effect are integrated to create the different projectiles.
The function createBaseProjectile()
is responsible for assigning the base components for all projectiles within game. The components added for base projectiles are PhysicsComponent()
, PhysicsMovementComponent()
, hitBoxComponent()
and an AI component TrajectTask()
which focuses on the direction of the projectile.
This function will build upon the createBaseProjectile()
and adds more specific components for the fireball. It will add TouchAttackComponent()
and CombatStatsComponent()
. Then it will also set the speed depending on the parameter by accessing PhysicsMovementComponent()
and the .setSpeed()
function. Within the TouchAttackComponent()
, there is an optional knockback parameter which accepts a float and determines how far enemies will be knocked back. Another parameter is the disposeOnHit, which accepts a boolean that determines whether the projectile will disappear on contact.
Image for the Fireball:
This function builds upon createBaseProjectile()
and creates a projectile that applies an effect from the Effects Component class to the target entity and creates animations for the projectile.
Image for Stun effect:
Image for Burn effect:
Image for Slow effect:
This function builds upon createBaseProjectile()
and creates a projectile with a green design and rolling animation.
public static Entity createMobBall(short targetLayer, Vector2 destination, Vector2 speed) {
Entity projectile = createBaseProjectile(targetLayer, destination, speed);
AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService()
.getAsset("images/projectiles/mobProjectile.atlas", TextureAtlas.class));
animator.addAnimation("rotate", 0.15f, Animation.PlayMode.LOOP);
projectile
.addComponent(animator)
.addComponent(new MobProjectileAnimationController());
projectile
.getComponent(AnimationRenderComponent.class).scaleEntity();
return projectile;
}
Image used within game
MobKing fireball builds upon createBaseProjectile()
and creates a fireball that does damage to its target but won't self destruct on impact.
public static Entity createMobKingBall(short targetLayer, Vector2 destination, Vector2 speed) {
Entity projectile = createBaseProjectile(targetLayer, destination, speed);
AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService()
.getAsset("images/projectiles/mobKing_projectile.atlas", TextureAtlas.class));
animator.addAnimation("mob_boss", 0.17f, Animation.PlayMode.NORMAL);
animator.addAnimation("mob_bossFinal", 0.17f, Animation.PlayMode.NORMAL);
projectile
.addComponent(animator)
.addComponent(new MobKingProjectAnimController());
projectile
.getComponent(AnimationRenderComponent.class).scaleEntity();
return projectile;
}
Image for MobKing ball:
Pierce fireball builds upon createBaseProjectile()
and creates a fireball that does damage to its target but won't self destruct on impact.
public static Entity createPierceFireBall(short targetLayer, Vector2 destination, Vector2 speed) {
Entity fireBall = createPierceBallAnim(targetLayer, destination, speed);
fireBall.getComponent(TouchAttackComponent.class).setDisposeOnHit(false);
fireBall.getComponent(TouchAttackComponent.class).setKnockBack(0f);
return fireBall;
}
public static Entity createPierceBallAnim(short targetLayer, Vector2 destination, Vector2 speed) {
Entity projectile = createBaseProjectile(targetLayer, destination, speed);
AnimationRenderComponent animator = new AnimationRenderComponent(ServiceLocator.getResourceService()
.getAsset("images/projectiles/pierce_anim.atlas", TextureAtlas.class));
animator.addAnimation(START_ANIM, 0.05f, Animation.PlayMode.LOOP);
projectile
.addComponent(animator)
.addComponent(new PierceProjectileAnimationController());
return projectile;
}
Image used for Pierce Fireball:
Ricochet fireball builds upon createBaseProjectile()
and creates a fireball that does damage to its target as well as changing its direction.
public static Entity createRicochetFireball(short targetLayer, Vector2 destination, Vector2 speed, int bounceCount) {
Entity fireBall = createFireBall(targetLayer, destination, speed);
fireBall
.addComponent(new RicochetComponent(targetLayer, bounceCount));
setColliderSize(fireBall, (float) 0.1, (float) 0.1);
return fireBall;
}
Image used for Ricochet fireball:
Split Fireworks fireball builds upon createBaseProjectile()
and creates multiple fireballs that does damage to its target after a collision.
public static Entity createSplitFireWorksFireball(short targetLayer, Vector2 destination, Vector2 speed, int amount) {
Entity fireBall = createFireBall(targetLayer, destination, speed);
fireBall
.addComponent(new SplitFireworksComponent(targetLayer, amount));
return fireBall;
}
public static Entity createFireworks(short targetLayer, Vector2 destination, Vector2 speed) {
Entity projectile = createBaseProjectile(targetLayer, destination, speed);
AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService()
.getAsset("images/projectiles/firework_anim.atlas", TextureAtlas.class));
animator.addAnimation(START_ANIM, 0.2f, Animation.PlayMode.LOOP);
projectile
.addComponent(animator)
.addComponent(new FireworkAnimationController());
return projectile;
}
Image used for Fireworks: