menü eingefügt
This commit is contained in:
parent
8d009c94a6
commit
b69bc9534f
Binary file not shown.
After Width: | Height: | Size: 463 B |
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
|
@ -28,7 +28,7 @@ public class StarBackground extends Background {
|
|||
private int offset = 0;
|
||||
|
||||
public void update() {
|
||||
this.offset -= 3;
|
||||
this.offset -= 2;
|
||||
//System.out.println(this.offset);
|
||||
if(Math.abs(this.offset) > StarBackground.img.getWidth()) {
|
||||
this.offset += StarBackground.img.getWidth();
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.io.IOException;
|
|||
import javax.imageio.ImageIO;
|
||||
|
||||
public class EnemyOne extends Enemy {
|
||||
|
||||
|
||||
private static BufferedImage img;
|
||||
|
||||
static {
|
||||
|
|
|
@ -11,6 +11,7 @@ import de.teamteamteam.spacescooter.utility.GameConfig;
|
|||
public class Player extends ShootingEntity {
|
||||
|
||||
private static BufferedImage img;
|
||||
private boolean canMove = true;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
@ -27,28 +28,34 @@ public class Player extends ShootingEntity {
|
|||
this.setShootDelay(40);
|
||||
this.setShootSpawn(50, 16);
|
||||
this.setShootDirection(Shot.RIGHT);
|
||||
this.setShootSpeed(2);
|
||||
this.setShootSpeed(4);
|
||||
this.setHealthPoints(100);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
super.update();
|
||||
int off = 3;
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.y > 0) {
|
||||
this.y -= off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.y < (GameConfig.windowHeight - Player.img.getHeight())) {
|
||||
this.y += off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_LEFT) && this.x > 0) {
|
||||
this.x -= off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_RIGHT) && this.x < (GameConfig.windowWidth - Player.img.getWidth())) {
|
||||
this.x += off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
|
||||
this.shoot();
|
||||
if(canMove){
|
||||
super.update();
|
||||
int off = 3;
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.y > 0) {
|
||||
this.y -= off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.y < (GameConfig.windowHeight - Player.img.getHeight())) {
|
||||
this.y += off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_LEFT) && this.x > 0) {
|
||||
this.x -= off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_RIGHT) && this.x < (GameConfig.windowWidth - Player.img.getWidth())) {
|
||||
this.x += off;
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
|
||||
this.shoot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCanMove(boolean canMove){
|
||||
this.canMove = canMove;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -33,7 +33,7 @@ public class GameFrame extends JFrame {
|
|||
public void init() {
|
||||
this.setTitle("Unser schöner Titel");
|
||||
this.setSize(GameConfig.windowWidth, GameConfig.windowHeight);
|
||||
this.setResizable(false);
|
||||
// this.setResizable(false);
|
||||
this.setUndecorated(false);
|
||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
|
||||
|
|
|
@ -4,30 +4,105 @@ 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.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
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
|
||||
protected void paint(Graphics2D g) {
|
||||
g.setColor(new Color(0,0,120));
|
||||
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight);
|
||||
g.setColor(new Color(255,255,255));
|
||||
g.setFont(new Font("Monospace", 0, 50));
|
||||
g.drawString("Pause Menu. LOL", 100, 100);
|
||||
g.drawString("Press space to continue!", 100, 400);
|
||||
g.drawImage(img, 0, 0, null);
|
||||
LinkedList<Entity> list = this.getEntities();
|
||||
Iterator<Entity> i = list.iterator();
|
||||
while (i.hasNext()) {
|
||||
i.next().paint(g);
|
||||
}
|
||||
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
|
||||
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)) {
|
||||
this.parent.setOverlay(null);
|
||||
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);
|
||||
break;
|
||||
case 1:
|
||||
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,36 +5,114 @@ import java.awt.Font;
|
|||
import java.awt.Graphics2D;
|
||||
|
||||
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.entity.Entity;
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.gui.Button;
|
||||
import de.teamteamteam.spacescooter.utility.GameConfig;
|
||||
|
||||
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) {
|
||||
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
|
||||
public void paint(Graphics2D g) {
|
||||
g.setColor(new Color(0,0,120));
|
||||
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight);
|
||||
g.setColor(new Color(255,255,255));
|
||||
g.setFont(new Font("Monospace", 0, 50));
|
||||
g.drawString("Main Menu. LOL", 100, 100);
|
||||
g.drawString("Press space to play!", 100, 400);
|
||||
LinkedList<Entity> list = this.getEntities();
|
||||
Iterator<Entity> i = list.iterator();
|
||||
while (i.hasNext()) {
|
||||
i.next().paint(g);
|
||||
}
|
||||
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
|
||||
public void update() {
|
||||
/*for(Entity entity : this.entities) {
|
||||
entity.update();
|
||||
}*/
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
|
||||
this.parent.setOverlay(new GameScreen(this.parent));
|
||||
LinkedList<Entity> list = this.getEntities();
|
||||
Iterator<Entity> i = list.iterator();
|
||||
while (i.hasNext()) {
|
||||
i.next().update();
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
|
||||
System.exit(0);
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue