From d444b36351192463ff4b0a877eac1aedd1e11bed Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sat, 8 Nov 2014 15:17:45 +0100 Subject: [PATCH] Bugfix: Enemies do not hurt the player, player does not properly die. --- .../spacescooter/entity/LivingEntity.java | 6 +++--- .../spacescooter/entity/enemy/Enemy.java | 1 + .../spacescooter/entity/enemy/EnemyFour.java | 1 + .../spacescooter/entity/enemy/EnemyOne.java | 1 + .../spacescooter/entity/enemy/EnemyThree.java | 1 + .../spacescooter/entity/enemy/EnemyTwo.java | 1 + .../spacescooter/screen/GameScreen.java | 18 ++++++------------ 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 044bb3d..661ee90 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -100,12 +100,12 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl public void takeDamage(int damage) { //Skip everything if already dead. if(this.isAlive() == false) return; - if(this instanceof Shot) { - if(GameConfig.DEBUG) System.out.println("Shot took damage: " + damage + "left: "+this.getHealthPoints()+" (" + this + ")"); - } // TODO: shield and health logic this.healthPoints -= damage; if (this.isAlive() == false) { + //Set the correct values for gui indicators + this.healthPoints = 0; + this.shieldPoints = 0; if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP"); this.die(); } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java index 2871e27..56fb1a1 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java @@ -12,6 +12,7 @@ public abstract class Enemy extends ShootingEntity { this.name = "EnemyOne"; this.willShoot = r.nextBoolean(); this.setShootDirection(Shot.LEFT); + this.setShootDamage(5); } protected String name; diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java index 192a493..9acc966 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyFour.java @@ -20,6 +20,7 @@ public class EnemyFour extends Enemy{ this.setShootSpeed(4); this.setShootDelay(42); this.setShootSpawn(-10, 10); + this.setShootDamage(5); this.setHealthPoints(5); this.points = points; this.x = x; diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java index 4691ba7..b2c0e4f 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyOne.java @@ -9,6 +9,7 @@ public class EnemyOne extends Enemy { this.setShootSpeed(2); this.setShootDelay(42); this.setShootSpawn(-8, 10); + this.setShootDamage(5); this.setHealthPoints(5); this.setCollisionDamage(this.getHealthPoints()); } diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java index 990e102..48316f5 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java @@ -23,6 +23,7 @@ public class EnemyThree extends Enemy{ this.setShootSpeed(4); this.setShootDelay(42); this.setShootSpawn(-10, 10); + this.setShootDamage(5); this.setHealthPoints(15); this.setCollisionDamage(this.getHealthPoints()); this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight())); diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java index 2095680..1ad266c 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java @@ -14,6 +14,7 @@ public class EnemyTwo extends Enemy{ this.setShootSpeed(4); this.setShootDelay(42); this.setShootSpawn(-10, 10); + this.setShootDamage(5); this.setHealthPoints(5); this.setCollisionDamage(this.getHealthPoints()); this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight())); diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index d6a86da..363d23c 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -26,6 +26,8 @@ public class GameScreen extends Screen { private ArrayList points = new ArrayList(); + private Player player; + public GameScreen(Screen parent) { super(parent); new ItemChance(); @@ -33,7 +35,7 @@ public class GameScreen extends Screen { points.add(new Point(600,100)); points.add(new Point(0,500)); new StarBackground(0, 0); - new Player(200, 300); + this.player = new Player(200, 300); new HealthBar(10, 10); new EnemyFour(800, 400, points); new EnemyThree(650, 300); @@ -59,18 +61,10 @@ public class GameScreen extends Screen { if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) { this.setOverlay(new GamePausedScreen(this)); } - i.reset(); - while (i.hasNext()) { - Entity e = i.next(); - if (e instanceof Player) { - Player player = (Player) e; - if (!player.isAlive()) { - this.parent.setOverlay(new GameOverScreen(this.parent)); - } - } + if (!this.player.isAlive()) { + this.parent.setOverlay(new GameOverScreen(this.parent)); } - } - + }