Added getPlayer()
This commit is contained in:
parent
0a460e3ce2
commit
5d404e37bd
|
@ -4,10 +4,9 @@ import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator;
|
|
||||||
import de.teamteamteam.spacescooter.entity.Entity;
|
import de.teamteamteam.spacescooter.entity.Entity;
|
||||||
import de.teamteamteam.spacescooter.entity.Player;
|
import de.teamteamteam.spacescooter.entity.Player;
|
||||||
import de.teamteamteam.spacescooter.screen.Screen;
|
import de.teamteamteam.spacescooter.screen.GameScreen;
|
||||||
|
|
||||||
public class HealthBar extends Entity {
|
public class HealthBar extends Entity {
|
||||||
|
|
||||||
|
@ -16,22 +15,12 @@ public class HealthBar extends Entity {
|
||||||
private int health = 0;
|
private int health = 0;
|
||||||
private int healthwidth = 0;
|
private int healthwidth = 0;
|
||||||
|
|
||||||
private ConcurrentIterator<Entity> entityIterator;
|
|
||||||
|
|
||||||
public HealthBar(int x, int y) {
|
public HealthBar(int x, int y) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
this.entityIterator = Screen.currentScreen.createEntityIterator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
Player player = null;
|
Player player = GameScreen.getPlayer();
|
||||||
this.entityIterator.reset();
|
|
||||||
while(this.entityIterator.hasNext()) {
|
|
||||||
Entity e = this.entityIterator.next();
|
|
||||||
if(e instanceof Player){
|
|
||||||
player = ((Player) e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
this.health = player.getHealthPoints();
|
this.health = player.getHealthPoints();
|
||||||
this.healthwidth = ((this.width) * this.health) / 100;
|
this.healthwidth = ((this.width) * this.health) / 100;
|
||||||
|
|
|
@ -4,10 +4,9 @@ import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator;
|
|
||||||
import de.teamteamteam.spacescooter.entity.Entity;
|
import de.teamteamteam.spacescooter.entity.Entity;
|
||||||
import de.teamteamteam.spacescooter.entity.Player;
|
import de.teamteamteam.spacescooter.entity.Player;
|
||||||
import de.teamteamteam.spacescooter.screen.Screen;
|
import de.teamteamteam.spacescooter.screen.GameScreen;
|
||||||
|
|
||||||
public class ShieldBar extends Entity {
|
public class ShieldBar extends Entity {
|
||||||
|
|
||||||
|
@ -16,22 +15,12 @@ public class ShieldBar extends Entity {
|
||||||
private int shield = 0;
|
private int shield = 0;
|
||||||
private int shieldwidth = 0;
|
private int shieldwidth = 0;
|
||||||
|
|
||||||
private ConcurrentIterator<Entity> entityIterator;
|
|
||||||
|
|
||||||
public ShieldBar(int x, int y) {
|
public ShieldBar(int x, int y) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
this.entityIterator = Screen.currentScreen.createEntityIterator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
Player player = null;
|
Player player = GameScreen.getPlayer();
|
||||||
this.entityIterator.reset();
|
|
||||||
while(this.entityIterator.hasNext()) {
|
|
||||||
Entity e = this.entityIterator.next();
|
|
||||||
if(e instanceof Player){
|
|
||||||
player = ((Player) e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
this.shield = player.getShieldPoints();
|
this.shield = player.getShieldPoints();
|
||||||
this.shieldwidth = ((this.width) * this.shield) / 100;
|
this.shieldwidth = ((this.width) * this.shield) / 100;
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class GameScreen extends Screen {
|
||||||
|
|
||||||
private ArrayList<Point> points = new ArrayList<Point>();
|
private ArrayList<Point> points = new ArrayList<Point>();
|
||||||
|
|
||||||
private Player player;
|
private static Player player;
|
||||||
|
|
||||||
public GameScreen(Screen parent) {
|
public GameScreen(Screen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
@ -36,7 +36,7 @@ public class GameScreen extends Screen {
|
||||||
points.add(new Point(600,100));
|
points.add(new Point(600,100));
|
||||||
points.add(new Point(0,500));
|
points.add(new Point(0,500));
|
||||||
new StarBackground(0, 50);
|
new StarBackground(0, 50);
|
||||||
this.player = new Player(200, 300);
|
GameScreen.player = new Player(200, 300);
|
||||||
new InterfaceBar(0, 0);
|
new InterfaceBar(0, 0);
|
||||||
new HealthBar(10, 5);
|
new HealthBar(10, 5);
|
||||||
new ShieldBar(10, 27);
|
new ShieldBar(10, 27);
|
||||||
|
@ -65,10 +65,14 @@ public class GameScreen extends Screen {
|
||||||
if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
|
if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
|
||||||
this.setOverlay(new GamePausedScreen(this));
|
this.setOverlay(new GamePausedScreen(this));
|
||||||
}
|
}
|
||||||
if (!this.player.isAlive()) {
|
if (!GameScreen.player.isAlive()) {
|
||||||
this.parent.setOverlay(new GameOverScreen(this.parent));
|
this.parent.setOverlay(new GameOverScreen(this.parent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Player getPlayer() {
|
||||||
|
return GameScreen.player;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue