Highscore fertiggestellt: Wenn man stirbt und genug Punkte hat kann man ein Namen eingeben.
Im Highscore werden die besten 20 Spiele gespeichert. In den Menüs wird jetzt ein ImageEntity, mit dem Bild des Players, anstatt der echte Player verwendet.
This commit is contained in:
parent
9bba32307e
commit
41a0775e65
Binary file not shown.
After Width: | Height: | Size: 307 B |
|
@ -26,14 +26,9 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
||||||
private Keyboard keyboard;
|
private Keyboard keyboard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rocket Ammunition
|
* Ammunition of the secondary weapon.
|
||||||
*/
|
*/
|
||||||
private int rocketAmount;
|
private int secondaryWeaponAmount;
|
||||||
|
|
||||||
/**
|
|
||||||
* Beam Ammunition
|
|
||||||
*/
|
|
||||||
private int beamAmount;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cooldown countdown value to use in case
|
* Cooldown countdown value to use in case
|
||||||
|
@ -54,8 +49,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
||||||
*/
|
*/
|
||||||
public Player(int x, int y) {
|
public Player(int x, int y) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
this.rocketAmount = 1;
|
this.secondaryWeaponAmount = 0;
|
||||||
this.beamAmount = 1;
|
|
||||||
this.collisionCooldown = 150;
|
this.collisionCooldown = 150;
|
||||||
this.currentCollisionCooldown = 0;
|
this.currentCollisionCooldown = 0;
|
||||||
this.setImage("images/ship.png");
|
this.setImage("images/ship.png");
|
||||||
|
@ -113,10 +107,12 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
||||||
this.shoot();
|
this.shoot();
|
||||||
}
|
}
|
||||||
if(Keyboard.isKeyDown(KeyEvent.VK_Y)) {
|
if(Keyboard.isKeyDown(KeyEvent.VK_Y)) {
|
||||||
if(PlayerSession.getSecondsecondaryWeapon() == 1 && this.rocketAmount > 0) {
|
if(this.secondaryWeaponAmount > 0){
|
||||||
this.shootRocket();
|
if(PlayerSession.getSecondsecondaryWeapon() == 1) {
|
||||||
}else if(PlayerSession.getSecondsecondaryWeapon() == 2 && this.beamAmount > 0) {
|
this.shootRocket();
|
||||||
this.shootBeam();
|
}else if(PlayerSession.getSecondsecondaryWeapon() == 2) {
|
||||||
|
this.shootBeam();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,46 +219,34 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
||||||
@Override
|
@Override
|
||||||
public void createRocket() {
|
public void createRocket() {
|
||||||
super.createRocket();
|
super.createRocket();
|
||||||
this.removeRocketAmount();
|
this.removeSecondaryWeaponAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createBeam() {
|
public void createBeam() {
|
||||||
super.createBeam();
|
super.createBeam();
|
||||||
this.removeBeamAmount();
|
this.removeSecondaryWeaponAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current rocket amount.
|
* Get the current secondary weapon amount.
|
||||||
*/
|
*/
|
||||||
public int getRocketAmount(){
|
public int getSecondaryWeaponAmount(){
|
||||||
return rocketAmount;
|
return secondaryWeaponAmount;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
public int getBeamAmount(){
|
* Add one secondary weapon amount.
|
||||||
return beamAmount;
|
*/
|
||||||
|
public void addSecondaryWeaponAmount(){
|
||||||
|
secondaryWeaponAmount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add one rocket.
|
* Remove one secondary weapon amount.
|
||||||
*/
|
*/
|
||||||
public void addRocketAmount(){
|
public void removeSecondaryWeaponAmount(){
|
||||||
rocketAmount++;
|
secondaryWeaponAmount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBeamAmount(){
|
|
||||||
beamAmount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove one rocket.
|
|
||||||
*/
|
|
||||||
public void removeRocketAmount(){
|
|
||||||
rocketAmount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeBeamAmount(){
|
|
||||||
beamAmount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class ItemBeam extends Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void itemCollected(Player player) {
|
public void itemCollected(Player player) {
|
||||||
player.addBeamAmount();;
|
player.addSecondaryWeaponAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class ItemRocket extends Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void itemCollected(Player player) {
|
public void itemCollected(Player player) {
|
||||||
player.addRocketAmount();
|
player.addSecondaryWeaponAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,51 @@
|
||||||
package de.teamteamteam.spacescooter.gui;
|
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.entity.Entity;
|
||||||
|
|
||||||
public class ImageEntity extends Entity{
|
public class ImageEntity extends Entity{
|
||||||
|
|
||||||
|
private String text = null;
|
||||||
|
private int size;
|
||||||
|
private Color color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This only show an image.
|
* This only show an image or a String if filename is null and drawString was called.
|
||||||
*/
|
*/
|
||||||
public ImageEntity(int x, int y, String filename) {
|
public ImageEntity(int x, int y, String filename) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
setImage(filename);
|
if(filename != null) setImage(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the string, text size and color to paint a text.
|
||||||
|
*/
|
||||||
|
public void drawString(String text, int size, Color color){
|
||||||
|
this.text = text;
|
||||||
|
this.size = size;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText(){
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paint the image or paint a String if filename is null.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics2D g) {
|
||||||
|
if(this.text == null) super.paint(g);
|
||||||
|
else{
|
||||||
|
g.setFont(new Font("Monospace", 0, size));
|
||||||
|
g.setColor(color);
|
||||||
|
g.drawString(text, getX(), getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update(){}
|
public void update(){}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,9 @@ import de.teamteamteam.spacescooter.screen.GameScreen;
|
||||||
|
|
||||||
public class SecondaryWeaponAmount extends Entity{
|
public class SecondaryWeaponAmount extends Entity{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the current secondary weapon amount in the interface bar.
|
||||||
|
*/
|
||||||
public SecondaryWeaponAmount(int x, int y) {
|
public SecondaryWeaponAmount(int x, int y) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
if(PlayerSession.getSecondsecondaryWeapon() == 1){
|
if(PlayerSession.getSecondsecondaryWeapon() == 1){
|
||||||
|
@ -23,11 +26,8 @@ public class SecondaryWeaponAmount extends Entity{
|
||||||
public void paint(Graphics2D g) {
|
public void paint(Graphics2D g) {
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(Color.WHITE);
|
||||||
g.setFont(new Font("Monospace", 0, 16));
|
g.setFont(new Font("Monospace", 0, 16));
|
||||||
if(PlayerSession.getSecondsecondaryWeapon() == 1){
|
g.drawString("x " + GameScreen.getPlayer().getSecondaryWeaponAmount(), this.getX() + 30, this.getY() + 12);
|
||||||
g.drawString("x " + GameScreen.getPlayer().getRocketAmount(), this.getX() + 30, this.getY() + 12);
|
|
||||||
}else{
|
|
||||||
g.drawString("x " + GameScreen.getPlayer().getBeamAmount(), this.getX() + 30, this.getY() + 12);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,15 +3,15 @@ package de.teamteamteam.spacescooter.screen;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||||
import de.teamteamteam.spacescooter.brain.PlayerSession;
|
import de.teamteamteam.spacescooter.brain.PlayerSession;
|
||||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||||
import de.teamteamteam.spacescooter.entity.Player;
|
|
||||||
import de.teamteamteam.spacescooter.gui.Button;
|
import de.teamteamteam.spacescooter.gui.Button;
|
||||||
import de.teamteamteam.spacescooter.utility.Loader;
|
import de.teamteamteam.spacescooter.gui.ImageEntity;
|
||||||
|
import de.teamteamteam.spacescooter.utility.Highscore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the GameOverScreen, which is displayed once the player
|
* This is the GameOverScreen, which is displayed once the player
|
||||||
|
@ -19,43 +19,89 @@ import de.teamteamteam.spacescooter.utility.Loader;
|
||||||
* It allows to start a new game or going to the MainMenuScreen.
|
* It allows to start a new game or going to the MainMenuScreen.
|
||||||
*/
|
*/
|
||||||
public class GameOverScreen extends Screen {
|
public class GameOverScreen extends Screen {
|
||||||
|
|
||||||
private BufferedImage img;
|
private ImageEntity cursor;
|
||||||
private Player player;
|
private float cursorMoveSpeed = 0;
|
||||||
private float playerMoveSpeed = 0;
|
|
||||||
private int colorValue = 0;
|
private int colorValue = 0;
|
||||||
private boolean colorValueIncrease = true;
|
private boolean colorValueIncrease = true;
|
||||||
private int menuPoint = 0;
|
private int menuPoint = 0;
|
||||||
private int animationStatus = 0; //0 = Noch nicht gestartet, 1 = Animation läuft, 2 = Animation beendet
|
private int animationStatus = 0; //0 = Noch nicht gestartet, 1 = Animation läuft, 2 = Animation beendet
|
||||||
|
|
||||||
|
private boolean keyPressed = false;
|
||||||
|
private boolean saveScoreMenu = true;
|
||||||
|
private boolean uppercase = true;
|
||||||
|
private Point cursorPosition = new Point(0, 0);
|
||||||
|
private int score;
|
||||||
|
private int enteredLetter = 0;
|
||||||
|
private ImageEntity[] letters = new ImageEntity[10];
|
||||||
|
private ImageEntity[] lettersbox = new ImageEntity[10];
|
||||||
|
|
||||||
public GameOverScreen(Screen parent) {
|
public GameOverScreen(Screen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.img = Loader.getBufferedImageByFilename("images/pausebackground.png");
|
new ImageEntity(0, 0, "images/shopbackground.png");
|
||||||
new Button(GameConfig.windowWidth/2-125, 300);
|
this.score = PlayerSession.getScore();
|
||||||
new Button(GameConfig.windowWidth/2-125, 400);
|
if(Highscore.getPlacement(score) != -1){ // Player has a new high score
|
||||||
player = new Player(GameConfig.windowWidth/2-170, 309);
|
saveScoreMenu = true;
|
||||||
player.setCanMove(false);
|
this.cursor = new ImageEntity(173, 293, "images/ship.png");
|
||||||
player.setCanShoot(false);
|
for(int i = 0; i<10; i++){
|
||||||
|
lettersbox[i] = new ImageEntity(150 + (i*50), 200, "images/letterbox.png");
|
||||||
//Reset the player session for the next player.
|
}
|
||||||
//TODO: Make sure highscore "enter name" stuff happened before!
|
}else{
|
||||||
|
saveScoreMenu = false;
|
||||||
|
new Button(GameConfig.windowWidth/2-125, 300);
|
||||||
|
new Button(GameConfig.windowWidth/2-125, 400);
|
||||||
|
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, 309, "images/ship.png");
|
||||||
|
}
|
||||||
PlayerSession.reset();
|
PlayerSession.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paint(Graphics2D g) {
|
protected void paint(Graphics2D g) {
|
||||||
g.drawImage(this.img, 0, 0, null);
|
|
||||||
this.entityPaintIterator.reset();
|
this.entityPaintIterator.reset();
|
||||||
while (this.entityPaintIterator.hasNext()) {
|
while (this.entityPaintIterator.hasNext()) {
|
||||||
this.entityPaintIterator.next().paint(g);
|
this.entityPaintIterator.next().paint(g);
|
||||||
}
|
}
|
||||||
g.setFont(new Font("Monospace", 0, 100));
|
g.setFont(new Font("Monospace", 0, 100));
|
||||||
g.setColor(new Color(75 + colorValue, 175 + colorValue, 175 + colorValue));
|
g.setColor(new Color(75 + colorValue, 175 + colorValue, 175 + colorValue));
|
||||||
g.drawString("Game Over", GameConfig.windowWidth/2-290, 200);
|
g.drawString("Game Over", GameConfig.windowWidth/2-290, 120);
|
||||||
g.setFont(new Font("Monospace", 0, 20));
|
// Paint the screen to enter a name for the high score
|
||||||
g.setColor(new Color(0, 0, 0));
|
if(saveScoreMenu){
|
||||||
g.drawString("Wiederholen", GameConfig.windowWidth/2-60, 332);
|
g.setFont(new Font("Monospace", 0, 30));
|
||||||
g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-60, 432);
|
g.setColor(Color.WHITE);
|
||||||
|
if(uppercase){
|
||||||
|
g.drawString("A C D E G", 210, 320);
|
||||||
|
g.drawString("B F", 267, 320);
|
||||||
|
g.drawString("H I J K L M N", 210, 380);
|
||||||
|
g.drawString("O Q S T U", 210, 440);
|
||||||
|
g.drawString("P R", 267, 440);
|
||||||
|
g.drawString("V Z", 210, 500);
|
||||||
|
g.drawString("W X Y", 263, 500);
|
||||||
|
g.setFont(new Font("Monospace", 0, 15));
|
||||||
|
g.drawString("abc", 497, 493);
|
||||||
|
}else{
|
||||||
|
g.drawString("a b c d e", 210, 320);
|
||||||
|
g.drawString("f g", 505, 320);
|
||||||
|
g.drawString("h k l m n", 210, 380);
|
||||||
|
g.drawString("i j", 273, 380);
|
||||||
|
g.drawString("o p q r s t u", 210, 440);
|
||||||
|
g.drawString("v", 210, 500);
|
||||||
|
g.drawString("w x y z", 264, 500);
|
||||||
|
g.setFont(new Font("Monospace", 0, 15));
|
||||||
|
g.drawString("ABC", 496, 493);
|
||||||
|
}
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
g.drawString("del", 555, 493);
|
||||||
|
g.setFont(new Font("Monospace", 0, 20));
|
||||||
|
g.setColor(Color.GREEN);
|
||||||
|
g.drawString("Fertig", GameConfig.gameScreenWidth/2-40, 555);
|
||||||
|
g.drawString("Du bist auf dem " + (Highscore.getPlacement(score)+1) + ". Platz!", GameConfig.gameScreenWidth/2-130, 170);
|
||||||
|
// Paint the normal gameover screen
|
||||||
|
}else{
|
||||||
|
g.setFont(new Font("Monospace", 0, 20));
|
||||||
|
g.setColor(Color.BLACK);
|
||||||
|
g.drawString("Wiederholen", GameConfig.windowWidth/2-60, 332);
|
||||||
|
g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-60, 432);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +110,6 @@ public class GameOverScreen extends Screen {
|
||||||
while (this.entityUpdateIterator.hasNext()) {
|
while (this.entityUpdateIterator.hasNext()) {
|
||||||
this.entityUpdateIterator.next().update();
|
this.entityUpdateIterator.next().update();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.colorValueIncrease) {
|
if(this.colorValueIncrease) {
|
||||||
this.colorValue += 2;
|
this.colorValue += 2;
|
||||||
if(this.colorValue > 70) this.colorValueIncrease = false;
|
if(this.colorValue > 70) this.colorValueIncrease = false;
|
||||||
|
@ -72,35 +117,151 @@ public class GameOverScreen extends Screen {
|
||||||
this.colorValue -= 2;
|
this.colorValue -= 2;
|
||||||
if(this.colorValue < -70) this.colorValueIncrease = true;
|
if(this.colorValue < -70) this.colorValueIncrease = true;
|
||||||
}
|
}
|
||||||
|
//Control while enter the name for the high score.
|
||||||
|
if(this.saveScoreMenu){
|
||||||
|
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && !this.keyPressed){
|
||||||
|
this.keyPressed = true;
|
||||||
|
if(this.cursorPosition.getY() > 0){
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX(), this.cursorPosition.getY() - 1);
|
||||||
|
this.cursor.setPosition(173+(int)(this.cursorPosition.getX()*58), this.cursor.getY() - 60);
|
||||||
|
}else if(cursorPosition.getY() == 4){
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX(), this.cursorPosition.getY() - 1);
|
||||||
|
this.cursor.setPosition(173+(int)(this.cursorPosition.getX()*58), this.cursor.getY() - 60);
|
||||||
|
}else{
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX(), 4);
|
||||||
|
this.cursor.setPosition(325, 533);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !this.keyPressed){
|
||||||
|
this.keyPressed = true;
|
||||||
|
if(this.cursorPosition.getY() < 3){
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX(), this.cursorPosition.getY() + 1);
|
||||||
|
this.cursor.setPosition(173+(int)(this.cursorPosition.getX()*58), this.cursor.getY() + 60);
|
||||||
|
}else if(cursorPosition.getY() == 3){
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX(), this.cursorPosition.getY() + 1);
|
||||||
|
this.cursor.setPosition(325, this.cursor.getY() + 60);
|
||||||
|
}else{
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX(), 0);
|
||||||
|
this.cursor.setPosition(173+(int)(this.cursorPosition.getX()*58), 293);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Keyboard.isKeyDown(KeyEvent.VK_LEFT) && !this.keyPressed){
|
||||||
|
this.keyPressed = true;
|
||||||
|
if(cursorPosition.getY() !=4){
|
||||||
|
if(this.cursorPosition.getX() > 0){
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX() - 1, this.cursorPosition.getY());
|
||||||
|
this.cursor.setPosition(this.cursor.getX() - 58, this.cursor.getY());
|
||||||
|
}else{
|
||||||
|
this.cursorPosition.setLocation(6, this.cursorPosition.getY());
|
||||||
|
this.cursor.setPosition(521, this.cursor.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(Keyboard.isKeyDown(KeyEvent.VK_RIGHT) && !this.keyPressed){
|
||||||
|
this.keyPressed = true;
|
||||||
|
if(cursorPosition.getY() !=4){
|
||||||
|
if(this.cursorPosition.getX() < 6){
|
||||||
|
this.cursorPosition.setLocation(this.cursorPosition.getX() + 1, this.cursorPosition.getY());
|
||||||
|
this.cursor.setPosition(this.cursor.getX() + 58, this.cursor.getY());
|
||||||
|
}else{
|
||||||
|
this.cursorPosition.setLocation(0, this.cursorPosition.getY());
|
||||||
|
this.cursor.setPosition(173, this.cursor.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if((Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE)) && !this.keyPressed){
|
||||||
|
this.keyPressed = true;
|
||||||
|
if(this.cursorPosition.equals(new Point(5, 3))){
|
||||||
|
if(uppercase) uppercase = false;
|
||||||
|
else uppercase = true;
|
||||||
|
}else if(this.cursorPosition.equals(new Point(6, 3))){
|
||||||
|
if(enteredLetter > 0){
|
||||||
|
enteredLetter--;
|
||||||
|
letters[enteredLetter].remove();
|
||||||
|
}
|
||||||
|
}else if(cursorPosition.getY() == 4){
|
||||||
|
String eingabeName = "";
|
||||||
|
for(int i = 0; i<10; i++){
|
||||||
|
if(letters[i] != null){
|
||||||
|
eingabeName += letters[i].getText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Highscore.newScore(this.score, eingabeName);
|
||||||
|
animationStatus = 1;
|
||||||
|
}else{
|
||||||
|
if(this.enteredLetter < 10) this.searchForChar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0){
|
//Control in the game normal over menu (if the player does not came in the high score).
|
||||||
this.menuPoint = 1;
|
}else{
|
||||||
player.setPosition(player.getX(), 409);
|
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0){
|
||||||
}
|
this.menuPoint = 1;
|
||||||
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0){
|
this.cursor.setPosition(this.cursor.getX(), 409);
|
||||||
this.menuPoint = 0;
|
}
|
||||||
player.setPosition(player.getX(), 309);
|
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0){
|
||||||
}
|
this.menuPoint = 0;
|
||||||
|
this.cursor.setPosition(this.cursor.getX(), 309);
|
||||||
// make a selection
|
}
|
||||||
if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
|
|
||||||
this.animationStatus = 1;
|
// make a selection
|
||||||
|
if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE) && !this.keyPressed) {
|
||||||
|
this.animationStatus = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(this.animationStatus == 1) {
|
if(this.animationStatus == 1) {
|
||||||
if(player.getX() <= GameConfig.windowWidth) {
|
if(this.cursor.getX() <= GameConfig.windowWidth) {
|
||||||
player.setPosition(player.getX() + (int) playerMoveSpeed, player.getY());
|
this.cursor.setPosition(this.cursor.getX() + (int) this.cursorMoveSpeed, this.cursor.getY());
|
||||||
playerMoveSpeed += 0.1;
|
this.cursorMoveSpeed += 0.1;
|
||||||
} else this.animationStatus = 2;
|
} else this.animationStatus = 2;
|
||||||
} else if(this.animationStatus == 2) {
|
} else if(this.animationStatus == 2) {
|
||||||
switch (this.menuPoint) {
|
if(saveScoreMenu){
|
||||||
case 0:
|
this.cursor.remove();
|
||||||
this.parent.setOverlay(new GameScreen(this.parent, "levels/test.level"));
|
for(int i = 0; i<10; i++){
|
||||||
break;
|
if(lettersbox[i] != null) lettersbox[i].remove();
|
||||||
case 1:
|
if(letters[i] != null)letters[i].remove();
|
||||||
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
}
|
||||||
break;
|
this.saveScoreMenu = false;
|
||||||
|
new Button(GameConfig.windowWidth/2-125, 300);
|
||||||
|
new Button(GameConfig.windowWidth/2-125, 400);
|
||||||
|
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, 309, "images/ship.png");
|
||||||
|
this.animationStatus = 0;
|
||||||
|
this.cursorMoveSpeed = 0;
|
||||||
|
}else{
|
||||||
|
switch (this.menuPoint) {
|
||||||
|
case 0:
|
||||||
|
this.parent.setOverlay(new GameScreen(this.parent, "levels/test.level"));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!Keyboard.isKeyDown(KeyEvent.VK_ENTER) && !Keyboard.isKeyDown(KeyEvent.VK_SPACE) && !Keyboard.isKeyDown(KeyEvent.VK_UP) && !Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !Keyboard.isKeyDown(KeyEvent.VK_LEFT) && !Keyboard.isKeyDown(KeyEvent.VK_RIGHT)){
|
||||||
|
this.keyPressed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void searchForChar(){
|
||||||
|
char eingabe = (char) ('A' + this.cursorPosition.getX()+this.cursorPosition.getY()*7);
|
||||||
|
if(!this.uppercase){
|
||||||
|
eingabe += 32;
|
||||||
|
}
|
||||||
|
if(eingabe == 'W'){
|
||||||
|
letters[enteredLetter] = new ImageEntity(155+(50*this.enteredLetter), 230, null);
|
||||||
|
letters[enteredLetter].drawString("" + eingabe, 30, Color.WHITE);
|
||||||
|
}else if(eingabe == 'I' || eingabe =='J' || eingabe =='i' || eingabe =='j' || eingabe =='t' || eingabe =='l' || eingabe =='f'){
|
||||||
|
letters[enteredLetter] = new ImageEntity(165+(50*this.enteredLetter), 230, null);
|
||||||
|
letters[enteredLetter].drawString("" + eingabe, 30, Color.WHITE);
|
||||||
|
}else if(eingabe == 'w'){
|
||||||
|
letters[enteredLetter] = new ImageEntity(157+(50*this.enteredLetter), 230, null);
|
||||||
|
letters[enteredLetter].drawString("" + eingabe, 30, Color.WHITE);
|
||||||
|
}else{
|
||||||
|
letters[enteredLetter] = new ImageEntity(161+(50*this.enteredLetter), 230, null);
|
||||||
|
letters[enteredLetter].drawString("" + eingabe, 30, Color.WHITE);
|
||||||
|
}
|
||||||
|
enteredLetter++;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,10 @@ import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||||
import de.teamteamteam.spacescooter.entity.Player;
|
|
||||||
import de.teamteamteam.spacescooter.gui.Button;
|
import de.teamteamteam.spacescooter.gui.Button;
|
||||||
import de.teamteamteam.spacescooter.utility.Loader;
|
import de.teamteamteam.spacescooter.gui.ImageEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This GamePausedScreen shows up when the user pressed VK_ESCAPE ingame.
|
* This GamePausedScreen shows up when the user pressed VK_ESCAPE ingame.
|
||||||
|
@ -19,9 +16,8 @@ import de.teamteamteam.spacescooter.utility.Loader;
|
||||||
*/
|
*/
|
||||||
public class GamePausedScreen extends Screen {
|
public class GamePausedScreen extends Screen {
|
||||||
|
|
||||||
private BufferedImage img;
|
private ImageEntity cursor;
|
||||||
private Player player;
|
private float cursorMoveSpeed = 0;
|
||||||
private float playerMoveSpeed = 0;
|
|
||||||
private int colorValue = 0;
|
private int colorValue = 0;
|
||||||
private boolean colorValueIncrease = true;
|
private boolean colorValueIncrease = true;
|
||||||
private int menuPoint = 0;
|
private int menuPoint = 0;
|
||||||
|
@ -29,17 +25,14 @@ public class GamePausedScreen extends Screen {
|
||||||
|
|
||||||
public GamePausedScreen(Screen parent) {
|
public GamePausedScreen(Screen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.img = Loader.getBufferedImageByFilename("images/pausebackground.png");
|
new ImageEntity(0, 0, "images/pausebackground.png");
|
||||||
new Button(GameConfig.windowWidth/2-125, 300);
|
new Button(GameConfig.windowWidth/2-125, 300);
|
||||||
new Button(GameConfig.windowWidth/2-125, 400);
|
new Button(GameConfig.windowWidth/2-125, 400);
|
||||||
player = new Player(GameConfig.windowWidth/2-170, 309);
|
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, 309, "images/ship.png");
|
||||||
player.setCanMove(false);
|
|
||||||
player.setCanShoot(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paint(Graphics2D g) {
|
protected void paint(Graphics2D g) {
|
||||||
g.drawImage(this.img, 0, 0, null);
|
|
||||||
this.entityPaintIterator.reset();
|
this.entityPaintIterator.reset();
|
||||||
while (this.entityPaintIterator.hasNext()) {
|
while (this.entityPaintIterator.hasNext()) {
|
||||||
this.entityPaintIterator.next().paint(g);
|
this.entityPaintIterator.next().paint(g);
|
||||||
|
@ -70,11 +63,11 @@ public class GamePausedScreen extends Screen {
|
||||||
|
|
||||||
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0) {
|
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0) {
|
||||||
this.menuPoint = 1;
|
this.menuPoint = 1;
|
||||||
player.setPosition(player.getX(), 409);
|
cursor.setPosition(cursor.getX(), 409);
|
||||||
}
|
}
|
||||||
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0) {
|
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0) {
|
||||||
this.menuPoint = 0;
|
this.menuPoint = 0;
|
||||||
player.setPosition(player.getX(), 309);
|
cursor.setPosition(cursor.getX(), 309);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make a selection
|
// make a selection
|
||||||
|
@ -83,9 +76,9 @@ public class GamePausedScreen extends Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.animationStatus == 1) {
|
if(this.animationStatus == 1) {
|
||||||
if(player.getX() <= GameConfig.windowWidth) {
|
if(cursor.getX() <= GameConfig.windowWidth) {
|
||||||
player.setPosition(player.getX() + (int)playerMoveSpeed, player.getY());
|
cursor.setPosition(cursor.getX() + (int)cursorMoveSpeed, cursor.getY());
|
||||||
playerMoveSpeed += 0.1;
|
cursorMoveSpeed += 0.1;
|
||||||
} else this.animationStatus = 2;
|
} else this.animationStatus = 2;
|
||||||
} else if(this.animationStatus == 2) {
|
} else if(this.animationStatus == 2) {
|
||||||
switch (this.menuPoint) {
|
switch (this.menuPoint) {
|
||||||
|
|
|
@ -4,51 +4,44 @@ import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||||
import de.teamteamteam.spacescooter.entity.Player;
|
|
||||||
import de.teamteamteam.spacescooter.gui.Button;
|
import de.teamteamteam.spacescooter.gui.Button;
|
||||||
import de.teamteamteam.spacescooter.utility.Loader;
|
import de.teamteamteam.spacescooter.gui.ImageEntity;
|
||||||
|
import de.teamteamteam.spacescooter.utility.Highscore;
|
||||||
|
|
||||||
public class HighscoreScreen extends Screen{
|
public class HighscoreScreen extends Screen{
|
||||||
|
|
||||||
private BufferedImage img;
|
private ImageEntity cursor;
|
||||||
private float playerMoveSpeed = 0;
|
private float cursorMoveSpeed = 0;
|
||||||
private Player player;
|
|
||||||
private int animationStatus = 0; //0 = Animation noch nicht gestartet, 1 = Animation laeuft, 2 = Animation beendet
|
private int animationStatus = 0; //0 = Animation noch nicht gestartet, 1 = Animation laeuft, 2 = Animation beendet
|
||||||
private ArrayList<String> eintraege = new ArrayList<String>();
|
private int[] points;
|
||||||
|
private String[] names;
|
||||||
|
|
||||||
public HighscoreScreen(Screen parent) {
|
public HighscoreScreen(Screen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.img = Loader.getBufferedImageByFilename("images/shopbackground.png");
|
new ImageEntity(0, 0, "images/shopbackground.png");
|
||||||
new Button(GameConfig.windowWidth/2-125, GameConfig.windowHeight-75);
|
new Button(GameConfig.windowWidth/2-125, GameConfig.windowHeight-75);
|
||||||
player = new Player(GameConfig.windowWidth/2-170, GameConfig.windowHeight-63);
|
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, GameConfig.windowHeight-63, "images/ship.png");
|
||||||
player.setCanMove(false);
|
this.points = Highscore.getPoints();
|
||||||
player.setCanShoot(false);
|
this.names = Highscore.getNames();
|
||||||
readHighscore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paint(Graphics2D g) {
|
protected void paint(Graphics2D g) {
|
||||||
g.drawImage(this.img, 0, 0, null);
|
|
||||||
this.entityPaintIterator.reset();
|
this.entityPaintIterator.reset();
|
||||||
while (this.entityPaintIterator.hasNext()) {
|
while (this.entityPaintIterator.hasNext()) {
|
||||||
this.entityPaintIterator.next().paint(g);
|
this.entityPaintIterator.next().paint(g);
|
||||||
}
|
}
|
||||||
g.setFont(new Font("Monospace", 0, 20));
|
g.setFont(new Font("Monospace", 0, 20));
|
||||||
g.setColor(new Color(255, 255, 255));
|
g.setColor(new Color(255, 255, 255));
|
||||||
for(int i = 0; i<eintraege.size(); i++){
|
for(int i = 0; i<this.points.length; i++){
|
||||||
g.drawString(eintraege.get(i), 50, 27*(i+1));
|
g.drawString(String.valueOf(i+1), 50, 27*(i+1));
|
||||||
|
g.drawString(this.points[i] + "", 110, 27*(i+1));
|
||||||
|
g.drawString(this.names[i], 260, 27*(i+1));
|
||||||
}
|
}
|
||||||
g.setColor(new Color(0, 0, 0));
|
g.setColor(new Color(0, 0, 0));
|
||||||
g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-55, GameConfig.windowHeight-40);
|
g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-55, GameConfig.windowHeight-43);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,30 +50,12 @@ public class HighscoreScreen extends Screen{
|
||||||
this.animationStatus = 1;
|
this.animationStatus = 1;
|
||||||
}
|
}
|
||||||
if(this.animationStatus == 1) {
|
if(this.animationStatus == 1) {
|
||||||
if(this.player.getX() <= GameConfig.windowWidth) {
|
if(this.cursor.getX() <= GameConfig.windowWidth) {
|
||||||
this.player.setPosition(this.player.getX() + (int) playerMoveSpeed, this.player.getY());
|
this.cursor.setPosition(this.cursor.getX() + (int) cursorMoveSpeed, this.cursor.getY());
|
||||||
this.playerMoveSpeed += 0.1;
|
this.cursorMoveSpeed += 0.1;
|
||||||
} else this.animationStatus = 2;
|
} else this.animationStatus = 2;
|
||||||
} else if(this.animationStatus == 2) {
|
} else if(this.animationStatus == 2) {
|
||||||
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readHighscore(){
|
|
||||||
try {
|
|
||||||
File f = new File("save");
|
|
||||||
if(!f.exists()){
|
|
||||||
f.createNewFile();
|
|
||||||
}
|
|
||||||
Scanner scan = new Scanner(f);
|
|
||||||
while(scan.hasNextLine()){
|
|
||||||
this.eintraege.add(scan.nextLine());
|
|
||||||
}
|
|
||||||
scan.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,18 @@ import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.background.StarBackground;
|
import de.teamteamteam.spacescooter.background.StarBackground;
|
||||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||||
|
import de.teamteamteam.spacescooter.brain.PlayerSession;
|
||||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||||
import de.teamteamteam.spacescooter.entity.Player;
|
|
||||||
import de.teamteamteam.spacescooter.gui.Button;
|
import de.teamteamteam.spacescooter.gui.Button;
|
||||||
|
import de.teamteamteam.spacescooter.gui.ImageEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Screen show the games main menu.
|
* This Screen show the games main menu.
|
||||||
*/
|
*/
|
||||||
public class MainMenuScreen extends Screen {
|
public class MainMenuScreen extends Screen {
|
||||||
|
|
||||||
private Player player;
|
private ImageEntity cursor;
|
||||||
private float playerMoveSpeed = 0;
|
private float cursorMoveSpeed = 0;
|
||||||
private int colorValue = 0;
|
private int colorValue = 0;
|
||||||
private boolean colorValueIncrease = true;
|
private boolean colorValueIncrease = true;
|
||||||
private int menuPoint = 0;
|
private int menuPoint = 0;
|
||||||
|
@ -32,9 +33,7 @@ public class MainMenuScreen extends Screen {
|
||||||
new Button(GameConfig.windowWidth/2-125, 350);
|
new Button(GameConfig.windowWidth/2-125, 350);
|
||||||
new Button(GameConfig.windowWidth/2-125, 425);
|
new Button(GameConfig.windowWidth/2-125, 425);
|
||||||
new Button(GameConfig.windowWidth/2-125, 500);
|
new Button(GameConfig.windowWidth/2-125, 500);
|
||||||
player = new Player(GameConfig.windowWidth/2-170, 209);
|
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, 209, "images/ship.png");
|
||||||
player.setCanMove(false);
|
|
||||||
player.setCanShoot(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,13 +73,13 @@ public class MainMenuScreen extends Screen {
|
||||||
keyPressed = true;
|
keyPressed = true;
|
||||||
if(menuPoint<4){
|
if(menuPoint<4){
|
||||||
menuPoint++;
|
menuPoint++;
|
||||||
player.setPosition(player.getX(), 209+(menuPoint*75));
|
cursor.setPosition(cursor.getX(), 209+(menuPoint*75));
|
||||||
}
|
}
|
||||||
} else if(Keyboard.isKeyDown(KeyEvent.VK_UP) && !keyPressed && animationStatus == 0) {
|
} else if(Keyboard.isKeyDown(KeyEvent.VK_UP) && !keyPressed && animationStatus == 0) {
|
||||||
keyPressed = true;
|
keyPressed = true;
|
||||||
if(menuPoint>0) {
|
if(menuPoint>0) {
|
||||||
menuPoint--;
|
menuPoint--;
|
||||||
player.setPosition(player.getX(), 209+(menuPoint*75));
|
cursor.setPosition(cursor.getX(), 209+(menuPoint*75));
|
||||||
}
|
}
|
||||||
} else if(!Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !Keyboard.isKeyDown(KeyEvent.VK_UP)) {
|
} else if(!Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !Keyboard.isKeyDown(KeyEvent.VK_UP)) {
|
||||||
keyPressed = false;
|
keyPressed = false;
|
||||||
|
@ -92,9 +91,9 @@ public class MainMenuScreen extends Screen {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(animationStatus == 1) {
|
if(animationStatus == 1) {
|
||||||
if(player.getX() <= GameConfig.windowWidth) {
|
if(cursor.getX() <= GameConfig.windowWidth) {
|
||||||
player.setPosition(player.getX() + (int) playerMoveSpeed, player.getY());
|
cursor.setPosition(cursor.getX() + (int) cursorMoveSpeed, cursor.getY());
|
||||||
playerMoveSpeed += 0.1;
|
cursorMoveSpeed += 0.1;
|
||||||
} else animationStatus = 2;
|
} else animationStatus = 2;
|
||||||
} else if(animationStatus == 2) {
|
} else if(animationStatus == 2) {
|
||||||
switch (menuPoint) {
|
switch (menuPoint) {
|
||||||
|
|
|
@ -4,24 +4,19 @@ import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||||
import de.teamteamteam.spacescooter.brain.PlayerSession;
|
import de.teamteamteam.spacescooter.brain.PlayerSession;
|
||||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||||
import de.teamteamteam.spacescooter.entity.Player;
|
|
||||||
import de.teamteamteam.spacescooter.gui.Button;
|
import de.teamteamteam.spacescooter.gui.Button;
|
||||||
import de.teamteamteam.spacescooter.gui.ImageEntity;
|
import de.teamteamteam.spacescooter.gui.ImageEntity;
|
||||||
import de.teamteamteam.spacescooter.gui.ShopOffer;
|
import de.teamteamteam.spacescooter.gui.ShopOffer;
|
||||||
import de.teamteamteam.spacescooter.utility.Loader;
|
|
||||||
|
|
||||||
public class ShopScreen extends Screen {
|
public class ShopScreen extends Screen {
|
||||||
|
|
||||||
private BufferedImage img;
|
private ImageEntity cursor;
|
||||||
private float playerMoveSpeed = 0;
|
private float cursorMoveSpeed = 0;
|
||||||
private int menuPoint = 0;
|
private int menuPoint = 0;
|
||||||
private boolean keyPressed = false;
|
private boolean keyPressed = false;
|
||||||
private Player player;
|
|
||||||
private int animationStatus = 0; //0 = Animation noch nicht gestartet, 1 = Animation laeuft, 2 = Animation beendet
|
private int animationStatus = 0; //0 = Animation noch nicht gestartet, 1 = Animation laeuft, 2 = Animation beendet
|
||||||
private ShopOffer damage;
|
private ShopOffer damage;
|
||||||
private ShopOffer shield;
|
private ShopOffer shield;
|
||||||
|
@ -33,11 +28,11 @@ public class ShopScreen extends Screen {
|
||||||
*/
|
*/
|
||||||
public ShopScreen(Screen parent) {
|
public ShopScreen(Screen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
this.img = Loader.getBufferedImageByFilename("images/shopbackground.png");
|
new ImageEntity(0, 0, "images/shopbackground.png");
|
||||||
new Button(GameConfig.windowWidth/2-125, 500);
|
new Button(GameConfig.windowWidth/2-125, 500);
|
||||||
damage = new ShopOffer(100, 150, 15, PlayerSession.getShipShotUpgradesBought(), "Schaden 5C");
|
this.damage = new ShopOffer(100, 150, 15, PlayerSession.getShipShotUpgradesBought(), "Schaden 5C");
|
||||||
shield = new ShopOffer(100, 225, 15, PlayerSession.getShipShieldUpgradesBought(), "Schild 10C");
|
this.shield = new ShopOffer(100, 225, 15, PlayerSession.getShipShieldUpgradesBought(), "Schild 10C");
|
||||||
life = new ShopOffer(100, 300, 15, PlayerSession.getShipHealthUpgradesBought(), "Leben 10C");
|
this.life = new ShopOffer(100, 300, 15, PlayerSession.getShipHealthUpgradesBought(), "Leben 10C");
|
||||||
new ImageEntity(GameConfig.windowWidth / 2 - 120, 365, "images/shop/shoprocket.png");
|
new ImageEntity(GameConfig.windowWidth / 2 - 120, 365, "images/shop/shoprocket.png");
|
||||||
new ImageEntity(GameConfig.windowWidth / 2 + 30, 365, "images/shop/shopbeam.png");
|
new ImageEntity(GameConfig.windowWidth / 2 + 30, 365, "images/shop/shopbeam.png");
|
||||||
if(PlayerSession.getSecondsecondaryWeapon() == 1){
|
if(PlayerSession.getSecondsecondaryWeapon() == 1){
|
||||||
|
@ -47,14 +42,11 @@ public class ShopScreen extends Screen {
|
||||||
System.out.println("2");
|
System.out.println("2");
|
||||||
select = new ImageEntity(GameConfig.windowWidth / 2 + 20, 355, "images/shop/select.png");
|
select = new ImageEntity(GameConfig.windowWidth / 2 + 20, 355, "images/shop/select.png");
|
||||||
}
|
}
|
||||||
player = new Player(50, 149);
|
this.cursor = new ImageEntity(50, 149, "images/ship.png");
|
||||||
player.setCanMove(false);
|
|
||||||
player.setCanShoot(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paint(Graphics2D g) {
|
protected void paint(Graphics2D g) {
|
||||||
g.drawImage(this.img, 0, 0, null);
|
|
||||||
this.entityPaintIterator.reset();
|
this.entityPaintIterator.reset();
|
||||||
while (this.entityPaintIterator.hasNext()) {
|
while (this.entityPaintIterator.hasNext()) {
|
||||||
this.entityPaintIterator.next().paint(g);
|
this.entityPaintIterator.next().paint(g);
|
||||||
|
@ -79,11 +71,11 @@ public class ShopScreen extends Screen {
|
||||||
if(this.menuPoint<4){
|
if(this.menuPoint<4){
|
||||||
this.menuPoint++;
|
this.menuPoint++;
|
||||||
if(menuPoint == 3){
|
if(menuPoint == 3){
|
||||||
this.player.setPosition(GameConfig.windowWidth/2-180, 390);
|
this.cursor.setPosition(GameConfig.windowWidth/2-180, 390);
|
||||||
}else if(menuPoint == 4){
|
}else if(menuPoint == 4){
|
||||||
this.player.setPosition(GameConfig.windowWidth/2-170, 508);
|
this.cursor.setPosition(GameConfig.windowWidth/2-170, 508);
|
||||||
}else{
|
}else{
|
||||||
this.player.setPosition(this.player.getX(), 149+(this.menuPoint*75));
|
this.cursor.setPosition(this.cursor.getX(), 149+(this.menuPoint*75));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(Keyboard.isKeyDown(KeyEvent.VK_UP) && !this.keyPressed && this.animationStatus == 0) {
|
}else if(Keyboard.isKeyDown(KeyEvent.VK_UP) && !this.keyPressed && this.animationStatus == 0) {
|
||||||
|
@ -91,16 +83,16 @@ public class ShopScreen extends Screen {
|
||||||
if(this.menuPoint>0) {
|
if(this.menuPoint>0) {
|
||||||
this.menuPoint--;
|
this.menuPoint--;
|
||||||
if(menuPoint == 3){
|
if(menuPoint == 3){
|
||||||
this.player.setPosition(GameConfig.windowWidth/2-180, 390);
|
this.cursor.setPosition(GameConfig.windowWidth/2-180, 390);
|
||||||
}else{
|
}else{
|
||||||
this.player.setPosition(50, 149+(this.menuPoint*75));
|
this.cursor.setPosition(50, 149+(this.menuPoint*75));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selection.
|
* Selection.
|
||||||
*/
|
*/
|
||||||
}else if ( (Keyboard.isKeyDown(KeyEvent.VK_SPACE) || Keyboard.isKeyDown(KeyEvent.VK_ENTER)) && !this.keyPressed && this.animationStatus == 0) {
|
}else if((Keyboard.isKeyDown(KeyEvent.VK_SPACE) || Keyboard.isKeyDown(KeyEvent.VK_ENTER)) && !this.keyPressed && this.animationStatus == 0) {
|
||||||
this.keyPressed = true;
|
this.keyPressed = true;
|
||||||
switch (this.menuPoint) {
|
switch (this.menuPoint) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -149,9 +141,9 @@ public class ShopScreen extends Screen {
|
||||||
* Animation.
|
* Animation.
|
||||||
*/
|
*/
|
||||||
if(this.animationStatus == 1) {
|
if(this.animationStatus == 1) {
|
||||||
if(this.player.getX() <= GameConfig.windowWidth) {
|
if(this.cursor.getX() <= GameConfig.windowWidth) {
|
||||||
this.player.setPosition(this.player.getX() + (int) playerMoveSpeed, this.player.getY());
|
this.cursor.setPosition(this.cursor.getX() + (int) cursorMoveSpeed, this.cursor.getY());
|
||||||
this.playerMoveSpeed += 0.1;
|
this.cursorMoveSpeed += 0.1;
|
||||||
} else this.animationStatus = 2;
|
} else this.animationStatus = 2;
|
||||||
} else if(this.animationStatus == 2) {
|
} else if(this.animationStatus == 2) {
|
||||||
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
||||||
|
|
|
@ -0,0 +1,128 @@
|
||||||
|
package de.teamteamteam.spacescooter.utility;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
|
public class Highscore {
|
||||||
|
/**
|
||||||
|
* Points for the high score.
|
||||||
|
*/
|
||||||
|
private static int[] points;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Names for the high score.
|
||||||
|
*/
|
||||||
|
private static String[] names;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the high score from the save file, if it has not been loaded yet.
|
||||||
|
* If the file not exist, the standard value "0" and "Name" will be loaded for every entry.
|
||||||
|
*/
|
||||||
|
private static final void loadHighscore(){
|
||||||
|
if(Highscore.points == null || Highscore.names == null){
|
||||||
|
try {
|
||||||
|
File f = new File("Highscore");
|
||||||
|
if(!f.exists()){
|
||||||
|
int[] point;
|
||||||
|
String[] name;
|
||||||
|
point = new int[20];
|
||||||
|
name = new String[20];
|
||||||
|
for(int i = 0; i<point.length; i++){
|
||||||
|
point[i] = 0;
|
||||||
|
name[i] = "Name";
|
||||||
|
}
|
||||||
|
Highscore.points = point;
|
||||||
|
Highscore.names = name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FileInputStream fis = new FileInputStream(f);
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||||
|
Highscore.points = (int[])ois.readObject();
|
||||||
|
Highscore.names = (String[])ois.readObject();
|
||||||
|
ois.close();
|
||||||
|
fis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the high score.
|
||||||
|
*/
|
||||||
|
private static final void saveScore(){
|
||||||
|
try {
|
||||||
|
if(Highscore.points == null || Highscore.names == null){
|
||||||
|
Highscore.loadHighscore();
|
||||||
|
}
|
||||||
|
File f = new File("Highscore");
|
||||||
|
if(!f.exists()){
|
||||||
|
f.createNewFile();
|
||||||
|
}
|
||||||
|
FileOutputStream fos = new FileOutputStream(f);
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||||
|
oos.writeObject(Highscore.points);
|
||||||
|
oos.writeObject(Highscore.names);
|
||||||
|
oos.close();
|
||||||
|
fos.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the points of the high score.
|
||||||
|
* Load the high score, if it has not been loaded yet.
|
||||||
|
*/
|
||||||
|
public static final int[] getPoints(){
|
||||||
|
Highscore.loadHighscore();
|
||||||
|
return Highscore.points;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the names of the high score.
|
||||||
|
* Load the high score, if it has not been loaded yet.
|
||||||
|
*/
|
||||||
|
public static final String[] getNames(){
|
||||||
|
Highscore.loadHighscore();
|
||||||
|
return Highscore.names;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new high score.
|
||||||
|
*/
|
||||||
|
public static void newScore(int point, String name){
|
||||||
|
Highscore.loadHighscore();
|
||||||
|
int placemant = getPlacement(point);
|
||||||
|
int temp = 19;
|
||||||
|
if(placemant == -1) return;
|
||||||
|
while(temp>placemant){
|
||||||
|
points[temp] = points[temp-1];
|
||||||
|
names[temp] = names[temp-1];
|
||||||
|
temp--;
|
||||||
|
}
|
||||||
|
points[placemant] = point;
|
||||||
|
names[placemant] = name;
|
||||||
|
saveScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get your placement in the high score, -1 if the score is too low
|
||||||
|
*/
|
||||||
|
public static int getPlacement(int point){
|
||||||
|
Highscore.loadHighscore();
|
||||||
|
for(int i = 0; i<20; i++){
|
||||||
|
if(point>=Highscore.points[i]) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -138,6 +138,7 @@ public class Loader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preload a LevelConfig by simply parsing it into a LevelConfig object.
|
* Preload a LevelConfig by simply parsing it into a LevelConfig object.
|
||||||
*/
|
*/
|
||||||
|
@ -211,5 +212,4 @@ public class Loader {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue