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:
Sosch 2014-12-09 22:46:01 +01:00
parent 9bba32307e
commit 41a0775e65
14 changed files with 455 additions and 188 deletions

BIN
Highscore Normal file

Binary file not shown.

BIN
res/images/letterbox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

View File

@ -26,14 +26,9 @@ public class Player extends ShootingEntity implements KeyboardListener {
private Keyboard keyboard;
/**
* Rocket Ammunition
* Ammunition of the secondary weapon.
*/
private int rocketAmount;
/**
* Beam Ammunition
*/
private int beamAmount;
private int secondaryWeaponAmount;
/**
* Cooldown countdown value to use in case
@ -54,8 +49,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
*/
public Player(int x, int y) {
super(x, y);
this.rocketAmount = 1;
this.beamAmount = 1;
this.secondaryWeaponAmount = 0;
this.collisionCooldown = 150;
this.currentCollisionCooldown = 0;
this.setImage("images/ship.png");
@ -113,13 +107,15 @@ public class Player extends ShootingEntity implements KeyboardListener {
this.shoot();
}
if(Keyboard.isKeyDown(KeyEvent.VK_Y)) {
if(PlayerSession.getSecondsecondaryWeapon() == 1 && this.rocketAmount > 0) {
if(this.secondaryWeaponAmount > 0){
if(PlayerSession.getSecondsecondaryWeapon() == 1) {
this.shootRocket();
}else if(PlayerSession.getSecondsecondaryWeapon() == 2 && this.beamAmount > 0) {
}else if(PlayerSession.getSecondsecondaryWeapon() == 2) {
this.shootBeam();
}
}
}
}
/**
* Override paint method for custom effects
@ -223,46 +219,34 @@ public class Player extends ShootingEntity implements KeyboardListener {
@Override
public void createRocket() {
super.createRocket();
this.removeRocketAmount();
this.removeSecondaryWeaponAmount();
}
@Override
public void createBeam() {
super.createBeam();
this.removeBeamAmount();
this.removeSecondaryWeaponAmount();
}
/**
* Get the current rocket amount.
* Get the current secondary weapon amount.
*/
public int getRocketAmount(){
return rocketAmount;
public int getSecondaryWeaponAmount(){
return secondaryWeaponAmount;
}
public int getBeamAmount(){
return beamAmount;
/**
* Add one secondary weapon amount.
*/
public void addSecondaryWeaponAmount(){
secondaryWeaponAmount++;
}
/**
* Add one rocket.
* Remove one secondary weapon amount.
*/
public void addRocketAmount(){
rocketAmount++;
public void removeSecondaryWeaponAmount(){
secondaryWeaponAmount--;
}
public void addBeamAmount(){
beamAmount++;
}
/**
* Remove one rocket.
*/
public void removeRocketAmount(){
rocketAmount--;
}
public void removeBeamAmount(){
beamAmount--;
}
}

View File

@ -11,7 +11,7 @@ public class ItemBeam extends Item {
@Override
public void itemCollected(Player player) {
player.addBeamAmount();;
player.addSecondaryWeaponAmount();
}
}

View File

@ -11,7 +11,7 @@ public class ItemRocket extends Item {
@Override
public void itemCollected(Player player) {
player.addRocketAmount();
player.addSecondaryWeaponAmount();
}
}

View File

@ -1,16 +1,51 @@
package de.teamteamteam.spacescooter.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import de.teamteamteam.spacescooter.entity.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) {
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(){}
}

View File

@ -10,6 +10,9 @@ import de.teamteamteam.spacescooter.screen.GameScreen;
public class SecondaryWeaponAmount extends Entity{
/**
* Show the current secondary weapon amount in the interface bar.
*/
public SecondaryWeaponAmount(int x, int y) {
super(x, y);
if(PlayerSession.getSecondsecondaryWeapon() == 1){
@ -23,11 +26,8 @@ public class SecondaryWeaponAmount extends Entity{
public void paint(Graphics2D g) {
g.setColor(Color.WHITE);
g.setFont(new Font("Monospace", 0, 16));
if(PlayerSession.getSecondsecondaryWeapon() == 1){
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);
}
g.drawString("x " + GameScreen.getPlayer().getSecondaryWeaponAmount(), this.getX() + 30, this.getY() + 12);
}
@Override

View File

@ -3,15 +3,15 @@ package de.teamteamteam.spacescooter.screen;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player;
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
@ -20,43 +20,89 @@ import de.teamteamteam.spacescooter.utility.Loader;
*/
public class GameOverScreen extends Screen {
private BufferedImage img;
private Player player;
private float playerMoveSpeed = 0;
private ImageEntity cursor;
private float cursorMoveSpeed = 0;
private int colorValue = 0;
private boolean colorValueIncrease = true;
private int menuPoint = 0;
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) {
super(parent);
this.img = Loader.getBufferedImageByFilename("images/pausebackground.png");
new ImageEntity(0, 0, "images/shopbackground.png");
this.score = PlayerSession.getScore();
if(Highscore.getPlacement(score) != -1){ // Player has a new high score
saveScoreMenu = true;
this.cursor = new ImageEntity(173, 293, "images/ship.png");
for(int i = 0; i<10; i++){
lettersbox[i] = new ImageEntity(150 + (i*50), 200, "images/letterbox.png");
}
}else{
saveScoreMenu = false;
new Button(GameConfig.windowWidth/2-125, 300);
new Button(GameConfig.windowWidth/2-125, 400);
player = new Player(GameConfig.windowWidth/2-170, 309);
player.setCanMove(false);
player.setCanShoot(false);
//Reset the player session for the next player.
//TODO: Make sure highscore "enter name" stuff happened before!
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, 309, "images/ship.png");
}
PlayerSession.reset();
}
@Override
protected void paint(Graphics2D g) {
g.drawImage(this.img, 0, 0, null);
this.entityPaintIterator.reset();
while (this.entityPaintIterator.hasNext()) {
this.entityPaintIterator.next().paint(g);
}
g.setFont(new Font("Monospace", 0, 100));
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);
// Paint the screen to enter a name for the high score
if(saveScoreMenu){
g.setFont(new Font("Monospace", 0, 30));
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(new Color(0, 0, 0));
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
protected void update() {
@ -64,7 +110,6 @@ public class GameOverScreen extends Screen {
while (this.entityUpdateIterator.hasNext()) {
this.entityUpdateIterator.next().update();
}
if(this.colorValueIncrease) {
this.colorValue += 2;
if(this.colorValue > 70) this.colorValueIncrease = false;
@ -72,26 +117,117 @@ public class GameOverScreen extends Screen {
this.colorValue -= 2;
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();
}
}
//Control in the game normal over menu (if the player does not came in the high score).
}else{
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0){
this.menuPoint = 1;
player.setPosition(player.getX(), 409);
this.cursor.setPosition(this.cursor.getX(), 409);
}
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0){
this.menuPoint = 0;
player.setPosition(player.getX(), 309);
this.cursor.setPosition(this.cursor.getX(), 309);
}
// make a selection
if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE) && !this.keyPressed) {
this.animationStatus = 1;
}
}
if(this.animationStatus == 1) {
if(player.getX() <= GameConfig.windowWidth) {
player.setPosition(player.getX() + (int) playerMoveSpeed, player.getY());
playerMoveSpeed += 0.1;
if(this.cursor.getX() <= GameConfig.windowWidth) {
this.cursor.setPosition(this.cursor.getX() + (int) this.cursorMoveSpeed, this.cursor.getY());
this.cursorMoveSpeed += 0.1;
} else this.animationStatus = 2;
} else if(this.animationStatus == 2) {
if(saveScoreMenu){
this.cursor.remove();
for(int i = 0; i<10; i++){
if(lettersbox[i] != null) lettersbox[i].remove();
if(letters[i] != null)letters[i].remove();
}
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"));
@ -102,5 +238,30 @@ public class GameOverScreen extends Screen {
}
}
}
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++;
}
}

View File

@ -4,13 +4,10 @@ import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player;
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.
@ -19,9 +16,8 @@ import de.teamteamteam.spacescooter.utility.Loader;
*/
public class GamePausedScreen extends Screen {
private BufferedImage img;
private Player player;
private float playerMoveSpeed = 0;
private ImageEntity cursor;
private float cursorMoveSpeed = 0;
private int colorValue = 0;
private boolean colorValueIncrease = true;
private int menuPoint = 0;
@ -29,17 +25,14 @@ public class GamePausedScreen extends Screen {
public GamePausedScreen(Screen 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, 400);
player = new Player(GameConfig.windowWidth/2-170, 309);
player.setCanMove(false);
player.setCanShoot(false);
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, 309, "images/ship.png");
}
@Override
protected void paint(Graphics2D g) {
g.drawImage(this.img, 0, 0, null);
this.entityPaintIterator.reset();
while (this.entityPaintIterator.hasNext()) {
this.entityPaintIterator.next().paint(g);
@ -70,11 +63,11 @@ public class GamePausedScreen extends Screen {
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0) {
this.menuPoint = 1;
player.setPosition(player.getX(), 409);
cursor.setPosition(cursor.getX(), 409);
}
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0) {
this.menuPoint = 0;
player.setPosition(player.getX(), 309);
cursor.setPosition(cursor.getX(), 309);
}
// make a selection
@ -83,9 +76,9 @@ public class GamePausedScreen extends Screen {
}
if(this.animationStatus == 1) {
if(player.getX() <= GameConfig.windowWidth) {
player.setPosition(player.getX() + (int)playerMoveSpeed, player.getY());
playerMoveSpeed += 0.1;
if(cursor.getX() <= GameConfig.windowWidth) {
cursor.setPosition(cursor.getX() + (int)cursorMoveSpeed, cursor.getY());
cursorMoveSpeed += 0.1;
} else this.animationStatus = 2;
} else if(this.animationStatus == 2) {
switch (this.menuPoint) {

View File

@ -4,51 +4,44 @@ import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
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.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player;
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{
private BufferedImage img;
private float playerMoveSpeed = 0;
private Player player;
private ImageEntity cursor;
private float cursorMoveSpeed = 0;
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) {
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);
player = new Player(GameConfig.windowWidth/2-170, GameConfig.windowHeight-63);
player.setCanMove(false);
player.setCanShoot(false);
readHighscore();
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, GameConfig.windowHeight-63, "images/ship.png");
this.points = Highscore.getPoints();
this.names = Highscore.getNames();
}
@Override
protected void paint(Graphics2D g) {
g.drawImage(this.img, 0, 0, null);
this.entityPaintIterator.reset();
while (this.entityPaintIterator.hasNext()) {
this.entityPaintIterator.next().paint(g);
}
g.setFont(new Font("Monospace", 0, 20));
g.setColor(new Color(255, 255, 255));
for(int i = 0; i<eintraege.size(); i++){
g.drawString(eintraege.get(i), 50, 27*(i+1));
for(int i = 0; i<this.points.length; i++){
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.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-55, GameConfig.windowHeight-40);
g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-55, GameConfig.windowHeight-43);
}
@Override
@ -57,30 +50,12 @@ public class HighscoreScreen extends Screen{
this.animationStatus = 1;
}
if(this.animationStatus == 1) {
if(this.player.getX() <= GameConfig.windowWidth) {
this.player.setPosition(this.player.getX() + (int) playerMoveSpeed, this.player.getY());
this.playerMoveSpeed += 0.1;
if(this.cursor.getX() <= GameConfig.windowWidth) {
this.cursor.setPosition(this.cursor.getX() + (int) cursorMoveSpeed, this.cursor.getY());
this.cursorMoveSpeed += 0.1;
} else this.animationStatus = 2;
} else if(this.animationStatus == 2) {
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();
}
}
}

View File

@ -7,17 +7,18 @@ import java.awt.event.KeyEvent;
import de.teamteamteam.spacescooter.background.StarBackground;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.gui.Button;
import de.teamteamteam.spacescooter.gui.ImageEntity;
/**
* This Screen show the games main menu.
*/
public class MainMenuScreen extends Screen {
private Player player;
private float playerMoveSpeed = 0;
private ImageEntity cursor;
private float cursorMoveSpeed = 0;
private int colorValue = 0;
private boolean colorValueIncrease = true;
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, 425);
new Button(GameConfig.windowWidth/2-125, 500);
player = new Player(GameConfig.windowWidth/2-170, 209);
player.setCanMove(false);
player.setCanShoot(false);
this.cursor = new ImageEntity(GameConfig.windowWidth/2-170, 209, "images/ship.png");
}
@Override
@ -74,13 +73,13 @@ public class MainMenuScreen extends Screen {
keyPressed = true;
if(menuPoint<4){
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) {
keyPressed = true;
if(menuPoint>0) {
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)) {
keyPressed = false;
@ -92,9 +91,9 @@ public class MainMenuScreen extends Screen {
}
if(animationStatus == 1) {
if(player.getX() <= GameConfig.windowWidth) {
player.setPosition(player.getX() + (int) playerMoveSpeed, player.getY());
playerMoveSpeed += 0.1;
if(cursor.getX() <= GameConfig.windowWidth) {
cursor.setPosition(cursor.getX() + (int) cursorMoveSpeed, cursor.getY());
cursorMoveSpeed += 0.1;
} else animationStatus = 2;
} else if(animationStatus == 2) {
switch (menuPoint) {

View File

@ -4,24 +4,19 @@ import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.gui.Button;
import de.teamteamteam.spacescooter.gui.ImageEntity;
import de.teamteamteam.spacescooter.gui.ShopOffer;
import de.teamteamteam.spacescooter.utility.Loader;
public class ShopScreen extends Screen {
private BufferedImage img;
private float playerMoveSpeed = 0;
private ImageEntity cursor;
private float cursorMoveSpeed = 0;
private int menuPoint = 0;
private boolean keyPressed = false;
private Player player;
private int animationStatus = 0; //0 = Animation noch nicht gestartet, 1 = Animation laeuft, 2 = Animation beendet
private ShopOffer damage;
private ShopOffer shield;
@ -33,11 +28,11 @@ public class ShopScreen extends Screen {
*/
public ShopScreen(Screen parent) {
super(parent);
this.img = Loader.getBufferedImageByFilename("images/shopbackground.png");
new ImageEntity(0, 0, "images/shopbackground.png");
new Button(GameConfig.windowWidth/2-125, 500);
damage = new ShopOffer(100, 150, 15, PlayerSession.getShipShotUpgradesBought(), "Schaden 5C");
shield = new ShopOffer(100, 225, 15, PlayerSession.getShipShieldUpgradesBought(), "Schild 10C");
life = new ShopOffer(100, 300, 15, PlayerSession.getShipHealthUpgradesBought(), "Leben 10C");
this.damage = new ShopOffer(100, 150, 15, PlayerSession.getShipShotUpgradesBought(), "Schaden 5C");
this.shield = new ShopOffer(100, 225, 15, PlayerSession.getShipShieldUpgradesBought(), "Schild 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 + 30, 365, "images/shop/shopbeam.png");
if(PlayerSession.getSecondsecondaryWeapon() == 1){
@ -47,14 +42,11 @@ public class ShopScreen extends Screen {
System.out.println("2");
select = new ImageEntity(GameConfig.windowWidth / 2 + 20, 355, "images/shop/select.png");
}
player = new Player(50, 149);
player.setCanMove(false);
player.setCanShoot(false);
this.cursor = new ImageEntity(50, 149, "images/ship.png");
}
@Override
protected void paint(Graphics2D g) {
g.drawImage(this.img, 0, 0, null);
this.entityPaintIterator.reset();
while (this.entityPaintIterator.hasNext()) {
this.entityPaintIterator.next().paint(g);
@ -79,11 +71,11 @@ public class ShopScreen extends Screen {
if(this.menuPoint<4){
this.menuPoint++;
if(menuPoint == 3){
this.player.setPosition(GameConfig.windowWidth/2-180, 390);
this.cursor.setPosition(GameConfig.windowWidth/2-180, 390);
}else if(menuPoint == 4){
this.player.setPosition(GameConfig.windowWidth/2-170, 508);
this.cursor.setPosition(GameConfig.windowWidth/2-170, 508);
}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) {
@ -91,9 +83,9 @@ public class ShopScreen extends Screen {
if(this.menuPoint>0) {
this.menuPoint--;
if(menuPoint == 3){
this.player.setPosition(GameConfig.windowWidth/2-180, 390);
this.cursor.setPosition(GameConfig.windowWidth/2-180, 390);
}else{
this.player.setPosition(50, 149+(this.menuPoint*75));
this.cursor.setPosition(50, 149+(this.menuPoint*75));
}
}
@ -149,9 +141,9 @@ public class ShopScreen extends Screen {
* Animation.
*/
if(this.animationStatus == 1) {
if(this.player.getX() <= GameConfig.windowWidth) {
this.player.setPosition(this.player.getX() + (int) playerMoveSpeed, this.player.getY());
this.playerMoveSpeed += 0.1;
if(this.cursor.getX() <= GameConfig.windowWidth) {
this.cursor.setPosition(this.cursor.getX() + (int) cursorMoveSpeed, this.cursor.getY());
this.cursorMoveSpeed += 0.1;
} else this.animationStatus = 2;
} else if(this.animationStatus == 2) {
this.parent.setOverlay(new MainMenuScreen(this.parent));

View File

@ -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;
}
}

View File

@ -138,6 +138,7 @@ public class Loader {
}
}
/**
* Preload a LevelConfig by simply parsing it into a LevelConfig object.
*/
@ -211,5 +212,4 @@ public class Loader {
e.printStackTrace();
}
}
}