diff --git a/res/images/explosion_proto.png b/res/images/explosion_proto.png new file mode 100644 index 0000000..fa65018 Binary files /dev/null and b/res/images/explosion_proto.png differ diff --git a/src/de/teamteamteam/spacescooter/entity/Explosion.java b/src/de/teamteamteam/spacescooter/entity/Explosion.java index 6db501c..caa8391 100644 --- a/src/de/teamteamteam/spacescooter/entity/Explosion.java +++ b/src/de/teamteamteam/spacescooter/entity/Explosion.java @@ -1,44 +1,53 @@ package de.teamteamteam.spacescooter.entity; +import java.util.Random; -public class Explosion extends Entity { +import de.teamteamteam.spacescooter.screen.Screen; - private int count = 71; + +public class Explosion extends LivingEntity { + + private boolean isActive = true; public Explosion(int x, int y) { super(x, y); - this.setImage("images/explosion1.png"); + this.setImage("images/explosion_proto.png"); this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + Random rand = new Random(); + if (rand.nextInt(99) <= 70) { + Screen.currentScreen.addEntity(new ExplosionOne(x, y)); + } else { + Screen.currentScreen.addEntity(new ExplosionTwo(x, y)); + } + } + + public Explosion(final int x, final int y, final int count, final int height, final int width) { + super(x, y); + this.setImage("images/explosion_proto.png"); + this.setPosition(x, y); + Thread explosionThread = new Thread(new Runnable() { //not yet compatible + public void run() { + Random rnd = new Random(); + for (int i = 0; i <= count; i++) { + new Explosion(x + (int) (width*rnd.nextDouble()), y + (int) (height*rnd.nextDouble())); + try { + Thread.sleep(5); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (i == count - 1) { + isActive = false; + } + } + } + }); + explosionThread.start(); + if(!this.isActive) { + this.remove(); + } } 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/ExplosionOne.java b/src/de/teamteamteam/spacescooter/entity/ExplosionOne.java new file mode 100644 index 0000000..6c8f96c --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/ExplosionOne.java @@ -0,0 +1,43 @@ +package de.teamteamteam.spacescooter.entity; + +public class ExplosionOne extends LivingEntity { + + private int count = 71; + + public ExplosionOne(int x, int y) { + super(x, y); + this.setImage("images/explosion_proto.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/ExplosionBig.java b/src/de/teamteamteam/spacescooter/entity/ExplosionTwo.java similarity index 86% rename from src/de/teamteamteam/spacescooter/entity/ExplosionBig.java rename to src/de/teamteamteam/spacescooter/entity/ExplosionTwo.java index eb6f8cf..b5defd0 100644 --- a/src/de/teamteamteam/spacescooter/entity/ExplosionBig.java +++ b/src/de/teamteamteam/spacescooter/entity/ExplosionTwo.java @@ -1,11 +1,13 @@ package de.teamteamteam.spacescooter.entity; -public class ExplosionBig extends Explosion { +public class ExplosionTwo extends LivingEntity { private int count = 141; - public ExplosionBig(int x, int y) { + public ExplosionTwo(int x, int y) { super(x, y); + this.setImage("images/explosion_proto.png"); + this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); } public void update() { diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index b000198..7c8b9c8 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -2,7 +2,6 @@ package de.teamteamteam.spacescooter.entity; import java.awt.Rectangle; import java.util.LinkedList; -import java.util.Random; import de.teamteamteam.spacescooter.screen.Screen; import de.teamteamteam.spacescooter.utility.GameConfig; @@ -91,12 +90,7 @@ public abstract class LivingEntity extends Entity implements Collidable { } private void explode() { - Random rnd = new Random(); - if (rnd.nextInt(99) < 70) { - Screen.currentScreen.addEntity(new Explosion(this.x, this.y)); - } else { - Screen.currentScreen.addEntity(new ExplosionBig(this.x, this.y)); - } + Screen.currentScreen.addEntity(new Explosion(this.x, this.y)); } public void setHealthPoints(int hp) { diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 55a53b8..051d0cf 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -12,6 +12,7 @@ import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.entity.EnemyFour; import de.teamteamteam.spacescooter.entity.EnemyThree; import de.teamteamteam.spacescooter.entity.Entity; +import de.teamteamteam.spacescooter.entity.Explosion; import de.teamteamteam.spacescooter.entity.ItemChance; import de.teamteamteam.spacescooter.entity.Player;