From 23d5db02992d8d34c572de81010ddcebbf48f1ef Mon Sep 17 00:00:00 2001 From: MiniSoda17 Date: Sat, 9 Sep 2023 15:24:24 +1000 Subject: [PATCH] Added Engineer bullet creation --- .../projectiles/engineer_projectile.atlas | 41 ++++++++++++++++++ .../projectiles/engineer_projectile.png | Bin 0 -> 386 bytes .../images/projectiles/mobProjectile.atlas | 2 +- .../csse3200/game/areas/ForestGameArea.java | 3 +- .../projectile/EngineerBullets.java | 29 +++++++++++++ .../MobProjectileAnimationController.java | 3 +- .../game/components/tasks/TrajectTask.java | 1 + .../tasks/human/EngineerCombatTask.java | 2 +- .../entities/factories/ProjectileFactory.java | 27 +++++++++++- 9 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 source/core/assets/images/projectiles/engineer_projectile.atlas create mode 100644 source/core/assets/images/projectiles/engineer_projectile.png create mode 100644 source/core/src/main/com/csse3200/game/components/projectile/EngineerBullets.java rename source/core/src/main/com/csse3200/game/components/{ => projectile}/MobProjectileAnimationController.java (88%) diff --git a/source/core/assets/images/projectiles/engineer_projectile.atlas b/source/core/assets/images/projectiles/engineer_projectile.atlas new file mode 100644 index 000000000..47eb72f99 --- /dev/null +++ b/source/core/assets/images/projectiles/engineer_projectile.atlas @@ -0,0 +1,41 @@ + +engineer_projectile.png +size: 128, 32 +format: RGBA8888 +filter: Nearest, Nearest +repeat: none +bullet + rotate: false + xy: 68, 2 + size: 19, 19 + orig: 19, 19 + offset: 0, 0 + index: -1 +bullet + rotate: false + xy: 25, 2 + size: 20, 19 + orig: 20, 19 + offset: 0, 0 + index: -1 +default + rotate: false + xy: 25, 2 + size: 20, 19 + orig: 20, 19 + offset: 0, 0 + index: -1 +bullet + rotate: false + xy: 2, 2 + size: 21, 19 + orig: 21, 19 + offset: 0, 0 + index: -1 +bulletFinal + rotate: false + xy: 47, 2 + size: 19, 19 + orig: 19, 19 + offset: 0, 0 + index: -1 diff --git a/source/core/assets/images/projectiles/engineer_projectile.png b/source/core/assets/images/projectiles/engineer_projectile.png new file mode 100644 index 0000000000000000000000000000000000000000..a98ae11e2738244ed8bbd2b7a69d747efb26ae38 GIT binary patch literal 386 zcmV-|0e$|7P)%!e|5l00030!t2dRtB}ElS#zi|uf^^5JoR-ByY`whC}KOn)7HWlcjKf0Y@fdJ zknwN#lW<)=ggLL9YtkWz=TS0)>cv57z0b}=pdr-9i=+U$`tB#wJ? z-}yF&z|$`tuT>(0L9jt;tzM>~;s890-_^IPnlVZJ<^J#GbvOWe2)zAttetCa27_RO zw50)f7vI-6uAKg#&sVMY@b>GQYib6Apo=Pf`gis1D(@#&=yV5M6#emJpa1- z?kmqTTj+iK1}Gq2c*$SDwohMq$aww*9DrT8R*mA#-fUj}eC^t6&fw_TO=6<}00000 g00000002ki2U!--uDg4S4*&oF07*qoM6N<$f?lh)dH?_b literal 0 HcmV?d00001 diff --git a/source/core/assets/images/projectiles/mobProjectile.atlas b/source/core/assets/images/projectiles/mobProjectile.atlas index d069c0394..5dabfa025 100644 --- a/source/core/assets/images/projectiles/mobProjectile.atlas +++ b/source/core/assets/images/projectiles/mobProjectile.atlas @@ -20,7 +20,7 @@ rotate index: -1 default rotate: false - xy: 54, 2 + xy: 28, 2 size: 24, 23 orig: 24, 23 offset: 0, 0 diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 7a586023b..5666d6af0 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -111,7 +111,8 @@ public class ForestGameArea extends GameArea { "images/mobs/rangeBossRight.atlas", "images/towers/TNTTower.atlas", "images/projectiles/basic_projectile.atlas", - "images/projectiles/mobProjectile.atlas" + "images/projectiles/mobProjectile.atlas", + "images/projectiles/engineer_bullets.atlas" }; private static final String[] forestSounds = { "sounds/Impact4.ogg", diff --git a/source/core/src/main/com/csse3200/game/components/projectile/EngineerBullets.java b/source/core/src/main/com/csse3200/game/components/projectile/EngineerBullets.java new file mode 100644 index 000000000..6b0a4d820 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/projectile/EngineerBullets.java @@ -0,0 +1,29 @@ +package com.csse3200.game.components.projectile; + +import com.csse3200.game.components.Component; +import com.csse3200.game.rendering.AnimationRenderComponent; +import com.csse3200.game.services.ServiceLocator; //used for sound + +public class EngineerBullets extends Component{ + /** Event name constants */ + + AnimationRenderComponent animator; + + @Override + public void create() { + super.create(); + animator = this.entity.getComponent(AnimationRenderComponent.class); + entity.getEvents().addListener("start", this::animateStart); + entity.getEvents().addListener("final", this::animateFinal); + + } + + void animateStart() { + animator.startAnimation("bullet"); + } + + void animateFinal() { + animator.startAnimation("bulletFinal"); + } +} + diff --git a/source/core/src/main/com/csse3200/game/components/MobProjectileAnimationController.java b/source/core/src/main/com/csse3200/game/components/projectile/MobProjectileAnimationController.java similarity index 88% rename from source/core/src/main/com/csse3200/game/components/MobProjectileAnimationController.java rename to source/core/src/main/com/csse3200/game/components/projectile/MobProjectileAnimationController.java index e1a55775e..e72fe612e 100644 --- a/source/core/src/main/com/csse3200/game/components/MobProjectileAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/projectile/MobProjectileAnimationController.java @@ -1,5 +1,6 @@ -package com.csse3200.game.components; +package com.csse3200.game.components.projectile; +import com.csse3200.game.components.Component; import com.csse3200.game.rendering.AnimationRenderComponent; diff --git a/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java b/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java index 56c81912b..8ca977d2f 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/TrajectTask.java @@ -41,6 +41,7 @@ public void start() { this.owner.getEntity().getEvents().trigger(START); this.owner.getEntity().getEvents().trigger("rotate"); + this.owner.getEntity().getEvents().trigger("start"); } public void switchProjectileState() { diff --git a/source/core/src/main/com/csse3200/game/components/tasks/human/EngineerCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/human/EngineerCombatTask.java index 1487fa714..f26d84be0 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/human/EngineerCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/human/EngineerCombatTask.java @@ -131,7 +131,7 @@ public void updateEngineerState() { if (shotsFired <= 10) { owner.getEntity().getEvents().trigger(FIRING); // this might be changed to an event which gets triggered everytime the tower enters the firing state - Entity newProjectile = ProjectileFactory.createFireBall(PhysicsLayer.NPC, + Entity newProjectile = ProjectileFactory.createEngineerBullet(PhysicsLayer.NPC, new Vector2(100, owner.getEntity().getPosition().y), new Vector2(4f, 4f)); newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.75), (float) (owner.getEntity().getPosition().y + 0.4)); diff --git a/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java index 58a705f0a..63482bd5f 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java @@ -9,7 +9,6 @@ import com.csse3200.game.components.tasks.TrajectTask; import com.csse3200.game.ai.tasks.AITaskComponent; import com.csse3200.game.components.CombatStatsComponent; -import com.csse3200.game.components.MobProjectileAnimationController; import com.csse3200.game.entities.configs.BaseEntityConfig; import com.csse3200.game.entities.configs.NPCConfigs; import com.csse3200.game.files.FileLoader; @@ -23,6 +22,7 @@ import com.csse3200.game.physics.components.PhysicsComponent; import com.csse3200.game.physics.components.PhysicsMovementComponent; import com.badlogic.gdx.math.Vector2; +import com.csse3200.game.components.projectile.MobProjectileAnimationController; import com.csse3200.game.components.projectile.ProjectileAnimationController; /** @@ -115,6 +115,31 @@ public static Entity createFireBall(short targetLayer, Vector2 destination, Vect return projectile; } + /** + * Creates a enginner bullet + * + * @param targetLayer The enemy layer that the projectile collides with. + * @param destination The destination the projectile heads towards. + * @param speed The speed of the projectile. + * @return Returns a new fireball projectile entity. + */ + public static Entity createEngineerBullet(short targetLayer, Vector2 destination, Vector2 speed) { + Entity projectile = createBaseProjectile(targetLayer, destination, speed); + + AnimationRenderComponent animator = + new AnimationRenderComponent( + ServiceLocator.getResourceService() + .getAsset(BASE_PROJECTILE_ATLAS, TextureAtlas.class)); + animator.addAnimation("bullet", START_SPEED, Animation.PlayMode.NORMAL); + animator.addAnimation("bulletFinal", FINAL_SPEED, Animation.PlayMode.NORMAL); + + projectile + .addComponent(animator) + .addComponent(new ProjectileAnimationController()); + // .addComponent(new SelfDestructOnHitComponent(PhysicsLayer.OBSTACLE)); + + return projectile; + } /** * Creates a projectile specifically for mobs to shoot