diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 661ee90..48c808b 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -7,6 +7,7 @@ import de.teamteamteam.spacescooter.entity.explosion.Explosion; import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.entity.spi.Hittable; +import de.teamteamteam.spacescooter.gui.Credits; import de.teamteamteam.spacescooter.utility.GameConfig; /** @@ -106,6 +107,9 @@ public abstract class LivingEntity extends Entity implements Collidable, Hittabl //Set the correct values for gui indicators this.healthPoints = 0; this.shieldPoints = 0; + if(this instanceof Enemy){ // Add 1 credit for the shop + Credits.setCredits(Credits.getCredits() + 1); + } if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP"); this.die(); } diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 0037fa8..8aa9768 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -18,13 +18,13 @@ public class Player extends ShootingEntity implements KeyboardListener { super(x, y); this.setImage("images/ship.png"); this.setPrimaryShotImage("images/shots/laser_blue.png"); - this.setShootDamage(5); + this.setShootDamage(PlayerStatus.ShootDamage); this.setShootDelay(20); this.setShootSpawn(50, 16); this.setShootDirection(Shot.RIGHT); this.setShootSpeed(10); this.setCollisionDamage(10); - this.setHealthPoints(100); + this.setHealthPoints(PlayerStatus.HealthPoints); this.registerOnKeyboard(Keyboard.getInstance()); } diff --git a/src/de/teamteamteam/spacescooter/entity/PlayerStatus.java b/src/de/teamteamteam/spacescooter/entity/PlayerStatus.java new file mode 100644 index 0000000..5b2dcef --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/PlayerStatus.java @@ -0,0 +1,11 @@ +package de.teamteamteam.spacescooter.entity; + +public class PlayerStatus { + + /** + * Status values for the player + */ + + public static int ShootDamage = 5; + public static int HealthPoints = 100; +} diff --git a/src/de/teamteamteam/spacescooter/gui/Credits.java b/src/de/teamteamteam/spacescooter/gui/Credits.java new file mode 100644 index 0000000..930a580 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/gui/Credits.java @@ -0,0 +1,17 @@ +package de.teamteamteam.spacescooter.gui; + +public class Credits { + /** + * Credit points for the shop + */ + private static int credits = 1000; + + public static int getCredits() { + return credits; + } + + public static void setCredits(int credits) { + Credits.credits = credits; + System.out.println(credits); + } +} diff --git a/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java b/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java index f06075f..4c56e02 100644 --- a/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java @@ -101,6 +101,7 @@ public class MainMenuScreen extends Screen { this.parent.setOverlay(new GameScreen(this.parent)); break; case 1: + this.parent.setOverlay(new ShopScreen(this.parent)); break; case 2: break; diff --git a/src/de/teamteamteam/spacescooter/screen/ShopScreen.java b/src/de/teamteamteam/spacescooter/screen/ShopScreen.java new file mode 100644 index 0000000..64afe4a --- /dev/null +++ b/src/de/teamteamteam/spacescooter/screen/ShopScreen.java @@ -0,0 +1,101 @@ +package de.teamteamteam.spacescooter.screen; + +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.control.Keyboard; +import de.teamteamteam.spacescooter.entity.Player; +import de.teamteamteam.spacescooter.entity.PlayerStatus; +import de.teamteamteam.spacescooter.gui.Button; +import de.teamteamteam.spacescooter.gui.Credits; +import de.teamteamteam.spacescooter.utility.GameConfig; +import de.teamteamteam.spacescooter.utility.Loader; + +public class ShopScreen extends Screen { + + private BufferedImage img; + private float playerMoveSpeed = 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 + + public ShopScreen(Screen parent) { + super(parent); + this.img = Loader.getBufferedImageByFilename("images/testbackground.png"); + new Button(GameConfig.windowWidth/2-125, 250); + new Button(GameConfig.windowWidth/2-125, 350); + new Button(GameConfig.windowWidth/2-125, 450); + player = new Player(GameConfig.windowWidth/2-170, 259); + player.setCanMove(false); + player.setCanShoot(false); + } + + @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)); + g.drawString("Credits: " + String.valueOf(Credits.getCredits()), GameConfig.windowWidth/2-30, 200); + g.setColor(new Color(0, 0, 0)); + g.drawString("Schaden", GameConfig.windowWidth/2-30, 282); + g.drawString("Leben", GameConfig.windowWidth/2-50, 382); + g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-50, 482); + } + + @Override + protected void update() { + if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !this.keyPressed && this.animationStatus == 0) { + this.keyPressed = true; + if(this.menuPoint<2){ + this.menuPoint++; + this.player.setPosition(this.player.getX(), 259+(this.menuPoint*100)); + } + }else if(Keyboard.isKeyDown(KeyEvent.VK_UP) && !this.keyPressed && this.animationStatus == 0) { + this.keyPressed = true; + if(this.menuPoint>0) { + this.menuPoint--; + this.player.setPosition(this.player.getX(), 259+(this.menuPoint*100)); + } + }else if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) && !this.keyPressed && this.animationStatus == 0) { + this.keyPressed = true; + switch (this.menuPoint) { + case 0: + if(Credits.getCredits() >= 5){ + PlayerStatus.ShootDamage += 5; + Credits.setCredits(Credits.getCredits() - 5); + } + break; + case 1: + if(Credits.getCredits() >= 10){ + PlayerStatus.HealthPoints += 10; + Credits.setCredits(Credits.getCredits() - 10); + } + break; + case 2: + this.animationStatus = 1; + break; + } + } + if(!Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !Keyboard.isKeyDown(KeyEvent.VK_UP) && !Keyboard.isKeyDown(KeyEvent.VK_ENTER)) { + this.keyPressed = false; + } + + 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; + } else this.animationStatus = 2; + } else if(this.animationStatus == 2) { + this.parent.setOverlay(new MainMenuScreen(this.parent)); + } + } + +}