diff --git a/src/de/teamteamteam/spacescooter/gui/HealthBar.java b/src/de/teamteamteam/spacescooter/gui/HealthBar.java index 462244e..80ad595 100644 --- a/src/de/teamteamteam/spacescooter/gui/HealthBar.java +++ b/src/de/teamteamteam/spacescooter/gui/HealthBar.java @@ -4,10 +4,9 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; -import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator; import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Player; -import de.teamteamteam.spacescooter.screen.Screen; +import de.teamteamteam.spacescooter.screen.GameScreen; public class HealthBar extends Entity { @@ -16,22 +15,12 @@ public class HealthBar extends Entity { private int health = 0; private int healthwidth = 0; - private ConcurrentIterator entityIterator; - public HealthBar(int x, int y) { super(x, y); - this.entityIterator = Screen.currentScreen.createEntityIterator(); } public void paint(Graphics2D g) { - Player player = null; - this.entityIterator.reset(); - while(this.entityIterator.hasNext()) { - Entity e = this.entityIterator.next(); - if(e instanceof Player){ - player = ((Player) e); - } - } + Player player = GameScreen.getPlayer(); try { this.health = player.getHealthPoints(); this.healthwidth = ((this.width) * this.health) / 100; diff --git a/src/de/teamteamteam/spacescooter/gui/ShieldBar.java b/src/de/teamteamteam/spacescooter/gui/ShieldBar.java index 856c925..6dc14b8 100644 --- a/src/de/teamteamteam/spacescooter/gui/ShieldBar.java +++ b/src/de/teamteamteam/spacescooter/gui/ShieldBar.java @@ -4,10 +4,9 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; -import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator; import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Player; -import de.teamteamteam.spacescooter.screen.Screen; +import de.teamteamteam.spacescooter.screen.GameScreen; public class ShieldBar extends Entity { @@ -16,22 +15,12 @@ public class ShieldBar extends Entity { private int shield = 0; private int shieldwidth = 0; - private ConcurrentIterator entityIterator; - public ShieldBar(int x, int y) { super(x, y); - this.entityIterator = Screen.currentScreen.createEntityIterator(); } public void paint(Graphics2D g) { - Player player = null; - this.entityIterator.reset(); - while(this.entityIterator.hasNext()) { - Entity e = this.entityIterator.next(); - if(e instanceof Player){ - player = ((Player) e); - } - } + Player player = GameScreen.getPlayer(); try { this.shield = player.getShieldPoints(); this.shieldwidth = ((this.width) * this.shield) / 100; diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 8aa8eb0..646ad8c 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -27,7 +27,7 @@ public class GameScreen extends Screen { private ArrayList points = new ArrayList(); - private Player player; + private static Player player; public GameScreen(Screen parent) { super(parent); @@ -36,7 +36,7 @@ public class GameScreen extends Screen { points.add(new Point(600,100)); points.add(new Point(0,500)); new StarBackground(0, 50); - this.player = new Player(200, 300); + GameScreen.player = new Player(200, 300); new InterfaceBar(0, 0); new HealthBar(10, 5); new ShieldBar(10, 27); @@ -65,10 +65,14 @@ public class GameScreen extends Screen { if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) { this.setOverlay(new GamePausedScreen(this)); } - if (!this.player.isAlive()) { + if (!GameScreen.player.isAlive()) { this.parent.setOverlay(new GameOverScreen(this.parent)); } } + public static Player getPlayer() { + return GameScreen.player; + } + }