diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-02-07 22:03:22 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-02-07 22:03:22 -0500 |
commit | 3724f4ecbe61e6621d4a7e993cd80ab75ee41266 (patch) | |
tree | 7701709896cdb261c9c1a2e89cf240f57b18e6b1 /src/com/fourisland/fourpuzzle/gamestate/mapview | |
parent | b2b180730ad252b4a8d15d9bc59895b56c552c29 (diff) | |
download | fourpuzzle-3724f4ecbe61e6621d4a7e993cd80ab75ee41266.tar.gz fourpuzzle-3724f4ecbe61e6621d4a7e993cd80ab75ee41266.tar.bz2 fourpuzzle-3724f4ecbe61e6621d4a7e993cd80ab75ee41266.zip |
Added TurnLeft and TurnRight AnimationTypes
Also implemented opposite(), left() and right() functions for Direction which return the opposite, counterclockwise and clockwise directions respectively. I don't exactly like the current Direction implementation as it's not very elegant. Hopefully there is a way to make this prettier. Also added a setter to PossibleEvent that allows LayerEvent to notify it when it starts or stops moving. This is necessary because the TurnLeft and TurnRight AnimationTypes constantly attempt to rotate the Event and if the Direction of the Event is changed while it is moving, it will move to a different space and animation will look strange. Thus, setDirection() has been modified so it will disallow direction change if the Event is moving. Also fixed a small encapsulation bug in AbstractEvent. PossibleEvent's notification of movement was made possible through the overriding of the setMoving() function, which is used by AbstractEvent to set if the Event is currently moving. However, while it used setMoving() to turn on moving, previously it did not use it to turn off moving, it simply modified the field. This has been fixed.
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview')
5 files changed, 53 insertions, 6 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 3283da5..3acfff4 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(hero.getDirection().oppositeDirection()); | 137 | ev.setDirection(hero.getDirection().opposite()); |
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/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index 483ce49..2933fff 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java | |||
@@ -78,7 +78,7 @@ public abstract class AbstractEvent implements Event { | |||
78 | } else if (moveTimer == 0) | 78 | } else if (moveTimer == 0) |
79 | { | 79 | { |
80 | setAnimationStep(1); | 80 | setAnimationStep(1); |
81 | moving = false; | 81 | setMoving(false); |
82 | 82 | ||
83 | if (getDirection() == Direction.North) | 83 | if (getDirection() == Direction.North) |
84 | { | 84 | { |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java index 7824470..4c3aeb9 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java | |||
@@ -46,10 +46,44 @@ public enum AnimationType { | |||
46 | /** | 46 | /** |
47 | * An AnimationType that does not allow the Event to turn or animate. | 47 | * An AnimationType that does not allow the Event to turn or animate. |
48 | */ | 48 | */ |
49 | FixedGraphic(false, false); | 49 | FixedGraphic(false, false), |
50 | /** | ||
51 | * An AnimationType that is identical to CommonWithoutStepping except that | ||
52 | * it causes the Event in question to continually rotate counterclockwise. | ||
53 | */ | ||
54 | TurnLeft(true, true) | ||
55 | { | ||
56 | Interval in = Interval.createTickInterval(2); | ||
57 | |||
58 | @Override | ||
59 | public void tick(PossibleEvent pe) | ||
60 | { | ||
61 | if (in.isElapsed()) | ||
62 | { | ||
63 | pe.setDirection(pe.getDirection().left()); | ||
64 | } | ||
65 | } | ||
66 | }, | ||
67 | /** | ||
68 | * An AnimationType that is identical to CommonWithoutStepping except that | ||
69 | * it causes the Event in question to continually rotate clockwise. | ||
70 | */ | ||
71 | TurnRight(true, true) | ||
72 | { | ||
73 | Interval in = Interval.createTickInterval(2); | ||
74 | |||
75 | @Override | ||
76 | public void tick(PossibleEvent pe) | ||
77 | { | ||
78 | if (in.isElapsed()) | ||
79 | { | ||
80 | pe.setDirection(pe.getDirection().right()); | ||
81 | } | ||
82 | } | ||
83 | }; | ||
50 | 84 | ||
51 | private boolean canTurn; | 85 | private final boolean canTurn; |
52 | private boolean canStep; | 86 | private final boolean canStep; |
53 | private AnimationType(boolean canTurn, boolean canStep) | 87 | private AnimationType(boolean canTurn, boolean canStep) |
54 | { | 88 | { |
55 | this.canTurn = canTurn; | 89 | this.canTurn = canTurn; |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index e57d7f8..3c826cb 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java | |||
@@ -132,4 +132,11 @@ public class LayerEvent extends AbstractEvent implements Event { | |||
132 | return getPossibleEvent().getAnimationStep(); | 132 | return getPossibleEvent().getAnimationStep(); |
133 | } | 133 | } |
134 | 134 | ||
135 | @Override | ||
136 | public void setMoving(boolean moving) | ||
137 | { | ||
138 | super.setMoving(moving); | ||
139 | getPossibleEvent().setMoving(moving); | ||
140 | } | ||
141 | |||
135 | } \ No newline at end of file | 142 | } \ No newline at end of file |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java index f31dcaf..a8c3a51 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java | |||
@@ -119,6 +119,12 @@ public class PossibleEvent { | |||
119 | return movement; | 119 | return movement; |
120 | } | 120 | } |
121 | 121 | ||
122 | private boolean moving = false; | ||
123 | void setMoving(boolean moving) | ||
124 | { | ||
125 | this.moving = moving; | ||
126 | } | ||
127 | |||
122 | Direction getDirection() | 128 | Direction getDirection() |
123 | { | 129 | { |
124 | return direction; | 130 | return direction; |
@@ -126,7 +132,7 @@ public class PossibleEvent { | |||
126 | 132 | ||
127 | void setDirection(Direction direction) | 133 | void setDirection(Direction direction) |
128 | { | 134 | { |
129 | if (animation.canTurn()) | 135 | if (animation.canTurn() && !moving) |
130 | { | 136 | { |
131 | this.direction = direction; | 137 | this.direction = direction; |
132 | graphic.setDirection(direction); | 138 | graphic.setDirection(direction); |