summary refs log tree commit diff stats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/fourisland/fourpuzzle/Direction.java100
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java2
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java2
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java40
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java7
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java8
6 files changed, 133 insertions, 26 deletions
diff --git a/src/com/fourisland/fourpuzzle/Direction.java b/src/com/fourisland/fourpuzzle/Direction.java index 4742521..4fa0908 100644 --- a/src/com/fourisland/fourpuzzle/Direction.java +++ b/src/com/fourisland/fourpuzzle/Direction.java
@@ -10,30 +10,90 @@ package com.fourisland.fourpuzzle;
10 * @author hatkirby 10 * @author hatkirby
11 */ 11 */
12public enum Direction { 12public enum Direction {
13 North, 13 North
14 East, 14 {
15 South, 15 public Direction opposite()
16 West; 16 {
17 return Direction.South;
18 }
19
20 public Direction left()
21 {
22 return Direction.West;
23 }
24
25 public Direction right()
26 {
27 return Direction.East;
28 }
29 },
30 East
31 {
32 public Direction opposite()
33 {
34 return Direction.West;
35 }
36
37 public Direction left()
38 {
39 return Direction.North;
40 }
41
42 public Direction right()
43 {
44 return Direction.South;
45 }
46 },
47 South
48 {
49 public Direction opposite()
50 {
51 return Direction.North;
52 }
53
54 public Direction left()
55 {
56 return Direction.East;
57 }
58
59 public Direction right()
60 {
61 return Direction.West;
62 }
63 },
64 West
65 {
66 public Direction opposite()
67 {
68 return Direction.East;
69 }
70
71 public Direction left()
72 {
73 return Direction.South;
74 }
75
76 public Direction right()
77 {
78 return Direction.North;
79 }
80 };
17 81
18 /** 82 /**
19 * TODO Find a way to serve the inverse of a Direction without using a 83 * Returns the direction opposite from the current one
20 * switch, which is apparently bad practice 84 * @return A Direction representing the wanted direction
21 */ 85 */
86 public abstract Direction opposite();
22 87
23 /** 88 /**
24 * Returns the direction opposite from the current one 89 * Returns the direction counterclockwise from the current one
25 * @return A Direction representing the opposite direction 90 * @return A Direction representing the wanted direction
26 */ 91 */
27 public Direction oppositeDirection() 92 public abstract Direction left();
28 { 93
29 switch (this) 94 /**
30 { 95 * Returns the direction clockwise from the current one
31 case North: return Direction.South; 96 * @return A Direction representing the wanted direction
32 case West: return Direction.East; 97 */
33 case South: return Direction.North; 98 public abstract Direction right();
34 case East: return Direction.West;
35 }
36
37 return null;
38 }
39} 99}
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);