diff options
| author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-07 13:15:06 -0500 |
|---|---|---|
| committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-07 13:15:06 -0500 |
| commit | e8e617ed1465073d59a9e5eea9f0cc6c15058d49 (patch) | |
| tree | bf7af353d64ae505ab9ffe8e5dc1f4910934496b /src/com | |
| parent | b5ff6fcc1e572d1a6150ee2af159be68ee2c2a94 (diff) | |
| download | fourpuzzle-e8e617ed1465073d59a9e5eea9f0cc6c15058d49.tar.gz fourpuzzle-e8e617ed1465073d59a9e5eea9f0cc6c15058d49.tar.bz2 fourpuzzle-e8e617ed1465073d59a9e5eea9f0cc6c15058d49.zip | |
Implemented all AnimationTypes
Diffstat (limited to 'src/com')
5 files changed, 92 insertions, 41 deletions
| 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 { | |||
| 13 | North, | 13 | North, |
| 14 | East, | 14 | East, |
| 15 | South, | 15 | South, |
| 16 | West | 16 | West; |
| 17 | |||
| 18 | /** | ||
| 19 | * Returns the direction opposite from the current one | ||
| 20 | * @return A Direction representing the opposite direction | ||
| 21 | */ | ||
| 22 | public Direction oppositeDirection() | ||
| 23 | { | ||
| 24 | switch (this) | ||
| 25 | { | ||
| 26 | case North: return Direction.South; | ||
| 27 | case West: return Direction.East; | ||
| 28 | case South: return Direction.North; | ||
| 29 | case East: return Direction.West; | ||
| 30 | } | ||
| 31 | |||
| 32 | return null; | ||
| 33 | } | ||
| 17 | } | 34 | } |
| 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 { | |||
| 134 | { | 134 | { |
| 135 | if (Functions.isFacing(hero, ev)) | 135 | if (Functions.isFacing(hero, ev)) |
| 136 | { | 136 | { |
| 137 | ev.setDirection(Functions.oppositeDirection(hero.getDirection())); | 137 | ev.setDirection(hero.getDirection().oppositeDirection()); |
| 138 | ev.getCallback().activate(ev.getCalltime()); | 138 | ev.getCallback().activate(ev.getCalltime()); |
| 139 | } | 139 | } |
| 140 | } else { | 140 | } 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; | |||
| 10 | * @author hatkirby | 10 | * @author hatkirby |
| 11 | */ | 11 | */ |
| 12 | public enum AnimationType { | 12 | public enum AnimationType { |
| 13 | CommonWithoutStepping, | 13 | /** |
| 14 | CommonWithStepping, | 14 | * The default AnimationType, it allows the Event to turn and to animate |
| 15 | WithoutStepping, | 15 | * while it walks, but it only animates while it moves. |
| 16 | FixedGraphic, | 16 | */ |
| 17 | TurnLeft, | 17 | CommonWithoutStepping(true, true, false), |
| 18 | TurnRight | 18 | /** |
| 19 | * An AnimationType which allows the Event to turn and to animate. It will | ||
| 20 | * animate at all times, even while stationary. | ||
| 21 | */ | ||
| 22 | CommonWithStepping(true, true, true), | ||
| 23 | /** | ||
| 24 | * An AnimationType that allows the Event to turn, but not to animate. | ||
| 25 | */ | ||
| 26 | WithoutStepping(true, false, false), | ||
| 27 | /** | ||
| 28 | * An AnimationType that does not allow the Event to turn or animate. | ||
| 29 | */ | ||
| 30 | FixedGraphic(false, false, false); | ||
| 31 | |||
| 32 | private boolean canTurn; | ||
| 33 | private boolean canStep; | ||
| 34 | private boolean alwaysStepping; | ||
| 35 | private AnimationType(boolean canTurn, boolean canStep, boolean alwaysStepping) | ||
| 36 | { | ||
| 37 | this.canTurn = canTurn; | ||
| 38 | this.canStep = canStep; | ||
| 39 | |||
| 40 | if (!canStep) | ||
| 41 | { | ||
| 42 | this.alwaysStepping = false; | ||
| 43 | } else { | ||
| 44 | this.alwaysStepping = alwaysStepping; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | public boolean canTurn() | ||
| 49 | { | ||
| 50 | return canTurn; | ||
| 51 | } | ||
| 52 | |||
| 53 | public boolean canStep() | ||
| 54 | { | ||
| 55 | return canStep; | ||
| 56 | } | ||
| 57 | |||
| 58 | public boolean isAlwaysStepping() | ||
| 59 | { | ||
| 60 | return alwaysStepping; | ||
| 61 | } | ||
| 62 | |||
| 19 | } | 63 | } |
| 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 | |||
| 13 | import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.EventGraphic; | 13 | import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.EventGraphic; |
| 14 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.MovementType; | 14 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.MovementType; |
| 15 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.StayStillMovementType; | 15 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.StayStillMovementType; |
| 16 | import com.fourisland.fourpuzzle.util.Functions; | ||
| 17 | import java.awt.image.BufferedImage; | 16 | import java.awt.image.BufferedImage; |
| 18 | 17 | ||
| 19 | /** | 18 | /** |
| @@ -52,7 +51,24 @@ public class PossibleEvent { | |||
| 52 | return graphic.getImage(); | 51 | return graphic.getImage(); |
| 53 | } | 52 | } |
| 54 | 53 | ||
| 54 | private boolean aSLC = false; | ||
| 55 | public EventGraphic getGraphic() { | 55 | public EventGraphic getGraphic() { |
| 56 | if (animation.isAlwaysStepping()) | ||
| 57 | { | ||
| 58 | if (aSLC) | ||
| 59 | { | ||
| 60 | aSLC = false; | ||
| 61 | |||
| 62 | if (animationStep == 0) | ||
| 63 | { | ||
| 64 | setAnimationStep(2); | ||
| 65 | } else { | ||
| 66 | setAnimationStep(animationStep-1); | ||
| 67 | } | ||
| 68 | } else { | ||
| 69 | aSLC = true; | ||
| 70 | } | ||
| 71 | } | ||
| 56 | return graphic; | 72 | return graphic; |
| 57 | } | 73 | } |
| 58 | 74 | ||
| @@ -90,7 +106,7 @@ public class PossibleEvent { | |||
| 90 | 106 | ||
| 91 | public void setDirection(Direction direction) | 107 | public void setDirection(Direction direction) |
| 92 | { | 108 | { |
| 93 | if (Functions.canTurn(this)) | 109 | if (animation.canTurn()) |
| 94 | { | 110 | { |
| 95 | this.direction = direction; | 111 | this.direction = direction; |
| 96 | graphic.setDirection(direction); | 112 | graphic.setDirection(direction); |
| @@ -102,8 +118,11 @@ public class PossibleEvent { | |||
| 102 | } | 118 | } |
| 103 | 119 | ||
| 104 | public void setAnimationStep(int animationStep) { | 120 | public void setAnimationStep(int animationStep) { |
| 105 | this.animationStep = animationStep; | 121 | if (animation.canStep()) |
| 106 | graphic.setAnimationStep(animationStep); | 122 | { |
| 123 | this.animationStep = animationStep; | ||
| 124 | graphic.setAnimationStep(animationStep); | ||
| 125 | } | ||
| 107 | } | 126 | } |
| 108 | 127 | ||
| 109 | public void addPrecondition(Precondition precondition) | 128 | 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; | |||
| 7 | 7 | ||
| 8 | import com.fourisland.fourpuzzle.Direction; | 8 | import com.fourisland.fourpuzzle.Direction; |
| 9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | 9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; |
| 10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.PossibleEvent; | ||
| 11 | 10 | ||
| 12 | /** | 11 | /** |
| 13 | * | 12 | * |
| 14 | * @author hatkirby | 13 | * @author hatkirby |
| 15 | */ | 14 | */ |
| 16 | public class Functions { | 15 | public class Functions { |
| 17 | |||
| 18 | public static boolean canTurn(PossibleEvent ev) | ||
| 19 | { | ||
| 20 | switch (ev.getAnimation()) | ||
| 21 | { | ||
| 22 | case CommonWithoutStepping: return true; | ||
| 23 | case CommonWithStepping: return true; | ||
| 24 | case WithoutStepping: return true; | ||
| 25 | case FixedGraphic: return false; | ||
| 26 | case TurnLeft: return false; | ||
| 27 | case TurnRight: return false; | ||
| 28 | } | ||
| 29 | |||
| 30 | return false; | ||
| 31 | } | ||
| 32 | 16 | ||
| 33 | public static boolean isFacing(Event ev1, Event ev2) | 17 | public static boolean isFacing(Event ev1, Event ev2) |
| 34 | { | 18 | { |
| @@ -78,18 +62,5 @@ public class Functions { | |||
| 78 | 62 | ||
| 79 | return false; | 63 | return false; |
| 80 | } | 64 | } |
| 81 | |||
| 82 | public static Direction oppositeDirection(Direction dir) | ||
| 83 | { | ||
| 84 | switch (dir) | ||
| 85 | { | ||
| 86 | case North: return Direction.South; | ||
| 87 | case West: return Direction.East; | ||
| 88 | case South: return Direction.North; | ||
| 89 | case East: return Direction.West; | ||
| 90 | } | ||
| 91 | |||
| 92 | return null; | ||
| 93 | } | ||
| 94 | 65 | ||
| 95 | } | 66 | } |
