From a752e9001c0b8cdd3928e2b7ed4413b3be3163a9 Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Wed, 6 Sep 2023 21:11:51 +1000 Subject: [PATCH 01/10] Changed interator in getNearbyEntites to for loop because team 2 said it was breaking somewhere --- .../src/main/com/csse3200/game/entities/EntityService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/core/src/main/com/csse3200/game/entities/EntityService.java b/source/core/src/main/com/csse3200/game/entities/EntityService.java index c8c8823df..9c20b93d4 100644 --- a/source/core/src/main/com/csse3200/game/entities/EntityService.java +++ b/source/core/src/main/com/csse3200/game/entities/EntityService.java @@ -85,7 +85,9 @@ public Array getEntities() { public Array getNearbyEntities(Entity source, float radius) { Array nearbyEntities = new Array(); Array allEntities = ServiceLocator.getEntityService().getEntities(); - for (Entity otherEntity : allEntities) { + for (int i = 0; i < allEntities.size; i++) { + Entity otherEntity = allEntities.get(i); + if (source == otherEntity) continue; // Skip the source entity Vector2 positionSource = source.getPosition(); From 7e44262764f874fa7195117af3ef1e24ddb4e5e0 Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Wed, 6 Sep 2023 22:24:36 +1000 Subject: [PATCH 02/10] removed createAoeProjectile and instead replaced it with createEffectProjectile which has parameters that accepts different effects and whether it is an aoe projectile or not --- ...oeComponent.java => EffectsComponent.java} | 19 ++++- .../entities/factories/ProjectileFactory.java | 76 ++++++++++++++----- 2 files changed, 72 insertions(+), 23 deletions(-) rename source/core/src/main/com/csse3200/game/components/{AoeComponent.java => EffectsComponent.java} (77%) diff --git a/source/core/src/main/com/csse3200/game/components/AoeComponent.java b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java similarity index 77% rename from source/core/src/main/com/csse3200/game/components/AoeComponent.java rename to source/core/src/main/com/csse3200/game/components/EffectsComponent.java index 93403e8aa..e1e970ec5 100644 --- a/source/core/src/main/com/csse3200/game/components/AoeComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java @@ -2,14 +2,16 @@ import com.badlogic.gdx.physics.box2d.Fixture; import com.csse3200.game.entities.Entity; -import com.csse3200.game.physics.BodyUserData; +import com.csse3200.game.entities.factories.ProjectileFactory; import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.services.ServiceLocator; import com.badlogic.gdx.utils.Array; -public class AoeComponent extends Component { +public class EffectsComponent extends Component { private final float radius; + private final ProjectileFactory.ProjectileEffects effect; + private final boolean aoe; private HitboxComponent hitboxComponent; /** @@ -17,8 +19,10 @@ public class AoeComponent extends Component { * * @param radius The radius of the area-of-effect. */ - public AoeComponent(float radius) { + public EffectsComponent(float radius, ProjectileFactory.ProjectileEffects effect, boolean aoe) { this.radius = radius; + this.effect = effect; + this.aoe = aoe; } @Override @@ -37,7 +41,14 @@ private void onCollisionEnd(Fixture me, Fixture other) { // Not triggered by hitbox, ignore return; } - applyAoeDamage(); + switch (effect) { + case FIREBALL -> { + applyAoeDamage(); + } + case BURN -> {} + case SLOW -> {} + case STUN -> {} + } } /** * Apply damage to all entities within the area of effect (radius). 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 33d596599..4d451d93f 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 @@ -1,6 +1,6 @@ package com.csse3200.game.entities.factories; -import com.csse3200.game.components.AoeComponent; +import com.csse3200.game.components.EffectsComponent; import com.csse3200.game.components.TouchAttackComponent; import com.csse3200.game.components.tasks.TrajectTask; import com.csse3200.game.ai.tasks.AITaskComponent; @@ -23,9 +23,47 @@ */ public class ProjectileFactory { + public enum ProjectileEffects { + FIREBALL, //fireball projectile - deals damage based on baseAttack + BURN, //burn projectile - does 5 extra ticks of damage over 5 seconds + SLOW, //slow projectile - slows entity by half for 5 seconds + STUN //stun projectile - stuns entity for 5 seconds + } + private static final NPCConfigs configs = FileLoader.readClass(NPCConfigs.class, "configs/NPCs.json"); + /** + * Creates a single-targeting projectile with specified effect + * + * @param target The enemy entities that the projectile collides with. + * @param destination The destination the projectile heads towards. + * @param speed The speed of the projectile. + * @param effect Specified effect from the ProjectileEffects enums + * @return Returns a new single-target projectile entity + */ + public static Entity createEffectProjectile(Entity target, Vector2 destination, Vector2 speed, + ProjectileEffects effect, boolean aoe) { + BaseEntityConfig config = configs.fireBall; + Entity projectile = createFireBall(target, destination, speed); + + switch(effect) { + case FIREBALL -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.FIREBALL, aoe)); + } + case BURN -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.BURN, aoe)); + } + case SLOW -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.SLOW, aoe)); + } + case STUN -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.STUN, aoe)); + } + } + return projectile; + } + /** * Creates a fireball Entity. * @@ -56,24 +94,24 @@ public static Entity createFireBall(Entity target, Vector2 destination, Vector2 return projectile; } - /** - * Creates an AOE fireball Entity. - * - * @param target The enemy entities that the projectile collides with. - * @param destination The destination the projectile heads towards. - * @param speed The speed of the projectile. - * @param aoeSize The size of the AOE. - * @return Returns the new aoe projectile entity. - */ - public static Entity createAOEFireBall(Entity target, Vector2 destination, Vector2 speed, int aoeSize) { - BaseEntityConfig config = configs.fireBall; - Entity projectile = createFireBall(target, destination, speed); - projectile - // This is the component that allows the projectile to damage a specified target. - .addComponent(new AoeComponent(aoeSize)); - - return projectile; - } +// /** +// * Creates an AOE fireball Entity. +// * +// * @param target The enemy entities that the projectile collides with. +// * @param destination The destination the projectile heads towards. +// * @param speed The speed of the projectile. +// * @param aoeSize The size of the AOE. +// * @return Returns the new aoe projectile entity. +// */ +// public static Entity createAOEFireBall(Entity target, Vector2 destination, Vector2 speed, int aoeSize) { +// BaseEntityConfig config = configs.fireBall; +// Entity projectile = createFireBall(target, destination, speed); +// projectile +// // This is the component that allows the projectile to damage a specified target. +// .addComponent(new EffectsComponent(aoeSize, ProjectileEffects.FIREBALL, true)); +// +// return projectile; +// } /** * Creates a generic projectile entity that can be used for multiple types of * projectiles. From 6a87a8892411252916fae2cc813de8c14b28d53d Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Wed, 6 Sep 2023 22:47:44 +1000 Subject: [PATCH 03/10] Switched old aoe projectile function calls with new effect projectile function calls --- .../main/com/csse3200/game/areas/ForestGameArea.java | 10 ++++++---- .../com/csse3200/game/components/EffectsComponent.java | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) 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 c3e93e6ef..5b03db094 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -142,7 +142,7 @@ public void create() { playMusic(); // Types of projectile - spawnAoeProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), 1); + spawnEffectProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), ProjectileFactory.ProjectileEffects.FIREBALL, true); spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f)); spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7); spawnXenoGrunts(); @@ -377,10 +377,12 @@ private void spawnMultiProjectile(Vector2 position, Entity target, int direction * @param target The enemy entities of the "shooter". * @param direction The direction the projectile should head towards. * @param speed The speed of the projectiles. - * @param aoeSize The size of the area of effect. + * @param effect Type of effect. + * @param aoe Whether it is an aoe projectile. */ - private void spawnAoeProjectile(Vector2 position, Entity target, int direction, Vector2 speed, int aoeSize) { - Entity Projectile = ProjectileFactory.createAOEFireBall(target, new Vector2(direction, position.y), speed, aoeSize); + private void spawnEffectProjectile(Vector2 position, Entity target, int direction, Vector2 speed, + ProjectileFactory.ProjectileEffects effect, boolean aoe) { + Entity Projectile = ProjectileFactory.createEffectProjectile(target, new Vector2(direction, position.y), speed, effect, aoe); Projectile.setPosition(position); spawnEntity(Projectile); } diff --git a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java index e1e970ec5..0f6d9d352 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java @@ -43,7 +43,9 @@ private void onCollisionEnd(Fixture me, Fixture other) { } switch (effect) { case FIREBALL -> { - applyAoeDamage(); + if (aoe) { + applyAoeDamage(); + } } case BURN -> {} case SLOW -> {} From 0fe0c34846ac8720e292f3bd6f0eed0fe4b0f3ca Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Thu, 7 Sep 2023 14:03:19 +1000 Subject: [PATCH 04/10] Fixed issue where when creating a projectile the target parameter wasn't actually doing anything. Now uses PhysicsLayer to target. --- .../csse3200/game/areas/ForestGameArea.java | 31 ++++++------- .../game/components/EffectsComponent.java | 15 +++++-- .../components/tasks/TowerCombatTask.java | 2 +- .../entities/factories/ProjectileFactory.java | 44 +++++-------------- .../factories/ProjectileFactoryTest.java | 3 +- 5 files changed, 43 insertions(+), 52 deletions(-) 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 5b03db094..cef2ff09b 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -10,6 +10,7 @@ import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.factories.*; +import com.csse3200.game.physics.PhysicsLayer; import com.csse3200.game.utils.math.GridPoint2Utils; import com.csse3200.game.utils.math.RandomUtils; import com.csse3200.game.services.ResourceService; @@ -142,9 +143,9 @@ public void create() { playMusic(); // Types of projectile - spawnEffectProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), ProjectileFactory.ProjectileEffects.FIREBALL, true); - spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f)); - spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7); + spawnEffectProjectile(new Vector2(0, 10), PhysicsLayer.PLAYER, towardsMobs, new Vector2(2f, 2f), ProjectileFactory.ProjectileEffects.FIREBALL, true); +// spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f)); +// spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7); spawnXenoGrunts(); spawnGhosts(); @@ -269,13 +270,13 @@ private Entity spawnBossKing1() { * Spawns a projectile that only heads towards the enemies in its lane. * * @param position The position of the Entity that's shooting the projectile. - * @param target The enemy entities of the "shooter". + * @param targetLayer The enemy layer of the "shooter". * @param direction The direction the projectile should head towards. * @param speed The speed of the projectiles. * */ - private void spawnProjectile(Vector2 position, Entity target, int direction, Vector2 speed) { - Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y), speed); + private void spawnProjectile(Vector2 position, short targetLayer, int direction, Vector2 speed) { + Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y), speed); Projectile.setPosition(position); spawnEntity(Projectile); } @@ -284,14 +285,14 @@ private void spawnProjectile(Vector2 position, Entity target, int direction, Vec * Spawns a projectile to be used for multiple projectile function. * * @param position The position of the Entity that's shooting the projectile. - * @param target The enemy entities of the "shooter". + * @param targetLayer The enemy layer of the "shooter". * @param space The space between the projectiles' destination. * @param direction The direction the projectile should head towards. * @param speed The speed of the projectiles. * */ - private void spawnProjectile(Vector2 position, Entity target, int space, int direction, Vector2 speed) { - Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y + space), speed); + private void spawnProjectile(Vector2 position, short targetLayer, int space, int direction, Vector2 speed) { + Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y + space), speed); Projectile.setPosition(position); spawnEntity(Projectile); } @@ -356,16 +357,16 @@ private Entity spawnBossKing2() { * the starting point but different destinations. * * @param position The position of the Entity that's shooting the projectile. - * @param target The enemy entities of the "shooter". + * @param targetLayer The enemy layer of the "shooter". * @param direction The direction the projectile should head towards. * @param space The space between the projectiles' destination. * @param speed The speed of the projectiles. * @param quantity The amount of projectiles to spawn. */ - private void spawnMultiProjectile(Vector2 position, Entity target, int direction, int space, Vector2 speed, int quantity) { + private void spawnMultiProjectile(Vector2 position, short targetLayer, int direction, int space, Vector2 speed, int quantity) { int half = quantity / 2; for (int i = 0; i < quantity; i++) { - spawnProjectile(position, target, space * half, direction, speed); + spawnProjectile(position, targetLayer, space * half, direction, speed); --half; } } @@ -374,15 +375,15 @@ private void spawnMultiProjectile(Vector2 position, Entity target, int direction * Returns projectile that can do an area of effect damage * * @param position The position of the Entity that's shooting the projectile. - * @param target The enemy entities of the "shooter". + * @param targetLayer The enemy layer of the "shooter". * @param direction The direction the projectile should head towards. * @param speed The speed of the projectiles. * @param effect Type of effect. * @param aoe Whether it is an aoe projectile. */ - private void spawnEffectProjectile(Vector2 position, Entity target, int direction, Vector2 speed, + private void spawnEffectProjectile(Vector2 position, short targetLayer, int direction, Vector2 speed, ProjectileFactory.ProjectileEffects effect, boolean aoe) { - Entity Projectile = ProjectileFactory.createEffectProjectile(target, new Vector2(direction, position.y), speed, effect, aoe); + Entity Projectile = ProjectileFactory.createEffectProjectile(targetLayer, new Vector2(direction, position.y), speed, effect, aoe); Projectile.setPosition(position); spawnEntity(Projectile); } diff --git a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java index 0f6d9d352..0a580a43b 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java @@ -3,6 +3,7 @@ import com.badlogic.gdx.physics.box2d.Fixture; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.factories.ProjectileFactory; +import com.csse3200.game.physics.PhysicsLayer; import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.services.ServiceLocator; @@ -13,13 +14,15 @@ public class EffectsComponent extends Component { private final ProjectileFactory.ProjectileEffects effect; private final boolean aoe; private HitboxComponent hitboxComponent; + private final short targetLayer; /** * Constructor for the AoEComponent. * * @param radius The radius of the area-of-effect. */ - public EffectsComponent(float radius, ProjectileFactory.ProjectileEffects effect, boolean aoe) { + public EffectsComponent(short targetLayer, float radius, ProjectileFactory.ProjectileEffects effect, boolean aoe) { + this.targetLayer = targetLayer; this.radius = radius; this.effect = effect; this.aoe = aoe; @@ -27,8 +30,8 @@ public EffectsComponent(float radius, ProjectileFactory.ProjectileEffects effect @Override public void create() { - entity.getEvents().addListener("collisionStart", this::onCollisionStart); - entity.getEvents().addListener("collisionEnd", this::onCollisionEnd); + entity.getEvents().addListener("projectileCollisionStart", this::onCollisionStart); + entity.getEvents().addListener("projectileCollisionEnd", this::onCollisionEnd); hitboxComponent = entity.getComponent(HitboxComponent.class); } @@ -41,6 +44,12 @@ private void onCollisionEnd(Fixture me, Fixture other) { // Not triggered by hitbox, ignore return; } + + if (!PhysicsLayer.contains(targetLayer, other.getFilterData().categoryBits)) { + // Doesn't match our target layer, ignore + return; + } + switch (effect) { case FIREBALL -> { if (aoe) { diff --git a/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java index bae13b0fd..cf214240c 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java @@ -112,7 +112,7 @@ public void updateTowerState() { } else { 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(owner.getEntity(), new Vector2(100, owner.getEntity().getPosition().y), new Vector2(2f,2f)); + Entity newProjectile = ProjectileFactory.createFireBall(PhysicsLayer.PLAYER, new Vector2(100, owner.getEntity().getPosition().y), new Vector2(2f,2f)); newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.75), (float) (owner.getEntity().getPosition().y + 0.75)); ServiceLocator.getEntityService().register(newProjectile); } 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 4d451d93f..1de2cadf5 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 @@ -36,29 +36,29 @@ public enum ProjectileEffects { /** * Creates a single-targeting projectile with specified effect * - * @param target The enemy entities that the projectile collides with. + * @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. * @param effect Specified effect from the ProjectileEffects enums * @return Returns a new single-target projectile entity */ - public static Entity createEffectProjectile(Entity target, Vector2 destination, Vector2 speed, + public static Entity createEffectProjectile(short targetLayer, Vector2 destination, Vector2 speed, ProjectileEffects effect, boolean aoe) { BaseEntityConfig config = configs.fireBall; - Entity projectile = createFireBall(target, destination, speed); + Entity projectile = createFireBall(targetLayer, destination, speed); switch(effect) { case FIREBALL -> { - projectile.addComponent(new EffectsComponent(3, ProjectileEffects.FIREBALL, aoe)); + projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.FIREBALL, aoe)); } case BURN -> { - projectile.addComponent(new EffectsComponent(3, ProjectileEffects.BURN, aoe)); + projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.BURN, aoe)); } case SLOW -> { - projectile.addComponent(new EffectsComponent(3, ProjectileEffects.SLOW, aoe)); + projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.SLOW, aoe)); } case STUN -> { - projectile.addComponent(new EffectsComponent(3, ProjectileEffects.STUN, aoe)); + projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.STUN, aoe)); } } return projectile; @@ -67,22 +67,22 @@ public static Entity createEffectProjectile(Entity target, Vector2 destination, /** * Creates a fireball Entity. * - * @param target The enemy entities that the projectile collides with. + * @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 createFireBall(Entity target, Vector2 destination, Vector2 speed) { + public static Entity createFireBall(short targetLayer, Vector2 destination, Vector2 speed) { BaseEntityConfig config = configs.fireBall; - Entity projectile = createBaseProjectile(target, destination); + Entity projectile = createBaseProjectile(destination); projectile .addComponent(new TextureRenderComponent("images/projectiles/projectile.png")) .addComponent(new ColliderComponent().setSensor(true)) // This is the component that allows the projectile to damage a specified target. - .addComponent(new TouchAttackComponent(PhysicsLayer.PLAYER, 1.5f, true)) + .addComponent(new TouchAttackComponent(targetLayer, 1.5f, true)) .addComponent(new CombatStatsComponent(config.health, config.baseAttack)); projectile @@ -94,33 +94,13 @@ public static Entity createFireBall(Entity target, Vector2 destination, Vector2 return projectile; } -// /** -// * Creates an AOE fireball Entity. -// * -// * @param target The enemy entities that the projectile collides with. -// * @param destination The destination the projectile heads towards. -// * @param speed The speed of the projectile. -// * @param aoeSize The size of the AOE. -// * @return Returns the new aoe projectile entity. -// */ -// public static Entity createAOEFireBall(Entity target, Vector2 destination, Vector2 speed, int aoeSize) { -// BaseEntityConfig config = configs.fireBall; -// Entity projectile = createFireBall(target, destination, speed); -// projectile -// // This is the component that allows the projectile to damage a specified target. -// .addComponent(new EffectsComponent(aoeSize, ProjectileEffects.FIREBALL, true)); -// -// return projectile; -// } - /** * Creates a generic projectile entity that can be used for multiple types of * projectiles. * - * @param target The enemy entities that the projectile collides with. * @param destination The destination the projectile heads towards. * @return Returns a generic projectile entity. */ - public static Entity createBaseProjectile(Entity target, Vector2 destination) { + public static Entity createBaseProjectile(Vector2 destination) { AITaskComponent aiComponent = new AITaskComponent() .addTask(new TrajectTask(destination)); diff --git a/source/core/src/test/com/csse3200/game/entities/factories/ProjectileFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/ProjectileFactoryTest.java index 1e5c4fb27..5d4f9d686 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/ProjectileFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/ProjectileFactoryTest.java @@ -11,6 +11,7 @@ import com.csse3200.game.entities.EntityService; import com.csse3200.game.areas.ForestGameArea; import com.csse3200.game.extensions.GameExtension; +import com.csse3200.game.physics.PhysicsLayer; import com.csse3200.game.physics.PhysicsService; import com.csse3200.game.physics.components.ColliderComponent; import com.csse3200.game.physics.components.HitboxComponent; @@ -51,7 +52,7 @@ public void setUp() { Vector2 destination = new Vector2(0.1f, 0.1f); Vector2 speed = new Vector2(0.2f, 0.2f); - projectile = ProjectileFactory.createBaseProjectile(new Entity(), destination); + projectile = ProjectileFactory.createBaseProjectile(destination); } @Test From 3b59ae85467e6ef0f8467abef45b7b79ac9221fb Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Thu, 7 Sep 2023 14:59:30 +1000 Subject: [PATCH 05/10] Made ProjectileEffects enum class its own class instead of being in ProjectileFactory --- .../main/com/csse3200/game/areas/ForestGameArea.java | 5 +++-- .../com/csse3200/game/components/EffectsComponent.java | 10 +++++----- .../csse3200/game/components/ProjectileEffects.java | 8 ++++++++ .../game/entities/factories/ProjectileFactory.java | 8 +------- 4 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 source/core/src/main/com/csse3200/game/components/ProjectileEffects.java 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 cef2ff09b..e6ebd0769 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; +import com.csse3200.game.components.ProjectileEffects; import com.csse3200.game.input.DropInputComponent; import com.csse3200.game.areas.terrain.TerrainFactory; import com.csse3200.game.areas.terrain.TerrainFactory.TerrainType; @@ -143,7 +144,7 @@ public void create() { playMusic(); // Types of projectile - spawnEffectProjectile(new Vector2(0, 10), PhysicsLayer.PLAYER, towardsMobs, new Vector2(2f, 2f), ProjectileFactory.ProjectileEffects.FIREBALL, true); + spawnEffectProjectile(new Vector2(0, 10), PhysicsLayer.PLAYER, towardsMobs, new Vector2(2f, 2f), ProjectileEffects.FIREBALL, true); // spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f)); // spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7); spawnXenoGrunts(); @@ -382,7 +383,7 @@ private void spawnMultiProjectile(Vector2 position, short targetLayer, int direc * @param aoe Whether it is an aoe projectile. */ private void spawnEffectProjectile(Vector2 position, short targetLayer, int direction, Vector2 speed, - ProjectileFactory.ProjectileEffects effect, boolean aoe) { + ProjectileEffects effect, boolean aoe) { Entity Projectile = ProjectileFactory.createEffectProjectile(targetLayer, new Vector2(direction, position.y), speed, effect, aoe); Projectile.setPosition(position); spawnEntity(Projectile); diff --git a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java index 0a580a43b..0fb98fcf7 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java @@ -11,7 +11,7 @@ public class EffectsComponent extends Component { private final float radius; - private final ProjectileFactory.ProjectileEffects effect; + private final ProjectileEffects effect; private final boolean aoe; private HitboxComponent hitboxComponent; private final short targetLayer; @@ -21,7 +21,7 @@ public class EffectsComponent extends Component { * * @param radius The radius of the area-of-effect. */ - public EffectsComponent(short targetLayer, float radius, ProjectileFactory.ProjectileEffects effect, boolean aoe) { + public EffectsComponent(short targetLayer, float radius, ProjectileEffects effect, boolean aoe) { this.targetLayer = targetLayer; this.radius = radius; this.effect = effect; @@ -53,7 +53,7 @@ private void onCollisionEnd(Fixture me, Fixture other) { switch (effect) { case FIREBALL -> { if (aoe) { - applyAoeDamage(); + applyAoeEffect(ProjectileEffects.FIREBALL); } } case BURN -> {} @@ -62,9 +62,9 @@ private void onCollisionEnd(Fixture me, Fixture other) { } } /** - * Apply damage to all entities within the area of effect (radius). + * Used for aoe fireball projectile to apply damage to all entities within the area of effect (radius). */ - public void applyAoeDamage() { + public void applyAoeEffect(ProjectileEffects effect) { Entity hostEntity = getEntity(); CombatStatsComponent hostCombatStats = hostEntity.getComponent(CombatStatsComponent.class); diff --git a/source/core/src/main/com/csse3200/game/components/ProjectileEffects.java b/source/core/src/main/com/csse3200/game/components/ProjectileEffects.java new file mode 100644 index 000000000..39259b414 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/ProjectileEffects.java @@ -0,0 +1,8 @@ +package com.csse3200.game.components; + +public enum ProjectileEffects { + FIREBALL, //fireball projectile - deals damage based on baseAttack + BURN, //burn projectile - does 5 extra ticks of damage over 5 seconds + SLOW, //slow projectile - slows entity by half for 5 seconds + STUN //stun projectile - stuns entity for 5 seconds +} 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 1de2cadf5..4ec4c9e5f 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 @@ -1,6 +1,7 @@ package com.csse3200.game.entities.factories; import com.csse3200.game.components.EffectsComponent; +import com.csse3200.game.components.ProjectileEffects; import com.csse3200.game.components.TouchAttackComponent; import com.csse3200.game.components.tasks.TrajectTask; import com.csse3200.game.ai.tasks.AITaskComponent; @@ -23,13 +24,6 @@ */ public class ProjectileFactory { - public enum ProjectileEffects { - FIREBALL, //fireball projectile - deals damage based on baseAttack - BURN, //burn projectile - does 5 extra ticks of damage over 5 seconds - SLOW, //slow projectile - slows entity by half for 5 seconds - STUN //stun projectile - stuns entity for 5 seconds - } - private static final NPCConfigs configs = FileLoader.readClass(NPCConfigs.class, "configs/NPCs.json"); From ebb9ce2175e1c1d8c60fde21ddf4c0f11b2b3721 Mon Sep 17 00:00:00 2001 From: MiniSoda17 Date: Thu, 7 Sep 2023 15:21:45 +1000 Subject: [PATCH 06/10] Added a new method that creates mob ball projectiles with animation --- .../images/projectiles/mobProjectile.atlas | 41 +++++++++++++++++ .../images/projectiles/mobProjectile.png | Bin 0 -> 608 bytes .../csse3200/game/areas/ForestGameArea.java | 24 +++++++--- .../MobProjectileAnimationController.java | 23 ++++++++++ .../game/components/tasks/TrajectTask.java | 2 +- .../entities/factories/ProjectileFactory.java | 43 ++++++++++++++++++ 6 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 source/core/assets/images/projectiles/mobProjectile.atlas create mode 100644 source/core/assets/images/projectiles/mobProjectile.png create mode 100644 source/core/src/main/com/csse3200/game/components/MobProjectileAnimationController.java diff --git a/source/core/assets/images/projectiles/mobProjectile.atlas b/source/core/assets/images/projectiles/mobProjectile.atlas new file mode 100644 index 000000000..5dabfa025 --- /dev/null +++ b/source/core/assets/images/projectiles/mobProjectile.atlas @@ -0,0 +1,41 @@ + +mobProjectile.png +size: 128, 32 +format: RGBA8888 +filter: Nearest, Nearest +repeat: none +rotate + rotate: false + xy: 80, 2 + size: 24, 23 + orig: 24, 23 + offset: 0, 0 + index: -1 +rotate + rotate: false + xy: 28, 2 + size: 24, 23 + orig: 24, 23 + offset: 0, 0 + index: -1 +default + rotate: false + xy: 28, 2 + size: 24, 23 + orig: 24, 23 + offset: 0, 0 + index: -1 +rotate + rotate: false + xy: 2, 2 + size: 24, 23 + orig: 24, 23 + offset: 0, 0 + index: -1 +rotate + rotate: false + xy: 54, 2 + size: 24, 23 + orig: 24, 23 + offset: 0, 0 + index: -1 diff --git a/source/core/assets/images/projectiles/mobProjectile.png b/source/core/assets/images/projectiles/mobProjectile.png new file mode 100644 index 0000000000000000000000000000000000000000..9194760504b25240c5b0309bfdf675ac56f43508 GIT binary patch literal 608 zcmV-m0-ybfP)OwPF53vEOh34 zqqcZx_M-or7a4r>;h<&)wE1`vVvf9{(LJoaA6mYP34zR{(b=la3!1xH51Ct0wE6Rw z+j8w`EnM%0G^0&vy|(1q)9SpRg@iz!MaY`Z)pelG%KdRj2(2A=~?CRYE^H1fDvW2h2ww(wEee zd-!-fb1M!OXwApq(2Tbc3>>D|03ZZjV{{#<0of3E>*%?`c=Uu?5pye!4FJqXGjfe+ zWE=s|@75uRsFMqTtrIb~;^;Z*fzqz$s&UsQ8T8*A6xiX)4|Q3cIt!F(KfMn#5=qZdM;1ygW@8x?sLM@fW03n9ai zbW~&(I2z;Q(SrFnV*hJ&GdX$92RZ~fc})R21UY#_24p7qcygKu^MPHwRTS0?t0?Sy ut)j4VvLb{KLI@#*5JCtcgb+dqDaj8(v8KX@qyJ?90000 Date: Thu, 7 Sep 2023 15:24:39 +1000 Subject: [PATCH 07/10] Edited the javadoc for mob ball --- .../com/csse3200/game/entities/factories/ProjectileFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 71e98cce4..e373170fb 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 @@ -62,7 +62,7 @@ public static Entity createFireBall(Entity target, Vector2 destination, Vector2 } /** - * Creates a fireball Entity. + * Creates a projectile specifically for mobs to shoot * * @param target The enemy entities that the projectile collides with. * @param destination The destination the projectile heads towards. From 5700e00f29a1fe367c798414461dd207fe65c969 Mon Sep 17 00:00:00 2001 From: MiniSoda17 Date: Thu, 7 Sep 2023 15:37:06 +1000 Subject: [PATCH 08/10] Reversed the animation of the mob projectile to face the towers --- .../core/assets/images/projectiles/mobProjectile.atlas | 10 +++++----- .../main/com/csse3200/game/areas/ForestGameArea.java | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/core/assets/images/projectiles/mobProjectile.atlas b/source/core/assets/images/projectiles/mobProjectile.atlas index 5dabfa025..2a0f5357f 100644 --- a/source/core/assets/images/projectiles/mobProjectile.atlas +++ b/source/core/assets/images/projectiles/mobProjectile.atlas @@ -6,35 +6,35 @@ filter: Nearest, Nearest repeat: none rotate rotate: false - xy: 80, 2 + xy: 54, 2 size: 24, 23 orig: 24, 23 offset: 0, 0 index: -1 rotate rotate: false - xy: 28, 2 + xy: 2, 2 size: 24, 23 orig: 24, 23 offset: 0, 0 index: -1 default rotate: false - xy: 28, 2 + xy: 54, 2 size: 24, 23 orig: 24, 23 offset: 0, 0 index: -1 rotate rotate: false - xy: 2, 2 + xy: 28, 2 size: 24, 23 orig: 24, 23 offset: 0, 0 index: -1 rotate rotate: false - xy: 54, 2 + xy: 80, 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 ea3788ae9..f18d400ee 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -114,6 +114,7 @@ public class ForestGameArea extends GameArea { // Variables to be used with spawn projectile methods. This is the variable // that should occupy the direction param. private static final int towardsMobs = 100; + private static final int towardsTowers = 0; private Entity bossKing1; private Entity bossKing2; @@ -145,7 +146,7 @@ public void create() { // spawnAoeProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), 1); spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f)); - spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7); + spawnMultiProjectile(new Vector2(15, 10), player, towardsTowers, 20, new Vector2(2f, 2f), 7); spawnXenoGrunts(); From 0f6b0c11465154bbaca0cf28ae3d6a69e7b519b4 Mon Sep 17 00:00:00 2001 From: MiniSoda17 Date: Thu, 7 Sep 2023 16:41:18 +1000 Subject: [PATCH 09/10] Added a new spawn mob ball method in ForestGameArea --- .../csse3200/game/areas/ForestGameArea.java | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) 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 f18d400ee..95bea77ab 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -144,9 +144,11 @@ public void create() { playMusic(); - // spawnAoeProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), 1); + spawnAoeProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f), 1); spawnProjectile(new Vector2(0, 10), player, towardsMobs, new Vector2(2f, 2f)); - spawnMultiProjectile(new Vector2(15, 10), player, towardsTowers, 20, new Vector2(2f, 2f), 7); + + spawnMobBall(new Vector2(15, 10), player, towardsTowers, new Vector2(2f, 2f)); + spawnMultiProjectile(new Vector2(0, 10), player, towardsMobs, 20, new Vector2(2f, 2f), 7); spawnXenoGrunts(); @@ -277,13 +279,8 @@ private Entity spawnBossKing1() { * @param speed The speed of the projectiles. * */ - // private void spawnProjectile(Vector2 position, Entity target, int direction, Vector2 speed) { - // Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y), speed); - // Projectile.setPosition(position); - // spawnEntity(Projectile); - // } private void spawnProjectile(Vector2 position, Entity target, int direction, Vector2 speed) { - Entity Projectile = ProjectileFactory.createMobBall(target, new Vector2(direction, position.y), speed); + Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y), speed); Projectile.setPosition(position); spawnEntity(Projectile); } @@ -298,13 +295,24 @@ private void spawnProjectile(Vector2 position, Entity target, int direction, Vec * @param speed The speed of the projectiles. * */ - // private void spawnProjectile(Vector2 position, Entity target, int space, int direction, Vector2 speed) { - // Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y + space), speed); - // Projectile.setPosition(position); - // spawnEntity(Projectile); - // } private void spawnProjectile(Vector2 position, Entity target, int space, int direction, Vector2 speed) { - Entity Projectile = ProjectileFactory.createMobBall(target, new Vector2(direction, position.y + space), speed); + Entity Projectile = ProjectileFactory.createFireBall(target, new Vector2(direction, position.y + space), speed); + Projectile.setPosition(position); + spawnEntity(Projectile); + } + + /** + * Spawns a mob based projectile to be used for multiple projectile function. + * + * @param position The position of the Entity that's shooting the projectile. + * @param target The enemy entities of the "shooter". + * @param space The space between the projectiles' destination. + * @param direction The direction the projectile should head towards. + * @param speed The speed of the projectiles. + * + */ + private void spawnMobBall(Vector2 position, Entity target, int direction, Vector2 speed) { + Entity Projectile = ProjectileFactory.createMobBall(target, new Vector2(direction, position.y), speed); Projectile.setPosition(position); spawnEntity(Projectile); } From 7eaa3febfaef337f17db3b83966ced6655197d26 Mon Sep 17 00:00:00 2001 From: MiniSoda17 Date: Thu, 7 Sep 2023 17:02:04 +1000 Subject: [PATCH 10/10] Fixed merged conflicts --- .../csse3200/game/entities/factories/ProjectileFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 cad544597..4b7e957eb 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 @@ -101,10 +101,10 @@ public static Entity createFireBall(short targetLayer, Vector2 destination, Vect * @param speed The speed of the projectile. * @return Returns a new fireball projectile entity. */ - public static Entity createMobBall(Entity target, Vector2 destination, Vector2 speed) { + public static Entity createMobBall(short targetLayer, Vector2 destination, Vector2 speed) { BaseEntityConfig config = configs.fireBall; - Entity projectile = createBaseProjectile(target, destination); + Entity projectile = createBaseProjectile(destination); AnimationRenderComponent animator = new AnimationRenderComponent(