diff --git a/Highscore b/Highscore new file mode 100644 index 0000000..873e1da Binary files /dev/null and b/Highscore differ diff --git a/res/images/letterbox.png b/res/images/letterbox.png new file mode 100644 index 0000000..fac75ab Binary files /dev/null and b/res/images/letterbox.png differ diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index c650fcd..fd9f4b5 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -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,10 +107,12 @@ public class Player extends ShootingEntity implements KeyboardListener { this.shoot(); } if(Keyboard.isKeyDown(KeyEvent.VK_Y)) { - if(PlayerSession.getSecondsecondaryWeapon() == 1 && this.rocketAmount > 0) { - this.shootRocket(); - }else if(PlayerSession.getSecondsecondaryWeapon() == 2 && this.beamAmount > 0) { - this.shootBeam(); + if(this.secondaryWeaponAmount > 0){ + if(PlayerSession.getSecondsecondaryWeapon() == 1) { + this.shootRocket(); + }else if(PlayerSession.getSecondsecondaryWeapon() == 2) { + this.shootBeam(); + } } } } @@ -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--; - } } diff --git a/src/de/teamteamteam/spacescooter/entity/item/ItemBeam.java b/src/de/teamteamteam/spacescooter/entity/item/ItemBeam.java index a3e0b46..11df243 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/ItemBeam.java +++ b/src/de/teamteamteam/spacescooter/entity/item/ItemBeam.java @@ -11,7 +11,7 @@ public class ItemBeam extends Item { @Override public void itemCollected(Player player) { - player.addBeamAmount();; + player.addSecondaryWeaponAmount(); } } diff --git a/src/de/teamteamteam/spacescooter/entity/item/ItemRocket.java b/src/de/teamteamteam/spacescooter/entity/item/ItemRocket.java index fe0279f..59440de 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/ItemRocket.java +++ b/src/de/teamteamteam/spacescooter/entity/item/ItemRocket.java @@ -11,7 +11,7 @@ public class ItemRocket extends Item { @Override public void itemCollected(Player player) { - player.addRocketAmount(); + player.addSecondaryWeaponAmount(); } } diff --git a/src/de/teamteamteam/spacescooter/gui/ImageEntity.java b/src/de/teamteamteam/spacescooter/gui/ImageEntity.java index b32422e..210106e 100644 --- a/src/de/teamteamteam/spacescooter/gui/ImageEntity.java +++ b/src/de/teamteamteam/spacescooter/gui/ImageEntity.java @@ -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(){} } diff --git a/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java b/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java index c6c6c9a..69ec249 100644 --- a/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java +++ b/src/de/teamteamteam/spacescooter/gui/SecondaryWeaponAmount.java @@ -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 diff --git a/src/de/teamteamteam/spacescooter/screen/GameOverScreen.java b/src/de/teamteamteam/spacescooter/screen/GameOverScreen.java index 6386598..121690c 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameOverScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameOverScreen.java @@ -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 @@ -19,43 +19,89 @@ import de.teamteamteam.spacescooter.utility.Loader; * It allows to start a new game or going to the MainMenuScreen. */ 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 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! + 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); + 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.setFont(new Font("Monospace", 0, 20)); - g.setColor(new Color(0, 0, 0)); - g.drawString("Wiederholen", GameConfig.windowWidth/2-60, 332); - g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-60, 432); + 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(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 @@ -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,35 +117,151 @@ 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(); + } + } - if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0){ - this.menuPoint = 1; - player.setPosition(player.getX(), 409); - } - if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0){ - this.menuPoint = 0; - player.setPosition(player.getX(), 309); - } - - // make a selection - if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { - this.animationStatus = 1; + //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; + this.cursor.setPosition(this.cursor.getX(), 409); + } + 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.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) { - 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(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")); + 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++; + } + } diff --git a/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java b/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java index fc40c13..c518259 100644 --- a/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java @@ -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) { diff --git a/src/de/teamteamteam/spacescooter/screen/HighscoreScreen.java b/src/de/teamteamteam/spacescooter/screen/HighscoreScreen.java index bdf57a4..cfcead7 100644 --- a/src/de/teamteamteam/spacescooter/screen/HighscoreScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/HighscoreScreen.java @@ -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 eintraege = new ArrayList(); + 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; i0) { 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) { diff --git a/src/de/teamteamteam/spacescooter/screen/ShopScreen.java b/src/de/teamteamteam/spacescooter/screen/ShopScreen.java index 418a332..18ea0e5 100644 --- a/src/de/teamteamteam/spacescooter/screen/ShopScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/ShopScreen.java @@ -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,16 +83,16 @@ 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)); } } /** * 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; switch (this.menuPoint) { case 0: @@ -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)); diff --git a/src/de/teamteamteam/spacescooter/utility/Highscore.java b/src/de/teamteamteam/spacescooter/utility/Highscore.java new file mode 100644 index 0000000..af18731 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/utility/Highscore.java @@ -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; iplacemant){ + 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; + } +} diff --git a/src/de/teamteamteam/spacescooter/utility/Loader.java b/src/de/teamteamteam/spacescooter/utility/Loader.java index 8d4b93b..6edacd1 100644 --- a/src/de/teamteamteam/spacescooter/utility/Loader.java +++ b/src/de/teamteamteam/spacescooter/utility/Loader.java @@ -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(); } } - }