summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-03-17 09:34:18 -0400
committerStarla Insigna <hatkirby@fourisland.com>2009-03-17 09:34:18 -0400
commit28e41757f11ea216f641b4889bd43be2b6373484 (patch)
tree4d29231ca35702afd9e5bfad17b1c170098fc9aa /src/com/fourisland/fourpuzzle/gamestate/mapview/event
parent0a5ace745f171cad0150dbed11ae8febc0e17f27 (diff)
downloadfourpuzzle-28e41757f11ea216f641b4889bd43be2b6373484.tar.gz
fourpuzzle-28e41757f11ea216f641b4889bd43be2b6373484.tar.bz2
fourpuzzle-28e41757f11ea216f641b4889bd43be2b6373484.zip
Engine: Added ShakeScreen() special action
Also implemented F12 to return to the title screen and added a move frequency variable to events that decides how often they move.
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/event')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java11
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java3
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java1
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java29
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveFrequency.java34
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java20
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java50
7 files changed, 143 insertions, 5 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index e9482f9..aa2c3b3 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java
@@ -218,4 +218,15 @@ public abstract class AbstractEvent implements Event {
218 { 218 {
219 return moveSpeed; 219 return moveSpeed;
220 } 220 }
221
222 private MoveFrequency freq;
223 public void setFrequency(MoveFrequency freq)
224 {
225 this.freq = freq;
226 }
227
228 public MoveFrequency getFrequency()
229 {
230 return freq;
231 }
221} 232}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index 0cda403..936394b 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java
@@ -51,4 +51,7 @@ public interface Event {
51 51
52 public void setMoveSpeed(MoveSpeed moveSpeed); 52 public void setMoveSpeed(MoveSpeed moveSpeed);
53 public MoveSpeed getMoveSpeed(); 53 public MoveSpeed getMoveSpeed();
54
55 public void setFrequency(MoveFrequency freq);
56 public MoveFrequency getFrequency();
54} 57}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index 5db87a0..1df6c1d 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java
@@ -25,6 +25,7 @@ public class HeroEvent extends AbstractEvent implements Event {
25 { 25 {
26 setLocation(new Point()); 26 setLocation(new Point());
27 setMoveSpeed(MoveSpeed.Faster); 27 setMoveSpeed(MoveSpeed.Faster);
28 setFrequency(MoveFrequency.EIGHT);
28 } 29 }
29 30
30 public String getLabel() 31 public String getLabel()
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 9788b2e..afaf923 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java
@@ -12,6 +12,7 @@ import com.fourisland.fourpuzzle.Direction;
12import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic; 12import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic;
13import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.MoveableEventGraphic; 13import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.MoveableEventGraphic;
14import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition; 14import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition;
15import com.fourisland.fourpuzzle.util.PauseTimer;
15 16
16/** 17/**
17 * 18 *
@@ -97,15 +98,21 @@ public class LayerEvent extends AbstractEvent implements Event {
97 } 98 }
98 } 99 }
99 100
101 PauseTimer pt = new PauseTimer(0);
100 public void startMoving() 102 public void startMoving()
101 { 103 {
102 Direction toMove = getPossibleEvent().getMovement().nextMovement(new ImmutableEvent(this)); 104 if (pt.isElapsed())
103
104 if (toMove != null)
105 { 105 {
106 if (getPossibleEvent().getGraphic() instanceof MoveableEventGraphic) 106 pt.setTimer(getFrequency().getFrequency()-1);
107
108 Direction toMove = getPossibleEvent().getMovement().nextMovement(new ImmutableEvent(this));
109
110 if (toMove != null)
107 { 111 {
108 startMoving(toMove); 112 if (getPossibleEvent().getGraphic() instanceof MoveableEventGraphic)
113 {
114 startMoving(toMove);
115 }
109 } 116 }
110 } 117 }
111 } 118 }
@@ -169,4 +176,16 @@ public class LayerEvent extends AbstractEvent implements Event {
169 return getPossibleEvent().getMoveSpeed(); 176 return getPossibleEvent().getMoveSpeed();
170 } 177 }
171 178
179 @Override
180 public void setFrequency(MoveFrequency freq)
181 {
182 getPossibleEvent().setFrequency(freq);
183 }
184
185 @Override
186 public MoveFrequency getFrequency()
187 {
188 return getPossibleEvent().getFrequency();
189 }
190
172} \ No newline at end of file 191} \ No newline at end of file
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveFrequency.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveFrequency.java new file mode 100644 index 0000000..3e3cc0e --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveFrequency.java
@@ -0,0 +1,34 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8/**
9 *
10 * @author hatkirby
11 */
12public enum MoveFrequency {
13
14 EIGHT(1),
15 SEVEN(2),
16 SIX(3),
17 FIVE(4),
18 FOUR(5),
19 THREE(6),
20 TWO(7),
21 ONE(8);
22
23 private int freq;
24 private MoveFrequency(int freq)
25 {
26 this.freq = freq;
27 }
28
29 public int getFrequency()
30 {
31 return freq;
32 }
33
34}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java index 7f255dd..3f35943 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java
@@ -25,6 +25,7 @@ public class PossibleEvent {
25 private AnimationType animation; 25 private AnimationType animation;
26 private MovementType movement; 26 private MovementType movement;
27 private MoveSpeed moveSpeed; 27 private MoveSpeed moveSpeed;
28 private MoveFrequency freq;
28 private EventCallTime calltime; 29 private EventCallTime calltime;
29 private EventCall callback; 30 private EventCall callback;
30 31
@@ -44,6 +45,7 @@ public class PossibleEvent {
44 private AnimationType animation = AnimationType.CommonWithoutStepping; 45 private AnimationType animation = AnimationType.CommonWithoutStepping;
45 private MovementType movement = new StayStillMovementType(); 46 private MovementType movement = new StayStillMovementType();
46 private MoveSpeed moveSpeed = MoveSpeed.Normal; 47 private MoveSpeed moveSpeed = MoveSpeed.Normal;
48 private MoveFrequency freq = MoveFrequency.EIGHT;
47 private EventCallTime calltime = EventCallTime.PushKey; 49 private EventCallTime calltime = EventCallTime.PushKey;
48 private EventCall callback = EventCall.getEmptyEventCall(); 50 private EventCall callback = EventCall.getEmptyEventCall();
49 51
@@ -77,6 +79,12 @@ public class PossibleEvent {
77 return this; 79 return this;
78 } 80 }
79 81
82 public Builder freq(MoveFrequency freq)
83 {
84 this.freq = freq;
85 return this;
86 }
87
80 public Builder calltime(EventCallTime calltime) 88 public Builder calltime(EventCallTime calltime)
81 { 89 {
82 this.calltime = calltime; 90 this.calltime = calltime;
@@ -102,6 +110,7 @@ public class PossibleEvent {
102 animation = builder.animation; 110 animation = builder.animation;
103 movement = builder.movement; 111 movement = builder.movement;
104 moveSpeed = builder.moveSpeed; 112 moveSpeed = builder.moveSpeed;
113 freq = builder.freq;
105 calltime = builder.calltime; 114 calltime = builder.calltime;
106 callback = builder.callback; 115 callback = builder.callback;
107 } 116 }
@@ -114,6 +123,7 @@ public class PossibleEvent {
114 .animation(animation) 123 .animation(animation)
115 .movement(movement) 124 .movement(movement)
116 .speed(moveSpeed) 125 .speed(moveSpeed)
126 .freq(freq)
117 .calltime(calltime) 127 .calltime(calltime)
118 .callback(callback) 128 .callback(callback)
119 .build(); 129 .build();
@@ -154,6 +164,16 @@ public class PossibleEvent {
154 { 164 {
155 return moveSpeed; 165 return moveSpeed;
156 } 166 }
167
168 void setFrequency(MoveFrequency freq)
169 {
170 this.freq = freq;
171 }
172
173 public MoveFrequency getFrequency()
174 {
175 return freq;
176 }
157 177
158 private boolean moving = false; 178 private boolean moving = false;
159 void setMoving(boolean moving) 179 void setMoving(boolean moving)
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index ca3ba5e..2db33f7 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -16,6 +16,8 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventTh
16import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; 16import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint;
17import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.FixedViewpoint; 17import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.FixedViewpoint;
18import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.MovingViewpoint; 18import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.MovingViewpoint;
19import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.ShakingViewpoint;
20import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.ShakingViewpoint.ShakeSpeed;
19import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; 21import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint;
20import com.fourisland.fourpuzzle.transition.InTransition; 22import com.fourisland.fourpuzzle.transition.InTransition;
21import com.fourisland.fourpuzzle.transition.OutTransition; 23import com.fourisland.fourpuzzle.transition.OutTransition;
@@ -366,4 +368,52 @@ public class SpecialEvent {
366 throw new InterruptedException(); 368 throw new InterruptedException();
367 } 369 }
368 370
371 /**
372 * Shake the screen like an earthquake
373 *
374 * @param speed How fast the screen should shake
375 * @param length The amount of time (in milliseconds) the shaking should
376 * last
377 * @param block If true, the game will wait for the shaking to complete
378 * before executing any more commands
379 * @throws java.lang.InterruptedException
380 */
381 public void ShakeScreen(ShakeSpeed speed, int length, final boolean block) throws InterruptedException
382 {
383 Viewpoint viewpoint = mapView.getViewpoint();
384 final CountDownLatch blocker;
385
386 if (block)
387 {
388 blocker = new CountDownLatch(1);
389 } else {
390 blocker = null;
391 }
392
393 mapView.setViewpoint(new ShakingViewpoint(viewpoint.getX(), viewpoint.getY(), speed, length, new Runnable() {
394 public void run()
395 {
396 if (block)
397 {
398 blocker.countDown();
399 } else {
400 ResetViewpoint();
401 }
402 }
403 }));
404
405 if (block)
406 {
407 try
408 {
409 blocker.await();
410 } catch (InterruptedException ex)
411 {
412 throw ex;
413 } finally {
414 ResetViewpoint();
415 }
416 }
417 }
418
369} 419}