From df5aafb66f429d968323b55c17d42ba0c6a62bbc Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 8 Mar 2009 14:34:06 -0400 Subject: 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. --- .../gamestate/mapview/event/AbstractEvent.java | 42 +++++++++++++++------- .../fourpuzzle/gamestate/mapview/event/Event.java | 3 ++ .../gamestate/mapview/event/HeroEvent.java | 1 + .../gamestate/mapview/event/LayerEvent.java | 12 +++++++ .../gamestate/mapview/event/MoveSpeed.java | 31 ++++++++++++++++ .../gamestate/mapview/event/PossibleEvent.java | 20 +++++++++++ .../event/specialmove/ChangeSpeedMoveEvent.java | 30 ++++++++++++++++ src/com/fourisland/fourpuzzle/util/Interval.java | 5 ++- 8 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/MoveSpeed.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/ChangeSpeedMoveEvent.java (limited to 'src/com/fourisland') 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; import com.fourisland.fourpuzzle.Direction; import com.fourisland.fourpuzzle.gamestate.mapview.Map; import com.fourisland.fourpuzzle.util.Functions; +import com.fourisland.fourpuzzle.util.Interval; import java.awt.Point; import java.util.ArrayList; import java.util.List; @@ -60,7 +61,7 @@ public abstract class AbstractEvent implements Event { if (!getParentMap().checkForCollision(this, toMove)) { setAnimationStep(2); - moveTimer = 4; + moveTimer = getMoveSpeed().getSpeed(); setMoving(true); return true; @@ -69,19 +70,23 @@ public abstract class AbstractEvent implements Event { } } + Interval in = Interval.createTickInterval(0.5F); public void processMoving() { if (isMoving()) { - moveTimer--; - if (moveTimer == 2) + if (in.isElapsed()) { - setAnimationStep(0); - } else if (moveTimer == 0) - { - setAnimationStep(1); - setMoving(false); - setLocation(getDirection().to(getLocation())); + moveTimer--; + if (moveTimer <= 0) + { + setAnimationStep(1); + setMoving(false); + setLocation(getDirection().to(getLocation())); + } else if (moveTimer <= (getMoveSpeed().getSpeed() / 2)) + { + setAnimationStep(0); + } } } } @@ -146,10 +151,10 @@ public abstract class AbstractEvent implements Event { { if (getDirection() == Direction.West) { - return -((4 - moveTimer) * 4); + return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()))); } else if (getDirection() == Direction.East) { - return (4 - moveTimer) * 4; + return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())); } } @@ -162,13 +167,24 @@ public abstract class AbstractEvent implements Event { { if (getDirection() == Direction.North) { - return -((4 - moveTimer) * 4); + return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()))); } else if (getDirection() == Direction.South) { - return (4 - moveTimer) * 4; + return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())); } } return 0; } + + private MoveSpeed moveSpeed; + public void setMoveSpeed(MoveSpeed moveSpeed) + { + this.moveSpeed = moveSpeed; + } + + public MoveSpeed getMoveSpeed() + { + return moveSpeed; + } } 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 { public void setParentMap(Map parentMap); public Map getParentMap(); + + public void setMoveSpeed(MoveSpeed moveSpeed); + public MoveSpeed getMoveSpeed(); } 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 { public HeroEvent() { setLocation(new Point()); + setMoveSpeed(MoveSpeed.Faster); } 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 { getPossibleEvent().setMoving(moving); } + @Override + public void setMoveSpeed(MoveSpeed moveSpeed) + { + getPossibleEvent().setMoveSpeed(moveSpeed); + } + + @Override + public MoveSpeed getMoveSpeed() + { + return getPossibleEvent().getMoveSpeed(); + } + } \ 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event; + +/** + * + * @author hatkirby + */ +public enum MoveSpeed { + Slower2(16), + Slower(8), + Normal(6), + Faster(4), + Faster2(2), + Faster4(1); + + private int speed; + private MoveSpeed(int speed) + { + this.speed = speed; + } + + public int getSpeed() + { + return speed; + } + +} 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 { private Layer layer; private AnimationType animation; private MovementType movement; + private MoveSpeed moveSpeed; private EventCallTime calltime; private EventCall callback; @@ -42,6 +43,7 @@ public class PossibleEvent { private Layer layer = Layer.Below; private AnimationType animation = AnimationType.CommonWithoutStepping; private MovementType movement = new StayStillMovementType(); + private MoveSpeed moveSpeed = MoveSpeed.Normal; private EventCallTime calltime = EventCallTime.PushKey; private EventCall callback = EventCall.getEmptyEventCall(); @@ -69,6 +71,12 @@ public class PossibleEvent { return this; } + public Builder speed(MoveSpeed moveSpeed) + { + this.moveSpeed = moveSpeed; + return this; + } + public Builder calltime(EventCallTime calltime) { this.calltime = calltime; @@ -93,6 +101,7 @@ public class PossibleEvent { layer = builder.layer; animation = builder.animation; movement = builder.movement; + moveSpeed = builder.moveSpeed; calltime = builder.calltime; callback = builder.callback; } @@ -104,6 +113,7 @@ public class PossibleEvent { .layer(layer) .animation(animation) .movement(movement) + .speed(moveSpeed) .calltime(calltime) .callback(callback) .build(); @@ -134,6 +144,16 @@ public class PossibleEvent { { return movement; } + + void setMoveSpeed(MoveSpeed moveSpeed) + { + this.moveSpeed = moveSpeed; + } + + public MoveSpeed getMoveSpeed() + { + return moveSpeed; + } private boolean moving = false; 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; + +import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; +import com.fourisland.fourpuzzle.gamestate.mapview.event.MoveSpeed; + +/** + * ChangeSpeedMoveEvent changes the walk speed of an event; in other words, it + * changes how fast an event moves from one space to the next. + * + * @author hatkirby + */ +public class ChangeSpeedMoveEvent implements MoveEvent { + + private MoveSpeed moveSpeed; + public ChangeSpeedMoveEvent(MoveSpeed moveSpeed) + { + this.moveSpeed = moveSpeed; + } + + public void doAction(Event ev) + { + ev.setMoveSpeed(moveSpeed); + } + +} 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 @@ package com.fourisland.fourpuzzle.util; import com.fourisland.fourpuzzle.Game; -import com.fourisland.fourpuzzle.KeyboardInput; import com.fourisland.fourpuzzle.PuzzleApplication; /** @@ -21,9 +20,9 @@ public class Interval { this.wait = wait; } - public static Interval createTickInterval(int ticks) + public static Interval createTickInterval(float ticks) { - return createMillisInterval(Game.FPS*ticks); + return createMillisInterval((int) (Game.FPS * ticks)); } public static Interval createMillisInterval(int millis) -- cgit 1.4.1