From 82e91f3b85917f456214c121daa97ba65c7cce2a Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Thu, 5 Mar 2009 09:35:11 -0500 Subject: Engine: Started Escape Menu Refs #15 --- .../fourisland/fourpuzzle/PuzzleApplication.java | 10 +-- .../fourisland/fourpuzzle/database/Vocabulary.java | 8 ++- .../fourpuzzle/gamestate/GameOverGameState.java | 6 +- .../fourpuzzle/gamestate/TitleScreenGameState.java | 8 ++- .../gamestate/mapview/MapViewGameState.java | 15 +++- .../fourpuzzle/gamestate/menu/EscapeMenuState.java | 21 ++++++ .../fourpuzzle/gamestate/menu/MenuEMS.java | 83 ++++++++++++++++++++++ .../fourpuzzle/gamestate/menu/MenuGameState.java | 67 +++++++++++++++++ .../fourpuzzle/gamestate/menu/SaveEMS.java | 49 +++++++++++++ src/com/fourisland/fourpuzzle/util/Interval.java | 7 ++ src/com/fourisland/fourpuzzle/util/PauseTimer.java | 7 ++ .../fourisland/fourpuzzle/window/ChoiceWindow.java | 13 ++++ .../fourpuzzle/window/InputableChoiceWindow.java | 61 ++++++++++++++++ 13 files changed, 345 insertions(+), 10 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java create mode 100644 src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index 13758cb..16de273 100755 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java @@ -92,10 +92,10 @@ public class PuzzleApplication extends Application { { debugSpeed = true; } - } else { - KeyboardInput.getKey().keyInput(e); + } else { + KeyboardInput.getKey().keyInput(e); + } } - } @Override public void keyReleased(KeyEvent e) @@ -132,7 +132,7 @@ public class PuzzleApplication extends Application { Interval in = Interval.createTickInterval(1); while (true) { - if ((debugSpeed || in.isElapsed()) && !gameSleep) + if (in.isElapsed() && !gameSleep) { if (!Display.isTransitionRunning()) { @@ -165,7 +165,7 @@ public class PuzzleApplication extends Application { if ((ex instanceof Exception) && !(ex instanceof RuntimeException)) { return; - } + } JFrame errorBox = new JFrame(ex.getClass().getSimpleName()); JLabel text = new JLabel(); diff --git a/src/com/fourisland/fourpuzzle/database/Vocabulary.java b/src/com/fourisland/fourpuzzle/database/Vocabulary.java index e79f3c0..58b13ea 100644 --- a/src/com/fourisland/fourpuzzle/database/Vocabulary.java +++ b/src/com/fourisland/fourpuzzle/database/Vocabulary.java @@ -13,7 +13,13 @@ public enum Vocabulary { Title("Untitled Game"), NewGame("New Game"), LoadGame("Load Game"), - EndGame("End Game"); + EndGame("End Game"), + + EscapeMenuItems("Items"), + EscapeMenuEquipment("Equipment"), + EscapeMenuMagic("Magic"), + EscapeMenuSave("Save"), + EscapeMenuQuit("Quit"); private String value; private Vocabulary(String value) diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index 692554e..ed379cc 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java @@ -38,7 +38,11 @@ public class GameOverGameState implements GameState { { Game.setSaveFile(new SaveFile()); - Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true); + try { + Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index cedf5a6..6f12d02 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -55,8 +55,12 @@ public class TitleScreenGameState implements GameState { if (choices.getSelected().equals(Database.getVocab(Vocabulary.NewGame))) { Game.setSaveFile(new SaveFile()); - - Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true); + + try { + Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame))) { // Do nothing, yet diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index ccb1829..7635839 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -15,6 +15,7 @@ import com.fourisland.fourpuzzle.KeyInput; import com.fourisland.fourpuzzle.Layer; import com.fourisland.fourpuzzle.PuzzleApplication; import com.fourisland.fourpuzzle.database.Database; +import com.fourisland.fourpuzzle.database.Transitions; import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime; import com.fourisland.fourpuzzle.gamestate.mapview.event.EventHandler; import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; @@ -23,10 +24,13 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.SpecialEvent; import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; +import com.fourisland.fourpuzzle.gamestate.menu.MenuGameState; import com.fourisland.fourpuzzle.util.Functions; import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -141,7 +145,16 @@ public class MapViewGameState implements GameState { } } } - } + } + + if (key.getKey() == KeyEvent.VK_ESCAPE) + { + try { + Display.transition(Database.getTransition(Transitions.Generic), new MenuGameState(this), true); + } catch (InterruptedException ex) { + Logger.getLogger(MapViewGameState.class.getName()).log(Level.SEVERE, null, ex); + } + } } if (EventHandler.isRunningEvent()) diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java b/src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java new file mode 100644 index 0000000..d316a8d --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java @@ -0,0 +1,21 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.menu; + +import com.fourisland.fourpuzzle.util.Renderable; +import com.fourisland.fourpuzzle.util.Inputable; + +/** + * + * @author hatkirby + */ +public interface EscapeMenuState extends Renderable, Inputable { + + public void initalize(MenuGameState mgs); + public void deinitalize(); + public void tick(); + +} diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java new file mode 100644 index 0000000..4fad509 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java @@ -0,0 +1,83 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.menu; + +import com.fourisland.fourpuzzle.Display; +import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.KeyInput; +import com.fourisland.fourpuzzle.KeyboardInput; +import com.fourisland.fourpuzzle.database.Database; +import com.fourisland.fourpuzzle.database.Transitions; +import com.fourisland.fourpuzzle.database.Vocabulary; +import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; +import com.fourisland.fourpuzzle.window.ChoiceWindow; +import com.fourisland.fourpuzzle.window.InputableChoiceWindow; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.event.KeyEvent; +import java.util.Arrays; + +/** + * + * @author hatkirby + */ +public class MenuEMS implements EscapeMenuState { + + MenuGameState parent; + InputableChoiceWindow cw; + + public void initalize(MenuGameState mgs) + { + parent = mgs; + cw = new InputableChoiceWindow(Arrays.asList(Database.getVocab(Vocabulary.EscapeMenuItems), Database.getVocab(Vocabulary.EscapeMenuEquipment), Database.getVocab(Vocabulary.EscapeMenuMagic), Database.getVocab(Vocabulary.EscapeMenuSave), Database.getVocab(Vocabulary.EscapeMenuQuit)), false, ChoiceWindow.ChoiceWindowLocation.AbsoluteTopLeft); + Display.registerRenderable(cw); + KeyboardInput.registerInputable(cw); + } + + public void deinitalize() + { + Display.unregisterRenderable(cw); + KeyboardInput.unregisterInputable(cw); + } + + public void tick() + { + if (cw.hasInput()) + { + String value = cw.getSelected(); + if (value.equals(Database.getVocab(Vocabulary.EscapeMenuQuit))) + { + try { + Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } else if (value.equals(Database.getVocab(Vocabulary.EscapeMenuSave))) + { + parent.setEMS(new SaveEMS()); + } + } + } + + public void render(Graphics2D g) + { + g.setBackground(Color.BLACK); + g.clearRect(0, 0, Game.WIDTH, Game.HEIGHT); + } + + public void processInput(KeyInput key) + { + if (key.getKey() == KeyEvent.VK_ESCAPE) + { + try { + Display.transition(Database.getTransition(Transitions.Generic), parent.mapView, true); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } + } + +} diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java new file mode 100644 index 0000000..884195c --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java @@ -0,0 +1,67 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.menu; + +import com.fourisland.fourpuzzle.Audio; +import com.fourisland.fourpuzzle.gamestate.*; +import com.fourisland.fourpuzzle.KeyInput; +import com.fourisland.fourpuzzle.database.Database; +import com.fourisland.fourpuzzle.database.Sound; +import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; +import java.awt.Graphics2D; + +/** + * + * @author hatkirby + */ +public class MenuGameState implements GameState { + + EscapeMenuState ems; + MapViewGameState mapView; + + public MenuGameState(MapViewGameState mapView) + { + this.mapView = mapView; + } + + public void initalize() + { + Audio.playSound(Database.getSound(Sound.Selection)); + setEMS(new MenuEMS()); + } + + public void deinitalize() + { + this.ems.deinitalize(); + } + + public void doGameCycle() + { + ems.tick(); + } + + public void render(Graphics2D g) + { + ems.render(g); + } + + public void processInput(KeyInput key) + { + ems.processInput(key); + } + + public void setEMS(EscapeMenuState ems) + { + if (this.ems != null) + { + this.ems.deinitalize(); + } + + this.ems = ems; + this.ems.initalize(this); + } + +} diff --git a/src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java b/src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java new file mode 100644 index 0000000..02e0f41 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java @@ -0,0 +1,49 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.menu; + +import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.KeyInput; +import com.fourisland.fourpuzzle.window.Window; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public class SaveEMS implements EscapeMenuState { + + MenuGameState parent; + BufferedImage cacheBase; + + public void initalize(MenuGameState mgs) + { + parent = mgs; + cacheBase = Window.Default.getImage(Game.WIDTH-Window.Default.getFullWidth(0), Window.Default.getFullHeight(Game.HEIGHT)/3+Window.Default.getFullHeight(0)); + } + + public void deinitalize() + { + //throw new UnsupportedOperationException("Not supported yet."); + } + + public void tick() + { + //throw new UnsupportedOperationException("Not supported yet."); + } + + public void render(Graphics2D g) + { + g.drawImage(cacheBase, 0, 0, null); + } + + public void processInput(KeyInput key) + { + //throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/src/com/fourisland/fourpuzzle/util/Interval.java b/src/com/fourisland/fourpuzzle/util/Interval.java index 27d9e6a..044c50b 100755 --- a/src/com/fourisland/fourpuzzle/util/Interval.java +++ b/src/com/fourisland/fourpuzzle/util/Interval.java @@ -6,6 +6,8 @@ package com.fourisland.fourpuzzle.util; import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.KeyboardInput; +import com.fourisland.fourpuzzle.PuzzleApplication; /** * @@ -32,6 +34,11 @@ public class Interval { private long last = System.nanoTime(); public boolean isElapsed() { + if (PuzzleApplication.debugSpeed) + { + return true; + } + if (last+wait < System.nanoTime()) { last = System.nanoTime(); diff --git a/src/com/fourisland/fourpuzzle/util/PauseTimer.java b/src/com/fourisland/fourpuzzle/util/PauseTimer.java index 8ae7330..7d66d1a 100644 --- a/src/com/fourisland/fourpuzzle/util/PauseTimer.java +++ b/src/com/fourisland/fourpuzzle/util/PauseTimer.java @@ -5,6 +5,8 @@ package com.fourisland.fourpuzzle.util; +import com.fourisland.fourpuzzle.PuzzleApplication; + /** * * @author hatkirby @@ -20,6 +22,11 @@ public class PauseTimer { Interval in = Interval.createTickInterval(1); public boolean isElapsed() { + if (PuzzleApplication.debugSpeed) + { + return true; + } + if (in.isElapsed()) { if (ticks == 0) diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index ef57226..4926a6d 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java @@ -124,6 +124,19 @@ public class ChoiceWindow implements Renderable { public static enum ChoiceWindowLocation { + AbsoluteTopLeft + { + public int getX(int width) + { + return 0; + } + + @Override + public int getY(int height) + { + return 0; + } + }, BottomLeft { public int getX(int width) diff --git a/src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java new file mode 100644 index 0000000..02bc737 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java @@ -0,0 +1,61 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.window; + +import com.fourisland.fourpuzzle.KeyInput; +import java.util.List; +import com.fourisland.fourpuzzle.util.Inputable; +import com.fourisland.fourpuzzle.util.PauseTimer; +import java.awt.event.KeyEvent; + +/** + * + * @author hatkirby + */ +public class InputableChoiceWindow extends ChoiceWindow implements Inputable { + + Boolean hasInput = false; + PauseTimer pt = new PauseTimer(0); + + public InputableChoiceWindow(List choices, boolean center, ChoiceWindowLocation cwl) + { + super(choices, center, cwl); + } + + public void processInput(KeyInput key) + { + if (key.getKey() == KeyEvent.VK_UP) + { + if (pt.isElapsed()) + { + moveUp(); + pt.setTimer(1); + } + } else if (key.getKey() == KeyEvent.VK_DOWN) + { + if (pt.isElapsed()) + { + moveDown(); + pt.setTimer(1); + } + } else if (key.isActionDown()) + { + synchronized (hasInput) + { + hasInput = true; + } + } + } + + public boolean hasInput() + { + synchronized (hasInput) + { + return hasInput; + } + } + +} -- cgit 1.4.1