summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-03-26 09:28:21 -0400
committerStarla Insigna <hatkirby@fourisland.com>2009-03-26 09:28:21 -0400
commit2c40ab0439f7bbb0dcca1f7c833f055e9cb17bfc (patch)
tree7fd425192f9438956b1ae282723279c6deacf4e9 /src/com/fourisland
parent82cfc90465c6e85bc0b73a55ea00e7a70438d67f (diff)
downloadfourpuzzle-2c40ab0439f7bbb0dcca1f7c833f055e9cb17bfc.tar.gz
fourpuzzle-2c40ab0439f7bbb0dcca1f7c833f055e9cb17bfc.tar.bz2
fourpuzzle-2c40ab0439f7bbb0dcca1f7c833f055e9cb17bfc.zip
Engine: Seperated move direction from facing direction HEAD master
Diffstat (limited to 'src/com/fourisland')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index e9482f9..10b40f3 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java
@@ -43,6 +43,7 @@ public abstract class AbstractEvent implements Event {
43 } 43 }
44 44
45 private int moveTimer; 45 private int moveTimer;
46 private Direction moveDirection;
46 public boolean startMoving(Direction toMove) 47 public boolean startMoving(Direction toMove)
47 { 48 {
48 /* If the event is already moving (sometimes it manages to slip through 49 /* If the event is already moving (sometimes it manages to slip through
@@ -52,24 +53,19 @@ public abstract class AbstractEvent implements Event {
52 return false; 53 return false;
53 } 54 }
54 55
55 /* Attempt to turn in the correct direction and then check if it was 56 /* Attempt to face the event in the specified direction
56 * done. It could fail in certain cases which would mean the event
57 * shouldn't move, for instance, if a LayerEvent's AnimationType was
58 * FixedGraphic.
59 * 57 *
60 * There is a slight problem with this, however. Currently, if the 58 * This may fail due to an incompatiable LayerEvent's AnimationType, but
61 * AnimationType is FixedGraphic, but the event is already facing the 59 * moving will work regardless of this */
62 * correct direction, the event will move anyway, despite being fixed */
63 setDirection(toMove); 60 setDirection(toMove);
64 if (getDirection() != toMove)
65 {
66 return false;
67 }
68 61
69 /* Make sure that there are no present obstructions on the map in the 62 /* Make sure that there are no present obstructions on the map in the
70 * specified direction */ 63 * specified direction */
71 if (!getParentMap().checkForCollision(this, toMove)) 64 if (!getParentMap().checkForCollision(this, toMove))
72 { 65 {
66 // Face the event in the correct direction
67 moveDirection = toMove;
68
73 // Start the stepping animation 69 // Start the stepping animation
74 setAnimationStep(2); 70 setAnimationStep(2);
75 71
@@ -80,7 +76,7 @@ public abstract class AbstractEvent implements Event {
80 setMoving(true); 76 setMoving(true);
81 77
82 return true; 78 return true;
83 } else { 79 } else {
84 return false; 80 return false;
85 } 81 }
86 } 82 }
@@ -104,7 +100,7 @@ public abstract class AbstractEvent implements Event {
104 setMoving(false); 100 setMoving(false);
105 101
106 // Move the event to the correct location 102 // Move the event to the correct location
107 setLocation(getDirection().to(getLocation())); 103 setLocation(moveDirection.to(getLocation()));
108 } else if (moveTimer <= (getMoveSpeed().getSpeed() / 2)) 104 } else if (moveTimer <= (getMoveSpeed().getSpeed() / 2))
109 { 105 {
110 // If movement is half-complete, advance its animation 106 // If movement is half-complete, advance its animation
@@ -127,7 +123,7 @@ public abstract class AbstractEvent implements Event {
127 * (if it's moving at all) */ 123 * (if it's moving at all) */
128 if (isMoving()) 124 if (isMoving())
129 { 125 {
130 Point loc = getDirection().to(getLocation()); 126 Point loc = moveDirection.to(getLocation());
131 if ((loc.x == x) && (loc.y == y)) 127 if ((loc.x == x) && (loc.y == y))
132 { 128 {
133 return true; 129 return true;
@@ -180,10 +176,10 @@ public abstract class AbstractEvent implements Event {
180 { 176 {
181 if (isMoving()) 177 if (isMoving())
182 { 178 {
183 if (getDirection() == Direction.West) 179 if (moveDirection == Direction.West)
184 { 180 {
185 return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()))); 181 return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())));
186 } else if (getDirection() == Direction.East) 182 } else if (moveDirection == Direction.East)
187 { 183 {
188 return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())); 184 return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()));
189 } 185 }
@@ -196,10 +192,10 @@ public abstract class AbstractEvent implements Event {
196 { 192 {
197 if (isMoving()) 193 if (isMoving())
198 { 194 {
199 if (getDirection() == Direction.North) 195 if (moveDirection == Direction.North)
200 { 196 {
201 return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()))); 197 return -(Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())));
202 } else if (getDirection() == Direction.South) 198 } else if (moveDirection == Direction.South)
203 { 199 {
204 return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed())); 200 return Math.round((getMoveSpeed().getSpeed() - moveTimer) * (16F / getMoveSpeed().getSpeed()));
205 } 201 }