diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-30 15:03:35 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-30 15:03:35 -0500 |
commit | 000384f5921bad138b77870fb6381fea5ac4d38b (patch) | |
tree | ecabd4bd7900c812c3f55b3d02474e4d35226971 /src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | |
parent | 0526f49e9b06d77f979d3e3ae67ce4f8b827a362 (diff) | |
download | fourpuzzle-000384f5921bad138b77870fb6381fea5ac4d38b.tar.gz fourpuzzle-000384f5921bad138b77870fb6381fea5ac4d38b.tar.bz2 fourpuzzle-000384f5921bad138b77870fb6381fea5ac4d38b.zip |
Implemented viewpoint-related Event actions
Implemented FixViewpoint(), PanViewpoint() and ResetViewpoint()
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java')
-rw-r--r-- | src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 615396b..342b65f 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | |||
@@ -9,6 +9,11 @@ import com.fourisland.fourpuzzle.*; | |||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; | 9 | import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; |
10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; | 10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; |
11 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; | 11 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; |
12 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; | ||
13 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.FixedViewpoint; | ||
14 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.MovingViewpoint; | ||
15 | import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; | ||
16 | import java.util.concurrent.CountDownLatch; | ||
12 | import java.util.logging.Level; | 17 | import java.util.logging.Level; |
13 | import java.util.logging.Logger; | 18 | import java.util.logging.Logger; |
14 | 19 | ||
@@ -17,6 +22,12 @@ import java.util.logging.Logger; | |||
17 | * @author hatkirby | 22 | * @author hatkirby |
18 | */ | 23 | */ |
19 | public class SpecialEvent { | 24 | public class SpecialEvent { |
25 | |||
26 | protected static MapViewGameState mapView = null; | ||
27 | public static void setMapView(MapViewGameState mapView) | ||
28 | { | ||
29 | SpecialEvent.mapView = mapView; | ||
30 | } | ||
20 | 31 | ||
21 | /** | 32 | /** |
22 | * Display a message on the screen. | 33 | * Display a message on the screen. |
@@ -165,4 +176,71 @@ public class SpecialEvent { | |||
165 | } | 176 | } |
166 | } | 177 | } |
167 | 178 | ||
179 | /** | ||
180 | * Fixes the viewpoint in the current position | ||
181 | */ | ||
182 | public void FixViewpoint() | ||
183 | { | ||
184 | Viewpoint viewpoint = mapView.getViewpoint(); | ||
185 | mapView.setViewpoint(new FixedViewpoint(viewpoint.getX(),viewpoint.getY())); | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * Pans the viewpoint the the specified tile location | ||
190 | * | ||
191 | * @param x The x coordinate of the tile to pan to | ||
192 | * @param y The y coordinate of the tile to pan to | ||
193 | * @param length How long (in milliseconds) it will take to pan | ||
194 | * @param block If true, the game will wait for the pan to complete | ||
195 | * before executing any more commands | ||
196 | */ | ||
197 | public void PanViewpoint(final int x, final int y, int length, final boolean block) | ||
198 | { | ||
199 | Viewpoint viewpoint = mapView.getViewpoint(); | ||
200 | final CountDownLatch blocker; | ||
201 | |||
202 | if (block) | ||
203 | { | ||
204 | blocker = new CountDownLatch(1); | ||
205 | } else { | ||
206 | blocker = null; | ||
207 | } | ||
208 | |||
209 | mapView.setViewpoint(new MovingViewpoint(viewpoint.getX(), viewpoint.getY(), x*16, y*16, new Runnable() { | ||
210 | public void run() | ||
211 | { | ||
212 | mapView.setViewpoint(new FixedViewpoint(x*16,y*16)); | ||
213 | |||
214 | if (block) | ||
215 | { | ||
216 | blocker.countDown(); | ||
217 | } | ||
218 | } | ||
219 | }, length)); | ||
220 | |||
221 | if (block) | ||
222 | { | ||
223 | try { | ||
224 | blocker.await(); | ||
225 | } catch (InterruptedException ex) { | ||
226 | Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex); | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Resets the viewpoint from whatever state is is currently in | ||
233 | */ | ||
234 | public void ResetViewpoint() | ||
235 | { | ||
236 | Viewpoint viewpoint = mapView.getViewpoint(); | ||
237 | AutomaticViewpoint dest = new AutomaticViewpoint(mapView.getCurrentMap()); | ||
238 | |||
239 | mapView.setViewpoint(new MovingViewpoint(viewpoint.getX(), viewpoint.getY(), dest.getX(), dest.getY(), new Runnable() { | ||
240 | public void run() { | ||
241 | mapView.setViewpoint(new AutomaticViewpoint(mapView.getCurrentMap())); | ||
242 | } | ||
243 | })); | ||
244 | } | ||
245 | |||
168 | } | 246 | } |