From 68a0d139afc648dd29731b58d5f8b871eed9c12f Mon Sep 17 00:00:00 2001 From: Licht Date: Fri, 31 Oct 2014 12:10:41 +0100 Subject: [PATCH] Explosions added. They explode. --- .../spacescooter/entity/Explosion.java | 44 +++++++++++++++++++ .../spacescooter/entity/LivingEntity.java | 1 + .../spacescooter/screen/GameScreen.java | 2 + 3 files changed, 47 insertions(+) create mode 100644 src/de/teamteamteam/spacescooter/entity/Explosion.java diff --git a/src/de/teamteamteam/spacescooter/entity/Explosion.java b/src/de/teamteamteam/spacescooter/entity/Explosion.java new file mode 100644 index 0000000..6db501c --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/Explosion.java @@ -0,0 +1,44 @@ +package de.teamteamteam.spacescooter.entity; + + +public class Explosion extends Entity { + + private int count = 71; + + public Explosion(int x, int y) { + super(x, y); + this.setImage("images/explosion1.png"); + this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + } + + public void update() { + if (count >= 0) { + count--; + } else { + this.remove(); + } + switch (count) { + case 70: + this.setImage("images/explosion1.png"); + break; + case 60: + this.setImage("images/explosion2.png"); + break; + case 50: + this.setImage("images/explosion3.png"); + break; + case 40: + this.setImage("images/explosion4.png"); + break; + case 30: + this.setImage("images/explosion5.png"); + break; + case 20: + this.setImage("images/explosion6.png"); + break; + case 10: + this.setImage("images/explosion7.png"); + break; + } + } +} diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index f826fbd..687965d 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -79,6 +79,7 @@ public abstract class LivingEntity extends Entity implements Collidable { this.healthPoints -= damage; if (this.isAlive() == false) { if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP"); + Screen.currentScreen.addEntity(new Explosion(this.x, this.y)); this.remove(); } } diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 55fd6a3..eb00e8a 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -9,6 +9,7 @@ import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.entity.EnemyOne; import de.teamteamteam.spacescooter.entity.Entity; +import de.teamteamteam.spacescooter.entity.Explosion; import de.teamteamteam.spacescooter.entity.Player; public class GameScreen extends Screen { @@ -21,6 +22,7 @@ public class GameScreen extends Screen { this.entities.add(new EnemyOne(450, 100)); this.entities.add(new EnemyOne(750, 550)); this.entities.add(new EnemyOne(150, 250)); + this.entities.add(new Explosion(200, 200)); } @Override