summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/PuzzleApplication.java10
-rw-r--r--src/com/fourisland/fourpuzzle/database/Vocabulary.java8
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java6
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java8
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java15
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/menu/EscapeMenuState.java21
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/menu/MenuEMS.java83
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/menu/MenuGameState.java67
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/menu/SaveEMS.java49
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/util/Interval.java7
-rw-r--r--src/com/fourisland/fourpuzzle/util/PauseTimer.java7
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/window/ChoiceWindow.java13
-rw-r--r--src/com/fourisland/fourpuzzle/window/InputableChoiceWindow.java61
13 files changed, 345 insertions, 10 deletions
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 {
92 { 92 {
93 debugSpeed = true; 93 debugSpeed = true;
94 } 94 }
95 } else { 95 } else {
96 KeyboardInput.getKey().keyInput(e); 96 KeyboardInput.getKey().keyInput(e);
97 }
97 } 98 }
98 }
99 99
100 @Override 100 @Override
101 public void keyReleased(KeyEvent e) 101 public void keyReleased(KeyEvent e)
@@ -132,7 +132,7 @@ public class PuzzleApplication extends Application {
132 Interval in = Interval.createTickInterval(1); 132 Interval in = Interval.createTickInterval(1);
133 while (true) 133 while (true)
134 { 134 {
135 if ((debugSpeed || in.isElapsed()) && !gameSleep) 135 if (in.isElapsed() && !gameSleep)
136 { 136 {
137 if (!Display.isTransitionRunning()) 137 if (!Display.isTransitionRunning())
138 { 138 {
@@ -165,7 +165,7 @@ public class PuzzleApplication extends Application {
165 if ((ex instanceof Exception) && !(ex instanceof RuntimeException)) 165 if ((ex instanceof Exception) && !(ex instanceof RuntimeException))
166 { 166 {
167 return; 167 return;
168 } 168 }
169 169
170 JFrame errorBox = new JFrame(ex.getClass().getSimpleName()); 170 JFrame errorBox = new JFrame(ex.getClass().getSimpleName());
171 JLabel text = new JLabel(); 171 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 {
13 Title("Untitled Game"), 13 Title("Untitled Game"),
14 NewGame("New Game"), 14 NewGame("New Game"),
15 LoadGame("Load Game"), 15 LoadGame("Load Game"),
16 EndGame("End Game"); 16 EndGame("End Game"),
17
18 EscapeMenuItems("Items"),
19 EscapeMenuEquipment("Equipment"),
20 EscapeMenuMagic("Magic"),
21 EscapeMenuSave("Save"),
22 EscapeMenuQuit("Quit");
17 23
18 private String value; 24 private String value;
19 private Vocabulary(String value) 25 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 {
38 { 38 {
39 Game.setSaveFile(new SaveFile()); 39 Game.setSaveFile(new SaveFile());
40 40
41 Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true); 41 try {
42 Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true);
43 } catch (InterruptedException ex) {
44 Thread.currentThread().interrupt();
45 }
42 } 46 }
43 } 47 }
44 48
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 {
55 if (choices.getSelected().equals(Database.getVocab(Vocabulary.NewGame))) 55 if (choices.getSelected().equals(Database.getVocab(Vocabulary.NewGame)))
56 { 56 {
57 Game.setSaveFile(new SaveFile()); 57 Game.setSaveFile(new SaveFile());
58 58
59 Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true); 59 try {
60 Display.transition(Database.getTransition(Transitions.Generic), new MapViewGameState("TestMap", 1, 2), true);
61 } catch (InterruptedException ex) {
62 Thread.currentThread().interrupt();
63 }
60 } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame))) 64 } else if (choices.getSelected().equals(Database.getVocab(Vocabulary.LoadGame)))
61 { 65 {
62 // Do nothing, yet 66 // 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;
15import com.fourisland.fourpuzzle.Layer; 15import com.fourisland.fourpuzzle.Layer;
16import com.fourisland.fourpuzzle.PuzzleApplication; 16import com.fourisland.fourpuzzle.PuzzleApplication;
17import com.fourisland.fourpuzzle.database.Database; 17import com.fourisland.fourpuzzle.database.Database;
18import com.fourisland.fourpuzzle.database.Transitions;
18import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime; 19import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime;
19import com.fourisland.fourpuzzle.gamestate.mapview.event.EventHandler; 20import com.fourisland.fourpuzzle.gamestate.mapview.event.EventHandler;
20import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; 21import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList;
@@ -23,10 +24,13 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.SpecialEvent;
23import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; 24import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
24import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; 25import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint;
25import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; 26import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint;
27import com.fourisland.fourpuzzle.gamestate.menu.MenuGameState;
26import com.fourisland.fourpuzzle.util.Functions; 28import com.fourisland.fourpuzzle.util.Functions;
27import java.awt.Graphics2D; 29import java.awt.Graphics2D;
28import java.awt.event.KeyEvent; 30import java.awt.event.KeyEvent;
29import java.awt.image.BufferedImage; 31import java.awt.image.BufferedImage;
32import java.util.logging.Level;
33import java.util.logging.Logger;
30 34
31/** 35/**
32 * 36 *
@@ -141,7 +145,16 @@ public class MapViewGameState implements GameState {
141 } 145 }
142 } 146 }
143 } 147 }
144 } 148 }
149
150 if (key.getKey() == KeyEvent.VK_ESCAPE)
151 {
152 try {
153 Display.transition(Database.getTransition(Transitions.Generic), new MenuGameState(this), true);
154 } catch (InterruptedException ex) {
155 Logger.getLogger(MapViewGameState.class.getName()).log(Level.SEVERE, null, ex);
156 }
157 }
145 } 158 }
146 159
147 if (EventHandler.isRunningEvent()) 160 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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.menu;
7
8import com.fourisland.fourpuzzle.util.Renderable;
9import com.fourisland.fourpuzzle.util.Inputable;
10
11/**
12 *
13 * @author hatkirby
14 */
15public interface EscapeMenuState extends Renderable, Inputable {
16
17 public void initalize(MenuGameState mgs);
18 public void deinitalize();
19 public void tick();
20
21}
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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.menu;
7
8import com.fourisland.fourpuzzle.Display;
9import com.fourisland.fourpuzzle.Game;
10import com.fourisland.fourpuzzle.KeyInput;
11import com.fourisland.fourpuzzle.KeyboardInput;
12import com.fourisland.fourpuzzle.database.Database;
13import com.fourisland.fourpuzzle.database.Transitions;
14import com.fourisland.fourpuzzle.database.Vocabulary;
15import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState;
16import com.fourisland.fourpuzzle.window.ChoiceWindow;
17import com.fourisland.fourpuzzle.window.InputableChoiceWindow;
18import java.awt.Color;
19import java.awt.Graphics2D;
20import java.awt.event.KeyEvent;
21import java.util.Arrays;
22
23/**
24 *
25 * @author hatkirby
26 */
27public class MenuEMS implements EscapeMenuState {
28
29 MenuGameState parent;
30 InputableChoiceWindow cw;
31
32 public void initalize(MenuGameState mgs)
33 {
34 parent = mgs;
35 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);
36 Display.registerRenderable(cw);
37 KeyboardInput.registerInputable(cw);
38 }
39
40 public void deinitalize()
41 {
42 Display.unregisterRenderable(cw);
43 KeyboardInput.unregisterInputable(cw);
44 }
45
46 public void tick()
47 {
48 if (cw.hasInput())
49 {
50 String value = cw.getSelected();
51 if (value.equals(Database.getVocab(Vocabulary.EscapeMenuQuit)))
52 {
53 try {
54 Display.transition(Database.getTransition(Transitions.Generic), new TitleScreenGameState(), true);
55 } catch (InterruptedException ex) {
56 Thread.currentThread().interrupt();
57 }
58 } else if (value.equals(Database.getVocab(Vocabulary.EscapeMenuSave)))
59 {
60 parent.setEMS(new SaveEMS());
61 }
62 }
63 }
64
65 public void render(Graphics2D g)
66 {
67 g.setBackground(Color.BLACK);
68 g.clearRect(0, 0, Game.WIDTH, Game.HEIGHT);
69 }
70
71 public void processInput(KeyInput key)
72 {
73 if (key.getKey() == KeyEvent.VK_ESCAPE)
74 {
75 try {
76 Display.transition(Database.getTransition(Transitions.Generic), parent.mapView, true);
77 } catch (InterruptedException ex) {
78 Thread.currentThread().interrupt();
79 }
80 }
81 }
82
83}
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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.menu;
7
8import com.fourisland.fourpuzzle.Audio;
9import com.fourisland.fourpuzzle.gamestate.*;
10import com.fourisland.fourpuzzle.KeyInput;
11import com.fourisland.fourpuzzle.database.Database;
12import com.fourisland.fourpuzzle.database.Sound;
13import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
14import java.awt.Graphics2D;
15
16/**
17 *
18 * @author hatkirby
19 */
20public class MenuGameState implements GameState {
21
22 EscapeMenuState ems;
23 MapViewGameState mapView;
24
25 public MenuGameState(MapViewGameState mapView)
26 {
27 this.mapView = mapView;
28 }
29
30 public void initalize()
31 {
32 Audio.playSound(Database.getSound(Sound.Selection));
33 setEMS(new MenuEMS());
34 }
35
36 public void deinitalize()
37 {
38 this.ems.deinitalize();
39 }
40
41 public void doGameCycle()
42 {
43 ems.tick();
44 }
45
46 public void render(Graphics2D g)
47 {
48 ems.render(g);
49 }
50
51 public void processInput(KeyInput key)
52 {
53 ems.processInput(key);
54 }
55
56 public void setEMS(EscapeMenuState ems)
57 {
58 if (this.ems != null)
59 {
60 this.ems.deinitalize();
61 }
62
63 this.ems = ems;
64 this.ems.initalize(this);
65 }
66
67}
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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.menu;
7
8import com.fourisland.fourpuzzle.Game;
9import com.fourisland.fourpuzzle.KeyInput;
10import com.fourisland.fourpuzzle.window.Window;
11import java.awt.Graphics2D;
12import java.awt.image.BufferedImage;
13
14/**
15 *
16 * @author hatkirby
17 */
18public class SaveEMS implements EscapeMenuState {
19
20 MenuGameState parent;
21 BufferedImage cacheBase;
22
23 public void initalize(MenuGameState mgs)
24 {
25 parent = mgs;
26 cacheBase = Window.Default.getImage(Game.WIDTH-Window.Default.getFullWidth(0), Window.Default.getFullHeight(Game.HEIGHT)/3+Window.Default.getFullHeight(0));
27 }
28
29 public void deinitalize()
30 {
31 //throw new UnsupportedOperationException("Not supported yet.");
32 }
33
34 public void tick()
35 {
36 //throw new UnsupportedOperationException("Not supported yet.");
37 }
38
39 public void render(Graphics2D g)
40 {
41 g.drawImage(cacheBase, 0, 0, null);
42 }
43
44 public void processInput(KeyInput key)
45 {
46 //throw new UnsupportedOperationException("Not supported yet.");
47 }
48
49}
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 @@
6package com.fourisland.fourpuzzle.util; 6package com.fourisland.fourpuzzle.util;
7 7
8import com.fourisland.fourpuzzle.Game; 8import com.fourisland.fourpuzzle.Game;
9import com.fourisland.fourpuzzle.KeyboardInput;
10import com.fourisland.fourpuzzle.PuzzleApplication;
9 11
10/** 12/**
11 * 13 *
@@ -32,6 +34,11 @@ public class Interval {
32 private long last = System.nanoTime(); 34 private long last = System.nanoTime();
33 public boolean isElapsed() 35 public boolean isElapsed()
34 { 36 {
37 if (PuzzleApplication.debugSpeed)
38 {
39 return true;
40 }
41
35 if (last+wait < System.nanoTime()) 42 if (last+wait < System.nanoTime())
36 { 43 {
37 last = System.nanoTime(); 44 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 @@
5 5
6package com.fourisland.fourpuzzle.util; 6package com.fourisland.fourpuzzle.util;
7 7
8import com.fourisland.fourpuzzle.PuzzleApplication;
9
8/** 10/**
9 * 11 *
10 * @author hatkirby 12 * @author hatkirby
@@ -20,6 +22,11 @@ public class PauseTimer {
20 Interval in = Interval.createTickInterval(1); 22 Interval in = Interval.createTickInterval(1);
21 public boolean isElapsed() 23 public boolean isElapsed()
22 { 24 {
25 if (PuzzleApplication.debugSpeed)
26 {
27 return true;
28 }
29
23 if (in.isElapsed()) 30 if (in.isElapsed())
24 { 31 {
25 if (ticks == 0) 32 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 {
124 124
125 public static enum ChoiceWindowLocation 125 public static enum ChoiceWindowLocation
126 { 126 {
127 AbsoluteTopLeft
128 {
129 public int getX(int width)
130 {
131 return 0;
132 }
133
134 @Override
135 public int getY(int height)
136 {
137 return 0;
138 }
139 },
127 BottomLeft 140 BottomLeft
128 { 141 {
129 public int getX(int width) 142 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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.window;
7
8import com.fourisland.fourpuzzle.KeyInput;
9import java.util.List;
10import com.fourisland.fourpuzzle.util.Inputable;
11import com.fourisland.fourpuzzle.util.PauseTimer;
12import java.awt.event.KeyEvent;
13
14/**
15 *
16 * @author hatkirby
17 */
18public class InputableChoiceWindow extends ChoiceWindow implements Inputable {
19
20 Boolean hasInput = false;
21 PauseTimer pt = new PauseTimer(0);
22
23 public InputableChoiceWindow(List<String> choices, boolean center, ChoiceWindowLocation cwl)
24 {
25 super(choices, center, cwl);
26 }
27
28 public void processInput(KeyInput key)
29 {
30 if (key.getKey() == KeyEvent.VK_UP)
31 {
32 if (pt.isElapsed())
33 {
34 moveUp();
35 pt.setTimer(1);
36 }
37 } else if (key.getKey() == KeyEvent.VK_DOWN)
38 {
39 if (pt.isElapsed())
40 {
41 moveDown();
42 pt.setTimer(1);
43 }
44 } else if (key.isActionDown())
45 {
46 synchronized (hasInput)
47 {
48 hasInput = true;
49 }
50 }
51 }
52
53 public boolean hasInput()
54 {
55 synchronized (hasInput)
56 {
57 return hasInput;
58 }
59 }
60
61}