Bugfix: Enemies do not hurt the player, player does not properly die.

This commit is contained in:
Jan Philipp Timme 2014-11-08 15:17:45 +01:00
parent 1086effdad
commit d444b36351
7 changed files with 14 additions and 15 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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;

View File

@ -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());
}

View File

@ -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()));

View File

@ -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()));

View File

@ -26,6 +26,8 @@ public class GameScreen extends Screen {
private ArrayList<Point> points = new ArrayList<Point>();
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));
}
}
}