summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-02-15 14:54:15 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-02-15 14:54:15 -0500
commit1fb7799ff91729285bf145b2c78f9233a61ac35c (patch)
treee6779a3409f76975b067dd11ce24cfa556583705 /src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
parentd242cfcf9a62bed5158c33c061e47fa393e2301a (diff)
downloadfourpuzzle-1fb7799ff91729285bf145b2c78f9233a61ac35c.tar.gz
fourpuzzle-1fb7799ff91729285bf145b2c78f9233a61ac35c.tar.bz2
fourpuzzle-1fb7799ff91729285bf145b2c78f9233a61ac35c.zip
Engine: Fixed MessageWindow bug
Previously, MessageWindow would, on occasion, throw out an ArrayIndexOutOfBoundsException. This may have been because of some keyboard input. Because of this, the keyboard input system has been re-written to be anologous to the Display system (Renderable). Now, only one input processor will run at a time because they are executed in order by KeyboardInput, rather than all at once using AWT event handlers.
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java115
1 files changed, 55 insertions, 60 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index a20062d..1213b0c 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -11,6 +11,7 @@ import com.fourisland.fourpuzzle.Direction;
11import com.fourisland.fourpuzzle.Display; 11import com.fourisland.fourpuzzle.Display;
12import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; 12import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent;
13import com.fourisland.fourpuzzle.Game; 13import com.fourisland.fourpuzzle.Game;
14import com.fourisland.fourpuzzle.KeyInput;
14import com.fourisland.fourpuzzle.Layer; 15import com.fourisland.fourpuzzle.Layer;
15import com.fourisland.fourpuzzle.PuzzleApplication; 16import com.fourisland.fourpuzzle.PuzzleApplication;
16import com.fourisland.fourpuzzle.database.Database; 17import com.fourisland.fourpuzzle.database.Database;
@@ -34,7 +35,6 @@ import java.awt.image.BufferedImage;
34public class MapViewGameState implements GameState { 35public class MapViewGameState implements GameState {
35 36
36 public boolean debugWalkthrough = false; 37 public boolean debugWalkthrough = false;
37 boolean processInput = true;
38 Map currentMap; 38 Map currentMap;
39 Viewpoint currentViewpoint = null; 39 Viewpoint currentViewpoint = null;
40 40
@@ -61,90 +61,85 @@ public class MapViewGameState implements GameState {
61 // Do nothing, yet 61 // Do nothing, yet
62 } 62 }
63 63
64 public void processInput() 64 public void processInput(KeyInput key)
65 { 65 {
66 if (processInput) 66 HeroEvent hero = Game.getSaveFile().getHero();
67 {
68 HeroEvent hero = Game.getSaveFile().getHero();
69 67
70 if (Game.getKey().isControlDown() && !debugWalkthrough) 68 if (key.isCtrlDown() && !debugWalkthrough)
69 {
70 if (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode"))
71 { 71 {
72 if (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) 72 debugWalkthrough = true;
73 {
74 debugWalkthrough = true;
75 }
76 } else {
77 debugWalkthrough = false;
78 } 73 }
74 } else {
75 debugWalkthrough = false;
76 }
79 77
80 if (!hero.isMoving() && !MoveEventThread.isHeroActive() && !EventHandler.isRunningEvent()) 78 if (!hero.isMoving() && !MoveEventThread.isHeroActive() && !EventHandler.isRunningEvent())
81 { 79 {
82 Direction toMove = null; 80 Direction toMove = null;
83 Boolean letsMove = false; 81 Boolean letsMove = false;
84 82
85 switch (Game.getKey().getKeyCode()) 83 switch (key.getKey())
86 { 84 {
87 case KeyEvent.VK_UP: 85 case KeyEvent.VK_UP:
88 toMove = Direction.North; 86 toMove = Direction.North;
89 letsMove = true; 87 letsMove = true;
90 break; 88 break;
91 case KeyEvent.VK_RIGHT: 89 case KeyEvent.VK_RIGHT:
92 toMove = Direction.East; 90 toMove = Direction.East;
93 letsMove = true; 91 letsMove = true;
94 break; 92 break;
95 case KeyEvent.VK_DOWN: 93 case KeyEvent.VK_DOWN:
96 toMove = Direction.South; 94 toMove = Direction.South;
97 letsMove = true; 95 letsMove = true;
98 break; 96 break;
99 case KeyEvent.VK_LEFT: 97 case KeyEvent.VK_LEFT:
100 toMove = Direction.West; 98 toMove = Direction.West;
101 letsMove = true; 99 letsMove = true;
102 break; 100 break;
103 } 101 }
104 102
105 if (letsMove) 103 if (letsMove)
104 {
105 if (!hero.startMoving(toMove))
106 { 106 {
107 if (!hero.startMoving(toMove)) 107 for (LayerEvent ev : currentMap.getEvents())
108 { 108 {
109 for (LayerEvent ev : currentMap.getEvents()) 109 if (ev.getCalltime() == EventCallTime.OnHeroTouch)
110 { 110 {
111 if (ev.getCalltime() == EventCallTime.OnHeroTouch) 111 if (ev.getLayer() == Layer.Middle)
112 { 112 {
113 if (ev.getLayer() == Layer.Middle) 113 if (Functions.isFacing(hero, ev))
114 { 114 {
115 if (Functions.isFacing(hero, ev)) 115 ev.getCallback().activate(ev.getCalltime());
116 {
117 ev.getCallback().activate(ev.getCalltime());
118 }
119 } 116 }
120 } 117 }
121 } 118 }
122 } 119 }
123 } 120 }
121 }
124 122
125 if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) 123 if ((key.getKey() == KeyEvent.VK_ENTER) || (key.getKey() == KeyEvent.VK_SPACE))
124 {
125 for (LayerEvent ev : currentMap.getEvents())
126 { 126 {
127 for (LayerEvent ev : currentMap.getEvents()) 127 if (ev.getCalltime() == EventCallTime.PushKey)
128 { 128 {
129 if (ev.getCalltime() == EventCallTime.PushKey) 129 if (ev.getLayer() == Layer.Middle)
130 { 130 {
131 if (ev.getLayer() == Layer.Middle) 131 if (Functions.isFacing(hero, ev))
132 { 132 {
133 if (Functions.isFacing(hero, ev)) 133 ev.setDirection(hero.getDirection().opposite());
134 { 134 ev.getCallback().activate(ev.getCalltime());
135 ev.setDirection(hero.getDirection().opposite()); 135 }
136 ev.getCallback().activate(ev.getCalltime()); 136 } else {
137 } 137 if (ev.getLocation().equals(hero.getLocation()))
138 } else { 138 {
139 if (ev.getLocation().equals(hero.getLocation())) 139 ev.getCallback().activate(ev.getCalltime());
140 {
141 ev.getCallback().activate(ev.getCalltime());
142 }
143 } 140 }
144 } 141 }
145 } 142 }
146
147 Game.getKey().setKeyCode(KeyEvent.VK_UNDEFINED);
148 } 143 }
149 } 144 }
150 } 145 }