summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-03-08 14:34:06 -0400
committerStarla Insigna <hatkirby@fourisland.com>2009-03-08 14:34:06 -0400
commitdf5aafb66f429d968323b55c17d42ba0c6a62bbc (patch)
tree69bed76b284a21819e9e3899d1252a9861d5e053 /src
parenteeee11b2ace3af986173bf7b6d2bc2a1eae97a1b (diff)
downloadfourpuzzle-df5aafb66f429d968323b55c17d42ba0c6a62bbc.tar.gz
fourpuzzle-df5aafb66f429d968323b55c17d42ba0c6a62bbc.tar.bz2
fourpuzzle-df5aafb66f429d968323b55c17d42ba0c6a62bbc.zip
Engine: Added variable movement speed
Now, like in RM2K, Events can have different movement speeds. The Hero starts out with a faster MoveSpeed than other events and it can be changed when initalizing PossibleEvent or with a ChangeSpeedMoveEvent.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java42
-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.java12
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveSpeed.java31
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java20
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/ChangeSpeedMoveEvent.java30
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/util/Interval.java5
8 files changed, 128 insertions, 16 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index a2616e5..f859739 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java
@@ -8,6 +8,7 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event;
8import com.fourisland.fourpuzzle.Direction; 8import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.gamestate.mapview.Map; 9import com.fourisland.fourpuzzle.gamestate.mapview.Map;
10import com.fourisland.fourpuzzle.util.Functions; 10import com.fourisland.fourpuzzle.util.Functions;
11import com.fourisland.fourpuzzle.util.Interval;
11import java.awt.Point; 12import java.awt.Point;
12import java.util.ArrayList; 13import java.util.ArrayList;
13import java.util.List; 14import java.util.List;
@@ -60,7 +61,7 @@ public abstract class AbstractEvent implements Event {
60 if (!getParentMap().checkForCollision(this, toMove)) 61 if (!getParentMap().checkForCollision(this, toMove))
61 { 62 {
62 setAnimationStep(2); 63 setAnimationStep(2);
63 moveTimer = 4; 64 moveTimer = getMoveSpeed().getSpeed();
64 setMoving(true); 65 setMoving(true);
65 66
66 return true; 67 return true;
@@ -69,19 +70,23 @@ public abstract class AbstractEvent implements Event {
69 } 70 }
70 } 71 }
71 72
73 Interval in = Interval.createTickInterval(0.5F);
72 public void processMoving() 74 public void processMoving()
73 { 75 {
74 if (isMoving()) 76 if (isMoving())
75 { 77 {
76 moveTimer--; 78 if (in.isElapsed())
77 if (moveTimer == 2)
78 { 79 {
79 setAnimationStep(0); 80 moveTimer--;
80 } else if (moveTimer == 0) 81 if (moveTimer <= 0)
81 { 82 {
82 setAnimationStep(1); 83 setAnimationStep(1);
83 setMoving(false); 84 setMoving(false);
84 setLocation(getDirection().to(getLocation())); 85 setLocation(getDirection().to(getLocation()));
86 } else if (moveTimer <= (getMoveSpeed().getSpeed() / 2))
87 {
88 setAnimationStep(0);
89 }
85 } 90 }
86 } 91 }
87 } 92 }
@@ -146,10 +151,10 @@ public abstract class AbstractEvent implements Event {
146 { 151 {
147 if (getDirection() == Direction.West) 152 if (getDirection() == Direction.West)
148 { 153 {
149 return -((4 - moveTimer) * 4); 154 return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())));
150 } else if (getDirection() == Direction.East) 155 } else if (getDirection() == Direction.East)
151 { 156 {
152 return (4 - moveTimer) * 4; 157 return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()));
153 } 158 }
154 } 159 }
155 160
@@ -162,13 +167,24 @@ public abstract class AbstractEvent implements Event {
162 { 167 {
163 if (getDirection() == Direction.North) 168 if (getDirection() == Direction.North)
164 { 169 {
165 return -((4 - moveTimer) * 4); 170 return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())));
166 } else if (getDirection() == Direction.South) 171 } else if (getDirection() == Direction.South)
167 { 172 {
168 return (4 - moveTimer) * 4; 173 return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()));
169 } 174 }
170 } 175 }
171 176
172 return 0; 177 return 0;
173 } 178 }
179
180 private MoveSpeed moveSpeed;
181 public void setMoveSpeed(MoveSpeed moveSpeed)
182 {
183 this.moveSpeed = moveSpeed;
184 }
185
186 public MoveSpeed getMoveSpeed()
187 {
188 return moveSpeed;
189 }
174} 190}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index e6443c6..0cda403 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java
@@ -48,4 +48,7 @@ public interface Event {
48 48
49 public void setParentMap(Map parentMap); 49 public void setParentMap(Map parentMap);
50 public Map getParentMap(); 50 public Map getParentMap();
51
52 public void setMoveSpeed(MoveSpeed moveSpeed);
53 public MoveSpeed getMoveSpeed();
51} 54}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index fac21c6..5db87a0 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java
@@ -24,6 +24,7 @@ public class HeroEvent extends AbstractEvent implements Event {
24 public HeroEvent() 24 public HeroEvent()
25 { 25 {
26 setLocation(new Point()); 26 setLocation(new Point());
27 setMoveSpeed(MoveSpeed.Faster);
27 } 28 }
28 29
29 public String getLabel() 30 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 b1e9bdc..a95cad1 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java
@@ -165,4 +165,16 @@ public class LayerEvent extends AbstractEvent implements Event {
165 getPossibleEvent().setMoving(moving); 165 getPossibleEvent().setMoving(moving);
166 } 166 }
167 167
168 @Override
169 public void setMoveSpeed(MoveSpeed moveSpeed)
170 {
171 getPossibleEvent().setMoveSpeed(moveSpeed);
172 }
173
174 @Override
175 public MoveSpeed getMoveSpeed()
176 {
177 return getPossibleEvent().getMoveSpeed();
178 }
179
168} \ No newline at end of file 180} \ No newline at end of file
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveSpeed.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveSpeed.java new file mode 100644 index 0000000..5fb9df1 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveSpeed.java
@@ -0,0 +1,31 @@
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 MoveSpeed {
13 Slower2(16),
14 Slower(8),
15 Normal(6),
16 Faster(4),
17 Faster2(2),
18 Faster4(1);
19
20 private int speed;
21 private MoveSpeed(int speed)
22 {
23 this.speed = speed;
24 }
25
26 public int getSpeed()
27 {
28 return speed;
29 }
30
31}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java index f8934f4..7f255dd 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java
@@ -24,6 +24,7 @@ public class PossibleEvent {
24 private Layer layer; 24 private Layer layer;
25 private AnimationType animation; 25 private AnimationType animation;
26 private MovementType movement; 26 private MovementType movement;
27 private MoveSpeed moveSpeed;
27 private EventCallTime calltime; 28 private EventCallTime calltime;
28 private EventCall callback; 29 private EventCall callback;
29 30
@@ -42,6 +43,7 @@ public class PossibleEvent {
42 private Layer layer = Layer.Below; 43 private Layer layer = Layer.Below;
43 private AnimationType animation = AnimationType.CommonWithoutStepping; 44 private AnimationType animation = AnimationType.CommonWithoutStepping;
44 private MovementType movement = new StayStillMovementType(); 45 private MovementType movement = new StayStillMovementType();
46 private MoveSpeed moveSpeed = MoveSpeed.Normal;
45 private EventCallTime calltime = EventCallTime.PushKey; 47 private EventCallTime calltime = EventCallTime.PushKey;
46 private EventCall callback = EventCall.getEmptyEventCall(); 48 private EventCall callback = EventCall.getEmptyEventCall();
47 49
@@ -69,6 +71,12 @@ public class PossibleEvent {
69 return this; 71 return this;
70 } 72 }
71 73
74 public Builder speed(MoveSpeed moveSpeed)
75 {
76 this.moveSpeed = moveSpeed;
77 return this;
78 }
79
72 public Builder calltime(EventCallTime calltime) 80 public Builder calltime(EventCallTime calltime)
73 { 81 {
74 this.calltime = calltime; 82 this.calltime = calltime;
@@ -93,6 +101,7 @@ public class PossibleEvent {
93 layer = builder.layer; 101 layer = builder.layer;
94 animation = builder.animation; 102 animation = builder.animation;
95 movement = builder.movement; 103 movement = builder.movement;
104 moveSpeed = builder.moveSpeed;
96 calltime = builder.calltime; 105 calltime = builder.calltime;
97 callback = builder.callback; 106 callback = builder.callback;
98 } 107 }
@@ -104,6 +113,7 @@ public class PossibleEvent {
104 .layer(layer) 113 .layer(layer)
105 .animation(animation) 114 .animation(animation)
106 .movement(movement) 115 .movement(movement)
116 .speed(moveSpeed)
107 .calltime(calltime) 117 .calltime(calltime)
108 .callback(callback) 118 .callback(callback)
109 .build(); 119 .build();
@@ -134,6 +144,16 @@ public class PossibleEvent {
134 { 144 {
135 return movement; 145 return movement;
136 } 146 }
147
148 void setMoveSpeed(MoveSpeed moveSpeed)
149 {
150 this.moveSpeed = moveSpeed;
151 }
152
153 public MoveSpeed getMoveSpeed()
154 {
155 return moveSpeed;
156 }
137 157
138 private boolean moving = false; 158 private boolean moving = false;
139 void setMoving(boolean moving) 159 void setMoving(boolean moving)
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/ChangeSpeedMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/ChangeSpeedMoveEvent.java new file mode 100644 index 0000000..d508bec --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/ChangeSpeedMoveEvent.java
@@ -0,0 +1,30 @@
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.specialmove;
7
8import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.MoveSpeed;
10
11/**
12 * ChangeSpeedMoveEvent changes the walk speed of an event; in other words, it
13 * changes how fast an event moves from one space to the next.
14 *
15 * @author hatkirby
16 */
17public class ChangeSpeedMoveEvent implements MoveEvent {
18
19 private MoveSpeed moveSpeed;
20 public ChangeSpeedMoveEvent(MoveSpeed moveSpeed)
21 {
22 this.moveSpeed = moveSpeed;
23 }
24
25 public void doAction(Event ev)
26 {
27 ev.setMoveSpeed(moveSpeed);
28 }
29
30}
diff --git a/src/com/fourisland/fourpuzzle/util/Interval.java b/src/com/fourisland/fourpuzzle/util/Interval.java index 044c50b..3383a39 100755 --- a/src/com/fourisland/fourpuzzle/util/Interval.java +++ b/src/com/fourisland/fourpuzzle/util/Interval.java
@@ -6,7 +6,6 @@
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; 9import com.fourisland.fourpuzzle.PuzzleApplication;
11 10
12/** 11/**
@@ -21,9 +20,9 @@ public class Interval {
21 this.wait = wait; 20 this.wait = wait;
22 } 21 }
23 22
24 public static Interval createTickInterval(int ticks) 23 public static Interval createTickInterval(float ticks)
25 { 24 {
26 return createMillisInterval(Game.FPS*ticks); 25 return createMillisInterval((int) (Game.FPS * ticks));
27 } 26 }
28 27
29 public static Interval createMillisInterval(int millis) 28 public static Interval createMillisInterval(int millis)