diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-03-08 17:59:07 -0400 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-03-08 17:59:07 -0400 |
commit | 5c0f253d5d59a042f57c4cb209092729ece8a310 (patch) | |
tree | 8bac121cbf80eef8ebb50ff0c166a2788607fbef /src/com/fourisland/fourpuzzle/gamestate/mapview/event | |
parent | df5aafb66f429d968323b55c17d42ba0c6a62bbc (diff) | |
download | fourpuzzle-5c0f253d5d59a042f57c4cb209092729ece8a310.tar.gz fourpuzzle-5c0f253d5d59a042f57c4cb209092729ece8a310.tar.bz2 fourpuzzle-5c0f253d5d59a042f57c4cb209092729ece8a310.zip |
Engine: Commented a lot of code
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/event')
-rwxr-xr-x | src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java | 41 | ||||
-rwxr-xr-x | src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java | 2 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index f859739..e9482f9 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java | |||
@@ -7,7 +7,6 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; | |||
7 | 7 | ||
8 | import com.fourisland.fourpuzzle.Direction; | 8 | import com.fourisland.fourpuzzle.Direction; |
9 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | 9 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; |
10 | import com.fourisland.fourpuzzle.util.Functions; | ||
11 | import com.fourisland.fourpuzzle.util.Interval; | 10 | import com.fourisland.fourpuzzle.util.Interval; |
12 | import java.awt.Point; | 11 | import java.awt.Point; |
13 | import java.util.ArrayList; | 12 | import java.util.ArrayList; |
@@ -46,22 +45,38 @@ public abstract class AbstractEvent implements Event { | |||
46 | private int moveTimer; | 45 | private int moveTimer; |
47 | public boolean startMoving(Direction toMove) | 46 | public boolean startMoving(Direction toMove) |
48 | { | 47 | { |
48 | /* If the event is already moving (sometimes it manages to slip through | ||
49 | * the other filters), simply return without doing anything */ | ||
49 | if (isMoving()) | 50 | if (isMoving()) |
50 | { | 51 | { |
51 | return false; | 52 | return false; |
52 | } | 53 | } |
53 | 54 | ||
55 | /* Attempt to turn in the correct direction and then check if it was | ||
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 | * | ||
60 | * There is a slight problem with this, however. Currently, if the | ||
61 | * AnimationType is FixedGraphic, but the event is already facing the | ||
62 | * correct direction, the event will move anyway, despite being fixed */ | ||
54 | setDirection(toMove); | 63 | setDirection(toMove); |
55 | |||
56 | if (getDirection() != toMove) | 64 | if (getDirection() != toMove) |
57 | { | 65 | { |
58 | return false; | 66 | return false; |
59 | } | 67 | } |
60 | 68 | ||
69 | /* Make sure that there are no present obstructions on the map in the | ||
70 | * specified direction */ | ||
61 | if (!getParentMap().checkForCollision(this, toMove)) | 71 | if (!getParentMap().checkForCollision(this, toMove)) |
62 | { | 72 | { |
73 | // Start the stepping animation | ||
63 | setAnimationStep(2); | 74 | setAnimationStep(2); |
75 | |||
76 | // Ask the event's MoveSpeed for the length of the animation | ||
64 | moveTimer = getMoveSpeed().getSpeed(); | 77 | moveTimer = getMoveSpeed().getSpeed(); |
78 | |||
79 | // Set the moving flag | ||
65 | setMoving(true); | 80 | setMoving(true); |
66 | 81 | ||
67 | return true; | 82 | return true; |
@@ -75,17 +90,25 @@ public abstract class AbstractEvent implements Event { | |||
75 | { | 90 | { |
76 | if (isMoving()) | 91 | if (isMoving()) |
77 | { | 92 | { |
93 | // Movement should be processed every half tick | ||
78 | if (in.isElapsed()) | 94 | if (in.isElapsed()) |
79 | { | 95 | { |
96 | // Decrement the move timer | ||
80 | moveTimer--; | 97 | moveTimer--; |
98 | |||
81 | if (moveTimer <= 0) | 99 | if (moveTimer <= 0) |
82 | { | 100 | { |
101 | /* If movement has finished, stop the animation and unset | ||
102 | * the moving flag */ | ||
83 | setAnimationStep(1); | 103 | setAnimationStep(1); |
84 | setMoving(false); | 104 | setMoving(false); |
105 | |||
106 | // Move the event to the correct location | ||
85 | setLocation(getDirection().to(getLocation())); | 107 | setLocation(getDirection().to(getLocation())); |
86 | } else if (moveTimer <= (getMoveSpeed().getSpeed() / 2)) | 108 | } else if (moveTimer <= (getMoveSpeed().getSpeed() / 2)) |
87 | { | 109 | { |
88 | setAnimationStep(0); | 110 | // If movement is half-complete, advance its animation |
111 | setAnimationStep(0); | ||
89 | } | 112 | } |
90 | } | 113 | } |
91 | } | 114 | } |
@@ -93,14 +116,22 @@ public abstract class AbstractEvent implements Event { | |||
93 | 116 | ||
94 | public boolean isOccupyingSpace(int x, int y) | 117 | public boolean isOccupyingSpace(int x, int y) |
95 | { | 118 | { |
119 | // Check if the event occupies the given location | ||
96 | if (getLocation().equals(new Point(x,y))) | 120 | if (getLocation().equals(new Point(x,y))) |
97 | { | 121 | { |
98 | return true; | 122 | return true; |
99 | } | 123 | } |
100 | 124 | ||
101 | if (Functions.isMovingTo(this, x, y)) | 125 | /* Because a moving event technically occupies two locations, we also |
126 | * need to check if the given location is where the event is moving to | ||
127 | * (if it's moving at all) */ | ||
128 | if (isMoving()) | ||
102 | { | 129 | { |
103 | return true; | 130 | Point loc = getDirection().to(getLocation()); |
131 | if ((loc.x == x) && (loc.y == y)) | ||
132 | { | ||
133 | return true; | ||
134 | } | ||
104 | } | 135 | } |
105 | 136 | ||
106 | return false; | 137 | return false; |
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java index 233c415..d05a3d8 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java | |||
@@ -39,7 +39,7 @@ public class MoveEventThread implements Runnable { | |||
39 | 39 | ||
40 | public void start() | 40 | public void start() |
41 | { | 41 | { |
42 | for (Future f : eventThreads) | 42 | for (Future f : new ArrayList<Future>(eventThreads)) |
43 | { | 43 | { |
44 | if (f.isDone()) | 44 | if (f.isDone()) |
45 | { | 45 | { |