Added Score
Added Interface fr Health, Sheild and Score Resized Game Window for the Interface Added Score for Enemy Kills
This commit is contained in:
parent
248e5f685a
commit
5982c0ced2
@ -26,7 +26,7 @@ public class Main {
|
|||||||
GraphicsSettings gs = new GraphicsSettings(); //Get settings
|
GraphicsSettings gs = new GraphicsSettings(); //Get settings
|
||||||
|
|
||||||
GameConfig.windowWidth = 800;
|
GameConfig.windowWidth = 800;
|
||||||
GameConfig.windowHeight = 600;
|
GameConfig.windowHeight = 650;
|
||||||
|
|
||||||
//Instantiate the GameFrame
|
//Instantiate the GameFrame
|
||||||
final GameFrame gameFrame = new GameFrame();
|
final GameFrame gameFrame = new GameFrame();
|
||||||
|
@ -4,9 +4,12 @@ import java.awt.Graphics2D;
|
|||||||
|
|
||||||
|
|
||||||
public class StarBackground extends Background {
|
public class StarBackground extends Background {
|
||||||
|
|
||||||
|
private int y;
|
||||||
|
|
||||||
public StarBackground(int x, int y) {
|
public StarBackground(int x, int y) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
|
this.y = y;
|
||||||
this.setImage("images/starbackground.png");
|
this.setImage("images/starbackground.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,9 +24,9 @@ public class StarBackground extends Background {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
g.drawImage(this.getImage(), (0+this.offset), 0, null);
|
g.drawImage(this.getImage(), (0+this.offset), this.y, null);
|
||||||
g.drawImage(this.getImage(), (this.getImage().getWidth()+this.offset), 0, null);
|
g.drawImage(this.getImage(), (this.getImage().getWidth()+this.offset), this.y, null);
|
||||||
g.drawImage(this.getImage(), (2*this.getImage().getWidth()+this.offset), 0, null);
|
g.drawImage(this.getImage(), (2*this.getImage().getWidth()+this.offset), this.y, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
25
src/de/teamteamteam/spacescooter/datastructure/Score.java
Normal file
25
src/de/teamteamteam/spacescooter/datastructure/Score.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package de.teamteamteam.spacescooter.datastructure;
|
||||||
|
|
||||||
|
public class Score {
|
||||||
|
|
||||||
|
private static int score = 0;
|
||||||
|
|
||||||
|
public static int getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setScore(int score) {
|
||||||
|
Score.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addScore(int score) {
|
||||||
|
if (Score.score != 99999999)
|
||||||
|
Score.score += score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeScore(int score) {
|
||||||
|
if (Score.score != 0)
|
||||||
|
Score.score -= score;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package de.teamteamteam.spacescooter.entity;
|
|||||||
|
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
import de.teamteamteam.spacescooter.datastructure.Score;
|
||||||
import de.teamteamteam.spacescooter.entity.enemy.Enemy;
|
import de.teamteamteam.spacescooter.entity.enemy.Enemy;
|
||||||
import de.teamteamteam.spacescooter.entity.explosion.Explosion;
|
import de.teamteamteam.spacescooter.entity.explosion.Explosion;
|
||||||
import de.teamteamteam.spacescooter.entity.shot.Shot;
|
import de.teamteamteam.spacescooter.entity.shot.Shot;
|
||||||
@ -33,6 +34,11 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl
|
|||||||
*/
|
*/
|
||||||
private int shieldPoints;
|
private int shieldPoints;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The LivingEntities shield points.
|
||||||
|
*/
|
||||||
|
private int ScorePoints;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
@ -106,6 +112,7 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl
|
|||||||
//Set the correct values for gui indicators
|
//Set the correct values for gui indicators
|
||||||
this.healthPoints = 0;
|
this.healthPoints = 0;
|
||||||
this.shieldPoints = 0;
|
this.shieldPoints = 0;
|
||||||
|
Score.addScore(ScorePoints);
|
||||||
if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP");
|
if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP");
|
||||||
this.die();
|
this.die();
|
||||||
}
|
}
|
||||||
@ -155,5 +162,12 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl
|
|||||||
public int getShieldPoints() {
|
public int getShieldPoints() {
|
||||||
return this.shieldPoints;
|
return this.shieldPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current score points.
|
||||||
|
*/
|
||||||
|
public void setScore(int s) {
|
||||||
|
this.ScorePoints = s;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
|||||||
this.setShootSpeed(10);
|
this.setShootSpeed(10);
|
||||||
this.setCollisionDamage(10);
|
this.setCollisionDamage(10);
|
||||||
this.setHealthPoints(100);
|
this.setHealthPoints(100);
|
||||||
|
this.setShieldPoints(100);
|
||||||
this.registerOnKeyboard(Keyboard.getInstance());
|
this.registerOnKeyboard(Keyboard.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ public class EnemyFour extends Enemy{
|
|||||||
this.setShootDamage(5);
|
this.setShootDamage(5);
|
||||||
this.setCollisionDamage(5);
|
this.setCollisionDamage(5);
|
||||||
this.setHealthPoints(5);
|
this.setHealthPoints(5);
|
||||||
|
this.setScore(40);
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
@ -13,6 +13,7 @@ public class EnemyOne extends Enemy {
|
|||||||
this.setCollisionDamage(5);
|
this.setCollisionDamage(5);
|
||||||
this.setHealthPoints(5);
|
this.setHealthPoints(5);
|
||||||
this.setCollisionDamage(this.getHealthPoints());
|
this.setCollisionDamage(this.getHealthPoints());
|
||||||
|
this.setScore(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,6 +27,7 @@ public class EnemyThree extends Enemy{
|
|||||||
this.setShootDamage(5);
|
this.setShootDamage(5);
|
||||||
this.setHealthPoints(15);
|
this.setHealthPoints(15);
|
||||||
this.setCollisionDamage(10);
|
this.setCollisionDamage(10);
|
||||||
|
this.setScore(30);
|
||||||
this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight()));
|
this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight()));
|
||||||
this.newY = this.getY();
|
this.newY = this.getY();
|
||||||
this.entityIterator = Screen.currentScreen.createEntityIterator();
|
this.entityIterator = Screen.currentScreen.createEntityIterator();
|
||||||
|
@ -17,6 +17,7 @@ public class EnemyTwo extends Enemy{
|
|||||||
this.setShootDamage(5);
|
this.setShootDamage(5);
|
||||||
this.setCollisionDamage(5);
|
this.setCollisionDamage(5);
|
||||||
this.setHealthPoints(5);
|
this.setHealthPoints(5);
|
||||||
|
this.setScore(20);
|
||||||
this.setCollisionDamage(this.getHealthPoints());
|
this.setCollisionDamage(this.getHealthPoints());
|
||||||
this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight()));
|
this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight()));
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.teamteamteam.spacescooter.gui;
|
package de.teamteamteam.spacescooter.gui;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator;
|
import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator;
|
||||||
@ -10,8 +11,9 @@ import de.teamteamteam.spacescooter.screen.Screen;
|
|||||||
|
|
||||||
public class HealthBar extends Entity {
|
public class HealthBar extends Entity {
|
||||||
|
|
||||||
private int width = 100;
|
private int width = 150;
|
||||||
private int height = 24;
|
private int height = 14;
|
||||||
|
private int health = 0;
|
||||||
|
|
||||||
private ConcurrentIterator<Entity> entityIterator;
|
private ConcurrentIterator<Entity> entityIterator;
|
||||||
|
|
||||||
@ -29,10 +31,20 @@ public class HealthBar extends Entity {
|
|||||||
player = ((Player) e);
|
player = ((Player) e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.setColor(Color.GREEN);
|
this.health = ((this.width) * player.getHealthPoints());
|
||||||
g.fillRect(this.getX(), this.getY(), (this.width / 100) * player.getHealthPoints(), this.height);
|
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(Color.WHITE);
|
||||||
g.drawRect(this.getX(), this.getY(), this.width, this.height);
|
g.setFont(new Font("Monospace", 0, 16));
|
||||||
|
g.drawString("Health:", this.getX(), this.getY()+12);
|
||||||
|
if (player.getHealthPoints() <= 15) {
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
} else if (player.getHealthPoints() <= 50) {
|
||||||
|
g.setColor(Color.YELLOW);
|
||||||
|
} else {
|
||||||
|
g.setColor(Color.GREEN);
|
||||||
|
}
|
||||||
|
g.fillRect(this.getX()+70, this.getY(), this.health / 100, this.height);
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.drawRect(this.getX()+70, this.getY(), this.width, this.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {}
|
public void update() {}
|
||||||
|
24
src/de/teamteamteam/spacescooter/gui/InterfaceBar.java
Normal file
24
src/de/teamteamteam/spacescooter/gui/InterfaceBar.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package de.teamteamteam.spacescooter.gui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
|
import de.teamteamteam.spacescooter.entity.Entity;;
|
||||||
|
|
||||||
|
public class InterfaceBar extends Entity {
|
||||||
|
|
||||||
|
private int width = 800;
|
||||||
|
private int height = 50;
|
||||||
|
|
||||||
|
public InterfaceBar(int x, int y) {
|
||||||
|
super(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(Graphics2D g) {
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.fillRect(this.getX(), this.getY(), this.width, this.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {}
|
||||||
|
|
||||||
|
}
|
25
src/de/teamteamteam/spacescooter/gui/ScoreBar.java
Normal file
25
src/de/teamteamteam/spacescooter/gui/ScoreBar.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package de.teamteamteam.spacescooter.gui;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
|
||||||
|
import de.teamteamteam.spacescooter.entity.Entity;
|
||||||
|
import de.teamteamteam.spacescooter.datastructure.Score;
|
||||||
|
|
||||||
|
public class ScoreBar extends Entity {
|
||||||
|
|
||||||
|
public ScoreBar(int x, int y) {
|
||||||
|
super(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paint(Graphics2D g) {
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.setFont(new Font("Monospace", 0, 24));
|
||||||
|
g.drawString("Score:", this.getX(), this.getY());
|
||||||
|
g.drawString(String.format("%08d", Integer.parseInt("" + Score.getScore())), this.getX()+77, this.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {}
|
||||||
|
|
||||||
|
}
|
46
src/de/teamteamteam/spacescooter/gui/ShieldBar.java
Normal file
46
src/de/teamteamteam/spacescooter/gui/ShieldBar.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package de.teamteamteam.spacescooter.gui;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class ShieldBar extends Entity {
|
||||||
|
|
||||||
|
private int width = 150;
|
||||||
|
private int height = 14;
|
||||||
|
private int shield = 0;
|
||||||
|
|
||||||
|
private ConcurrentIterator<Entity> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.shield = ((this.width) * player.getShieldPoints());
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.setFont(new Font("Monospace", 0, 16));
|
||||||
|
g.drawString("Shield:", this.getX(), this.getY()+12);
|
||||||
|
g.setColor(Color.BLUE);
|
||||||
|
g.fillRect(this.getX()+70, this.getY(), this.shield / 100, this.height);
|
||||||
|
g.setColor(Color.WHITE);
|
||||||
|
g.drawRect(this.getX()+70, this.getY(), this.width, this.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {}
|
||||||
|
|
||||||
|
}
|
@ -12,6 +12,9 @@ import de.teamteamteam.spacescooter.entity.enemy.EnemyFour;
|
|||||||
import de.teamteamteam.spacescooter.entity.enemy.EnemyThree;
|
import de.teamteamteam.spacescooter.entity.enemy.EnemyThree;
|
||||||
import de.teamteamteam.spacescooter.entity.item.ItemChance;
|
import de.teamteamteam.spacescooter.entity.item.ItemChance;
|
||||||
import de.teamteamteam.spacescooter.gui.HealthBar;
|
import de.teamteamteam.spacescooter.gui.HealthBar;
|
||||||
|
import de.teamteamteam.spacescooter.gui.InterfaceBar;
|
||||||
|
import de.teamteamteam.spacescooter.gui.ScoreBar;
|
||||||
|
import de.teamteamteam.spacescooter.gui.ShieldBar;
|
||||||
import de.teamteamteam.spacescooter.utility.CollisionHandler;
|
import de.teamteamteam.spacescooter.utility.CollisionHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,9 +35,12 @@ public class GameScreen extends Screen {
|
|||||||
points.add(new Point(300,300));
|
points.add(new Point(300,300));
|
||||||
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, 0);
|
new StarBackground(0, 50);
|
||||||
this.player = new Player(200, 300);
|
this.player = new Player(200, 300);
|
||||||
new HealthBar(10, 10);
|
new InterfaceBar(0, 0);
|
||||||
|
new HealthBar(10, 5);
|
||||||
|
new ShieldBar(10, 27);
|
||||||
|
new ScoreBar(575, 33);
|
||||||
new EnemyFour(800, 400, points);
|
new EnemyFour(800, 400, points);
|
||||||
new EnemyThree(650, 300);
|
new EnemyThree(650, 300);
|
||||||
new EnemyThree(450, 100);
|
new EnemyThree(450, 100);
|
||||||
|
Loading…
Reference in New Issue
Block a user