Add GamePausedScreen.

This commit is contained in:
Jan Philipp Timme 2014-10-28 17:17:13 +01:00
parent 4717280ffc
commit 8228c6de20
5 changed files with 48 additions and 11 deletions

View File

@ -29,12 +29,12 @@ public class Main {
final GameFrame gameFrame = new GameFrame();
//Initialize SuperScreen and add to GameFrame, so we can call doPaint() on it.
SuperScreen superScreen = new SuperScreen(null);
gameFrame.setSuperScreen(superScreen);
final SuperScreen superScreen = new SuperScreen(null);
//Initialize the GameFrame properly within the AWT EventQueue
EventQueue.invokeLater(new Runnable() {
public void run() {
gameFrame.setSuperScreen(superScreen);
gameFrame.init();
gameFrame.draw(); //Draw nothing for the first time.
}

View File

@ -0,0 +1,34 @@
package de.teamteamteam.spacescooter.screen;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.utility.GameConfig;
public class GamePausedScreen extends Screen {
public GamePausedScreen(Screen parent) {
super(parent);
}
@Override
protected void paint(Graphics 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);
}
@Override
protected void update() {
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
this.parent.setOverlay(null);
}
}
}

View File

@ -41,7 +41,7 @@ public class GameScreen extends Screen {
i.next().update();
}
if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
this.parent.setOverlay(new MainMenuScreen(this.parent));
this.setOverlay(new GamePausedScreen(this));
}
}

View File

@ -7,7 +7,6 @@ import java.awt.Graphics;
import java.awt.event.KeyEvent;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.utility.GameConfig;
public class MainMenuScreen extends Screen {
@ -28,9 +27,9 @@ public class MainMenuScreen extends Screen {
@Override
public void update() {
for(Entity entity : this.entities) {
/*for(Entity entity : this.entities) {
entity.update();
}
}*/
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
this.parent.setOverlay(new GameScreen(this.parent));
}

View File

@ -9,13 +9,13 @@ public abstract class Screen {
public static Screen currentScreen;
protected Screen overlay;
public Screen overlay;
protected Screen parent;
protected LinkedList<Entity> entities;
public Screen(Screen parent) {
this.overlay = null;
this.setOverlay(null);
this.parent = parent;
this.entities = new LinkedList<Entity>();
}
@ -43,13 +43,17 @@ public abstract class Screen {
public void doUpdate() {
if(this.overlay != null) {
this.overlay.doUpdate();
return;
} else {
this.update();
}
this.update();
}
public void setOverlay(Screen screen) {
this.overlay = screen;
Screen.currentScreen = screen;
if(screen == null) {
Screen.currentScreen = this;
} else {
Screen.currentScreen = screen;
}
}
}