menü eingefügt

This commit is contained in:
Sosch 2014-10-31 09:07:42 +01:00
parent 8d009c94a6
commit b69bc9534f
9 changed files with 234 additions and 40 deletions

BIN
res/images/button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -28,7 +28,7 @@ public class StarBackground extends Background {
private int offset = 0; private int offset = 0;
public void update() { public void update() {
this.offset -= 3; this.offset -= 2;
//System.out.println(this.offset); //System.out.println(this.offset);
if(Math.abs(this.offset) > StarBackground.img.getWidth()) { if(Math.abs(this.offset) > StarBackground.img.getWidth()) {
this.offset += StarBackground.img.getWidth(); this.offset += StarBackground.img.getWidth();

View File

@ -11,6 +11,7 @@ import de.teamteamteam.spacescooter.utility.GameConfig;
public class Player extends ShootingEntity { public class Player extends ShootingEntity {
private static BufferedImage img; private static BufferedImage img;
private boolean canMove = true;
static { static {
try { try {
@ -27,11 +28,12 @@ public class Player extends ShootingEntity {
this.setShootDelay(40); this.setShootDelay(40);
this.setShootSpawn(50, 16); this.setShootSpawn(50, 16);
this.setShootDirection(Shot.RIGHT); this.setShootDirection(Shot.RIGHT);
this.setShootSpeed(2); this.setShootSpeed(4);
this.setHealthPoints(100); this.setHealthPoints(100);
} }
public void update() { public void update() {
if(canMove){
super.update(); super.update();
int off = 3; int off = 3;
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.y > 0) { if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.y > 0) {
@ -50,5 +52,10 @@ public class Player extends ShootingEntity {
this.shoot(); this.shoot();
} }
} }
}
public void setCanMove(boolean canMove){
this.canMove = canMove;
}
} }

View File

@ -0,0 +1,34 @@
package de.teamteamteam.spacescooter.gui;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.Player;
public class Button extends Entity{
private static BufferedImage img;
static{
try {
img = ImageIO.read(Player.class.getClassLoader().getResourceAsStream("images/button.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Button(int x, int y) {
super(x, y);
this.setImage(img);
}
@Override
public void update() {
}
}

View File

@ -33,7 +33,7 @@ public class GameFrame extends JFrame {
public void init() { public void init() {
this.setTitle("Unser schöner Titel"); this.setTitle("Unser schöner Titel");
this.setSize(GameConfig.windowWidth, GameConfig.windowHeight); this.setSize(GameConfig.windowWidth, GameConfig.windowHeight);
this.setResizable(false); // this.setResizable(false);
this.setUndecorated(false); this.setUndecorated(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setDefaultCloseOperation(EXIT_ON_CLOSE);

View File

@ -4,30 +4,105 @@ 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.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import javax.imageio.ImageIO;
import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.gui.Button;
import de.teamteamteam.spacescooter.utility.GameConfig; import de.teamteamteam.spacescooter.utility.GameConfig;
public class GamePausedScreen extends Screen { public class GamePausedScreen extends Screen {
private static BufferedImage img;
private Player player;
private float playerMoveSpeed = 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
static{
try {
img = ImageIO.read(Player.class.getClassLoader().getResourceAsStream("images/pausebackground.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public GamePausedScreen(Screen parent) { public GamePausedScreen(Screen parent) {
super(parent); super(parent);
this.entities.add(new Button(GameConfig.windowWidth/2-125, 300));
this.entities.add(new Button(GameConfig.windowWidth/2-125, 400));
player = new Player(GameConfig.windowWidth/2-170, 309);
player.setCanMove(false);
this.entities.add(player);
} }
@Override @Override
protected void paint(Graphics2D g) { protected void paint(Graphics2D g) {
g.setColor(new Color(0,0,120)); g.drawImage(img, 0, 0, null);
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight); LinkedList<Entity> list = this.getEntities();
g.setColor(new Color(255,255,255)); Iterator<Entity> i = list.iterator();
g.setFont(new Font("Monospace", 0, 50)); while (i.hasNext()) {
g.drawString("Pause Menu. LOL", 100, 100); i.next().paint(g);
g.drawString("Press space to continue!", 100, 400); }
g.setFont(new Font("Monospace", 0, 100));
g.setColor(new Color(75 + colorValue, 175 + colorValue, 175 + colorValue));
g.drawString("Pause", GameConfig.windowWidth/2-145, 200);
g.setFont(new Font("Monospace", 0, 20));
g.setColor(new Color(0, 0, 0));
g.drawString("Weiter", GameConfig.windowWidth/2-30, 332);
g.drawString("Hauptmenü", GameConfig.windowWidth/2-50, 432);
} }
@Override @Override
protected void update() { protected void update() {
LinkedList<Entity> list = this.getEntities();
Iterator<Entity> i = list.iterator();
while (i.hasNext()) {
i.next().update();
}
if(colorValueIncrease){
colorValue += 2;
if(colorValue > 70) colorValueIncrease = false;
}else{
colorValue -= 2;
if(colorValue < -70) colorValueIncrease = true;
}
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN)){
menuPoint = 1;
player.setPosition(player.getX(), 409);
}
if(Keyboard.isKeyDown(KeyEvent.VK_UP)){
menuPoint = 0;
player.setPosition(player.getX(), 309);
}
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
animationStatus = 1;
}
if(animationStatus == 1){
if(player.getX() <= GameConfig.windowWidth){
player.setPosition(player.getX() + (int)playerMoveSpeed, player.getY());
playerMoveSpeed += 0.1;
}else animationStatus = 2;
}else if(animationStatus == 2){
switch (menuPoint) {
case 0:
this.parent.setOverlay(null); this.parent.setOverlay(null);
break;
case 1:
this.parent.setOverlay(new MainMenuScreen(this.parent));
break;
}
} }
} }

View File

@ -5,36 +5,114 @@ import java.awt.Font;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.Iterator;
import java.util.LinkedList;
import de.teamteamteam.spacescooter.background.StarBackground;
import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.gui.Button;
import de.teamteamteam.spacescooter.utility.GameConfig; import de.teamteamteam.spacescooter.utility.GameConfig;
public class MainMenuScreen extends Screen { public class MainMenuScreen extends Screen {
private Player player;
private float playerMoveSpeed = 0;
private int colorValue = 0;
private boolean colorValueIncrease = true;
private int menuPoint = 0;
private boolean keyPressed = false;
private int animationStatus = 0; //0 = Animation noch nicht gestartet, 1 = Animation läuft, 2 = Animation beendet
public MainMenuScreen(Screen parent) { public MainMenuScreen(Screen parent) {
super(parent); super(parent);
this.entities.add(new StarBackground(0, 0));
this.entities.add(new Button(GameConfig.windowWidth/2-125, 200));
this.entities.add(new Button(GameConfig.windowWidth/2-125, 275));
this.entities.add(new Button(GameConfig.windowWidth/2-125, 350));
this.entities.add(new Button(GameConfig.windowWidth/2-125, 425));
this.entities.add(new Button(GameConfig.windowWidth/2-125, 500));
player = new Player(GameConfig.windowWidth/2-170, 209);
player.setCanMove(false);
this.entities.add(player);
} }
@Override @Override
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
g.setColor(new Color(0,0,120)); LinkedList<Entity> list = this.getEntities();
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight); Iterator<Entity> i = list.iterator();
g.setColor(new Color(255,255,255)); while (i.hasNext()) {
g.setFont(new Font("Monospace", 0, 50)); i.next().paint(g);
g.drawString("Main Menu. LOL", 100, 100); }
g.drawString("Press space to play!", 100, 400); g.setFont(new Font("Monospace", 0, 70));
g.setColor(new Color(75 + colorValue, 175 + colorValue, 175 + colorValue));
g.drawString("SpaceScooter", GameConfig.windowWidth/2-225, 125);
g.setFont(new Font("Monospace", 0, 20));
g.setColor(new Color(0, 0, 0));
g.drawString("Neues Spiel", GameConfig.windowWidth/2-50, 232);
g.drawString("Hilfe", GameConfig.windowWidth/2-20, 308);
g.drawString("Highscore", GameConfig.windowWidth/2-45, 382);
g.drawString("Credits", GameConfig.windowWidth/2-33, 458);
g.drawString("Beenden", GameConfig.windowWidth/2-38, 532);
} }
@Override @Override
public void update() { public void update() {
/*for(Entity entity : this.entities) { LinkedList<Entity> list = this.getEntities();
entity.update(); Iterator<Entity> i = list.iterator();
}*/ while (i.hasNext()) {
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { i.next().update();
this.parent.setOverlay(new GameScreen(this.parent));
} }
if(Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
if(colorValueIncrease){
colorValue += 2;
if(colorValue > 70) colorValueIncrease = false;
}else{
colorValue -= 2;
if(colorValue < -70) colorValueIncrease = true;
}
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !keyPressed && animationStatus == 0){
keyPressed = true;
if(menuPoint<4){
menuPoint++;
player.setPosition(player.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));
}
}else if(!Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !Keyboard.isKeyDown(KeyEvent.VK_UP)){
keyPressed = false;
}
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
animationStatus = 1;
}
if(animationStatus == 1){
if(player.getX() <= GameConfig.windowWidth){
player.setPosition(player.getX() + (int)playerMoveSpeed, player.getY());
playerMoveSpeed += 0.1;
}else animationStatus = 2;
}else if(animationStatus == 2){
switch (menuPoint) {
case 0:
this.parent.setOverlay(new GameScreen(this.parent));
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
System.exit(0); System.exit(0);
break;
}
} }
} }