From c7588629064ff1f507cc04e54a4f7743f39f2c6f Mon Sep 17 00:00:00 2001 From: Allexit Date: Sun, 10 May 2015 22:26:12 +0300 Subject: [PATCH] renamed listeners package, added test dummy to kill --- .../com/saltosion/gladiator/GladiatorBrawler.java | 15 +++++++++++++++ .../saltosion/gladiator/components/CPhysics.java | 2 +- .../CollisionListener.java | 2 +- .../SwingHitboxListener.java | 9 +++++++-- .../saltosion/gladiator/systems/CombatSystem.java | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) rename core/src/com/saltosion/gladiator/{collisionlisteners => listeners}/CollisionListener.java (91%) rename core/src/com/saltosion/gladiator/{collisionlisteners => listeners}/SwingHitboxListener.java (76%) diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index 9f9bab5..e0e10a8 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -66,6 +66,7 @@ public class GladiatorBrawler extends ApplicationAdapter { // Initialize stuff in the world initializePlayer(); + initializeTestDummy(); initializeLevel(); // Initialize input @@ -94,6 +95,20 @@ public class GladiatorBrawler extends ApplicationAdapter { AppUtil.player = player; } + + public void initializeTestDummy() { + Entity dummy = new Entity(); + CRenderedObject renderedObject = new CRenderedObject(); + Sprite player1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 64, 64); + Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64); + SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2); + renderedObject.addSequence("Idle", sequence); + renderedObject.playAnimation("Idle"); + dummy.add(renderedObject); + dummy.add(new CPhysics().setSize(2, 4).setPosition(-6, 5)); + dummy.add(new CCombat().setBaseDamage(100).setHealth(1000).setSwingCD(.5f)); + engine.addEntity(dummy); + } public void initializeLevel() { Entity ground = new Entity(); diff --git a/core/src/com/saltosion/gladiator/components/CPhysics.java b/core/src/com/saltosion/gladiator/components/CPhysics.java index 4270793..0279400 100644 --- a/core/src/com/saltosion/gladiator/components/CPhysics.java +++ b/core/src/com/saltosion/gladiator/components/CPhysics.java @@ -2,7 +2,7 @@ package com.saltosion.gladiator.components; import com.badlogic.ashley.core.Component; import com.badlogic.gdx.math.Vector2; -import com.saltosion.gladiator.collisionlisteners.CollisionListener; +import com.saltosion.gladiator.listeners.CollisionListener; public class CPhysics extends Component { diff --git a/core/src/com/saltosion/gladiator/collisionlisteners/CollisionListener.java b/core/src/com/saltosion/gladiator/listeners/CollisionListener.java similarity index 91% rename from core/src/com/saltosion/gladiator/collisionlisteners/CollisionListener.java rename to core/src/com/saltosion/gladiator/listeners/CollisionListener.java index 7364acc..ce747e9 100644 --- a/core/src/com/saltosion/gladiator/collisionlisteners/CollisionListener.java +++ b/core/src/com/saltosion/gladiator/listeners/CollisionListener.java @@ -1,4 +1,4 @@ -package com.saltosion.gladiator.collisionlisteners; +package com.saltosion.gladiator.listeners; import com.badlogic.ashley.core.Entity; import com.saltosion.gladiator.util.Direction; diff --git a/core/src/com/saltosion/gladiator/collisionlisteners/SwingHitboxListener.java b/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java similarity index 76% rename from core/src/com/saltosion/gladiator/collisionlisteners/SwingHitboxListener.java rename to core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java index 43c07ce..e987803 100644 --- a/core/src/com/saltosion/gladiator/collisionlisteners/SwingHitboxListener.java +++ b/core/src/com/saltosion/gladiator/listeners/SwingHitboxListener.java @@ -1,10 +1,11 @@ -package com.saltosion.gladiator.collisionlisteners; +package com.saltosion.gladiator.listeners; import java.util.ArrayList; import com.badlogic.ashley.core.ComponentMapper; import com.badlogic.ashley.core.Entity; import com.saltosion.gladiator.components.CCombat; +import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.Direction; public class SwingHitboxListener implements CollisionListener { @@ -31,7 +32,11 @@ public class SwingHitboxListener implements CollisionListener { } int damage = cm.get(source).getDamage(); otherCombat.health -= damage; - System.out.println("Entity was hit for " + damage + " damage!"); + System.out.println(String.format("Entity was hit for %d damage, it now has only %d health left!", + damage, otherCombat.health)); + if (otherCombat.health <= 0) { + AppUtil.engine.removeEntity(other); + } } } diff --git a/core/src/com/saltosion/gladiator/systems/CombatSystem.java b/core/src/com/saltosion/gladiator/systems/CombatSystem.java index f9052a6..e89802c 100644 --- a/core/src/com/saltosion/gladiator/systems/CombatSystem.java +++ b/core/src/com/saltosion/gladiator/systems/CombatSystem.java @@ -8,11 +8,11 @@ import com.badlogic.ashley.core.Family; import com.badlogic.ashley.utils.ImmutableArray; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Vector2; -import com.saltosion.gladiator.collisionlisteners.SwingHitboxListener; import com.saltosion.gladiator.components.CCombat; import com.saltosion.gladiator.components.CDestructive; import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CRenderedObject; +import com.saltosion.gladiator.listeners.SwingHitboxListener; import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Name;