From e8e617ed1465073d59a9e5eea9f0cc6c15058d49 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 7 Feb 2009 13:15:06 -0500 Subject: Implemented all AnimationTypes --- src/com/fourisland/fourpuzzle/Direction.java | 19 +++++++- .../gamestate/mapview/MapViewGameState.java | 2 +- .../gamestate/mapview/event/AnimationType.java | 56 +++++++++++++++++++--- .../gamestate/mapview/event/PossibleEvent.java | 27 +++++++++-- src/com/fourisland/fourpuzzle/util/Functions.java | 29 ----------- 5 files changed, 92 insertions(+), 41 deletions(-) (limited to 'src/com/fourisland') diff --git a/src/com/fourisland/fourpuzzle/Direction.java b/src/com/fourisland/fourpuzzle/Direction.java index e3a6cb8..948b024 100644 --- a/src/com/fourisland/fourpuzzle/Direction.java +++ b/src/com/fourisland/fourpuzzle/Direction.java @@ -13,5 +13,22 @@ public enum Direction { North, East, South, - West + West; + + /** + * Returns the direction opposite from the current one + * @return A Direction representing the opposite direction + */ + public Direction oppositeDirection() + { + switch (this) + { + case North: return Direction.South; + case West: return Direction.East; + case South: return Direction.North; + case East: return Direction.West; + } + + return null; + } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 7c4de27..3283da5 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -134,7 +134,7 @@ public class MapViewGameState implements GameState { { if (Functions.isFacing(hero, ev)) { - ev.setDirection(Functions.oppositeDirection(hero.getDirection())); + ev.setDirection(hero.getDirection().oppositeDirection()); ev.getCallback().activate(ev.getCalltime()); } } else { diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java index e7901df..20d6bfc 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java @@ -10,10 +10,54 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; * @author hatkirby */ public enum AnimationType { - CommonWithoutStepping, - CommonWithStepping, - WithoutStepping, - FixedGraphic, - TurnLeft, - TurnRight + /** + * The default AnimationType, it allows the Event to turn and to animate + * while it walks, but it only animates while it moves. + */ + CommonWithoutStepping(true, true, false), + /** + * An AnimationType which allows the Event to turn and to animate. It will + * animate at all times, even while stationary. + */ + CommonWithStepping(true, true, true), + /** + * An AnimationType that allows the Event to turn, but not to animate. + */ + WithoutStepping(true, false, false), + /** + * An AnimationType that does not allow the Event to turn or animate. + */ + FixedGraphic(false, false, false); + + private boolean canTurn; + private boolean canStep; + private boolean alwaysStepping; + private AnimationType(boolean canTurn, boolean canStep, boolean alwaysStepping) + { + this.canTurn = canTurn; + this.canStep = canStep; + + if (!canStep) + { + this.alwaysStepping = false; + } else { + this.alwaysStepping = alwaysStepping; + } + } + + public boolean canTurn() + { + return canTurn; + } + + public boolean canStep() + { + return canStep; + } + + public boolean isAlwaysStepping() + { + return alwaysStepping; + } + } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java index c18385d..5ba887b 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java @@ -13,7 +13,6 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraph import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.EventGraphic; import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.MovementType; import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.StayStillMovementType; -import com.fourisland.fourpuzzle.util.Functions; import java.awt.image.BufferedImage; /** @@ -52,7 +51,24 @@ public class PossibleEvent { return graphic.getImage(); } + private boolean aSLC = false; public EventGraphic getGraphic() { + if (animation.isAlwaysStepping()) + { + if (aSLC) + { + aSLC = false; + + if (animationStep == 0) + { + setAnimationStep(2); + } else { + setAnimationStep(animationStep-1); + } + } else { + aSLC = true; + } + } return graphic; } @@ -90,7 +106,7 @@ public class PossibleEvent { public void setDirection(Direction direction) { - if (Functions.canTurn(this)) + if (animation.canTurn()) { this.direction = direction; graphic.setDirection(direction); @@ -102,8 +118,11 @@ public class PossibleEvent { } public void setAnimationStep(int animationStep) { - this.animationStep = animationStep; - graphic.setAnimationStep(animationStep); + if (animation.canStep()) + { + this.animationStep = animationStep; + graphic.setAnimationStep(animationStep); + } } public void addPrecondition(Precondition precondition) diff --git a/src/com/fourisland/fourpuzzle/util/Functions.java b/src/com/fourisland/fourpuzzle/util/Functions.java index 9966a2f..c7c1243 100644 --- a/src/com/fourisland/fourpuzzle/util/Functions.java +++ b/src/com/fourisland/fourpuzzle/util/Functions.java @@ -7,28 +7,12 @@ package com.fourisland.fourpuzzle.util; import com.fourisland.fourpuzzle.Direction; import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; -import com.fourisland.fourpuzzle.gamestate.mapview.event.PossibleEvent; /** * * @author hatkirby */ public class Functions { - - public static boolean canTurn(PossibleEvent ev) - { - switch (ev.getAnimation()) - { - case CommonWithoutStepping: return true; - case CommonWithStepping: return true; - case WithoutStepping: return true; - case FixedGraphic: return false; - case TurnLeft: return false; - case TurnRight: return false; - } - - return false; - } public static boolean isFacing(Event ev1, Event ev2) { @@ -78,18 +62,5 @@ public class Functions { return false; } - - public static Direction oppositeDirection(Direction dir) - { - switch (dir) - { - case North: return Direction.South; - case West: return Direction.East; - case South: return Direction.North; - case East: return Direction.West; - } - - return null; - } } -- cgit 1.4.1