Erster shop screen (erreichbar über Hilfe Button im hauptmenu) und credits eingefügt

llease enter the commit message for your changes. Lines starting
This commit is contained in:
Sosch 2014-11-11 12:11:40 +01:00
parent 81dc747aba
commit 223612de32
6 changed files with 136 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import de.teamteamteam.spacescooter.entity.explosion.Explosion;
import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.shot.Shot;
import de.teamteamteam.spacescooter.entity.spi.Collidable; import de.teamteamteam.spacescooter.entity.spi.Collidable;
import de.teamteamteam.spacescooter.entity.spi.Hittable; import de.teamteamteam.spacescooter.entity.spi.Hittable;
import de.teamteamteam.spacescooter.gui.Credits;
import de.teamteamteam.spacescooter.utility.GameConfig; 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 //Set the correct values for gui indicators
this.healthPoints = 0; this.healthPoints = 0;
this.shieldPoints = 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"); if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP");
this.die(); this.die();
} }

View File

@ -18,13 +18,13 @@ public class Player extends ShootingEntity implements KeyboardListener {
super(x, y); super(x, y);
this.setImage("images/ship.png"); this.setImage("images/ship.png");
this.setPrimaryShotImage("images/shots/laser_blue.png"); this.setPrimaryShotImage("images/shots/laser_blue.png");
this.setShootDamage(5); this.setShootDamage(PlayerStatus.ShootDamage);
this.setShootDelay(20); this.setShootDelay(20);
this.setShootSpawn(50, 16); this.setShootSpawn(50, 16);
this.setShootDirection(Shot.RIGHT); this.setShootDirection(Shot.RIGHT);
this.setShootSpeed(10); this.setShootSpeed(10);
this.setCollisionDamage(10); this.setCollisionDamage(10);
this.setHealthPoints(100); this.setHealthPoints(PlayerStatus.HealthPoints);
this.registerOnKeyboard(Keyboard.getInstance()); this.registerOnKeyboard(Keyboard.getInstance());
} }

View File

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

View File

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

View File

@ -101,6 +101,7 @@ public class MainMenuScreen extends Screen {
this.parent.setOverlay(new GameScreen(this.parent)); this.parent.setOverlay(new GameScreen(this.parent));
break; break;
case 1: case 1:
this.parent.setOverlay(new ShopScreen(this.parent));
break; break;
case 2: case 2:
break; break;

View File

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