diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-27 14:28:43 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-27 14:28:43 -0500 |
commit | 9ca53b553cfaf488f7e8e678721bf9e655fa377e (patch) | |
tree | fa110584eb1b083fbe0e005ab9f235f3a8f931f1 /src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | |
parent | cd6b39590b8aced78fc2f6ed0c345fb9af1960c0 (diff) | |
download | fourpuzzle-9ca53b553cfaf488f7e8e678721bf9e655fa377e.tar.gz fourpuzzle-9ca53b553cfaf488f7e8e678721bf9e655fa377e.tar.bz2 fourpuzzle-9ca53b553cfaf488f7e8e678721bf9e655fa377e.zip |
Fixed "walk-thru-me" bug
Previously, Map's checkForCollision did not properly check collision and would allow an event to initiate movement to a location another event was already moving to (but wasn't at yet).
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java')
-rw-r--r-- | src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index 3e9c717..62270bf 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | |||
@@ -20,7 +20,7 @@ public abstract class Map { | |||
20 | 20 | ||
21 | public abstract void initalize(); | 21 | public abstract void initalize(); |
22 | 22 | ||
23 | public void initalize(Dimension size) | 23 | protected void initalize(Dimension size) |
24 | { | 24 | { |
25 | setSize(size); | 25 | setSize(size); |
26 | mapData = new Vector<HashMap<Integer,Integer>>(); | 26 | mapData = new Vector<HashMap<Integer,Integer>>(); |
@@ -31,7 +31,7 @@ public abstract class Map { | |||
31 | { | 31 | { |
32 | return size; | 32 | return size; |
33 | } | 33 | } |
34 | public void setSize(Dimension size) | 34 | private void setSize(Dimension size) |
35 | { | 35 | { |
36 | if ((size.width < 20) || (size.height < 15)) | 36 | if ((size.width < 20) || (size.height < 15)) |
37 | { | 37 | { |
@@ -58,7 +58,7 @@ public abstract class Map { | |||
58 | 58 | ||
59 | return null; | 59 | return null; |
60 | } | 60 | } |
61 | 61 | ||
62 | public boolean checkForCollision(int x, int y, Direction toMove) | 62 | public boolean checkForCollision(int x, int y, Direction toMove) |
63 | { | 63 | { |
64 | if ((toMove == Direction.North) && (y == 0)) | 64 | if ((toMove == Direction.North) && (y == 0)) |
@@ -75,48 +75,22 @@ public abstract class Map { | |||
75 | return true; | 75 | return true; |
76 | } | 76 | } |
77 | 77 | ||
78 | for (LayerEvent ev : events) | 78 | if ((toMove == Direction.North) && (checkForEventCollision(x, y-1))) |
79 | { | ||
80 | if (ev.getLayer() == Layer.Middle) | ||
81 | { | ||
82 | if ((ev.getLocation().y == (y - 1)) && (ev.getLocation().x == x) && (toMove == Direction.North)) | ||
83 | { | ||
84 | return true; | ||
85 | } | ||
86 | |||
87 | if ((ev.getLocation().x == (x - 1)) && (ev.getLocation().y == y) && (toMove == Direction.West)) | ||
88 | { | ||
89 | return true; | ||
90 | } | ||
91 | |||
92 | if ((ev.getLocation().y == (y + 1)) && (ev.getLocation().x == x) && (toMove == Direction.South)) | ||
93 | { | ||
94 | return true; | ||
95 | } | ||
96 | |||
97 | if ((ev.getLocation().x == (x + 1)) && (ev.getLocation().y == y) && (toMove == Direction.East)) | ||
98 | { | ||
99 | return true; | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | if ((Game.getHeroEvent().getLocation().y == (y - 1)) && (Game.getHeroEvent().getLocation().x == x) && (toMove == Direction.North)) | ||
105 | { | 79 | { |
106 | return true; | 80 | return true; |
107 | } | 81 | } |
108 | 82 | ||
109 | if ((Game.getHeroEvent().getLocation().x == (x - 1)) && (Game.getHeroEvent().getLocation().y == y) && (toMove == Direction.West)) | 83 | if ((toMove == Direction.West) && (checkForEventCollision(x-1, y))) |
110 | { | 84 | { |
111 | return true; | 85 | return true; |
112 | } | 86 | } |
113 | 87 | ||
114 | if ((Game.getHeroEvent().getLocation().y == (y + 1)) && (Game.getHeroEvent().getLocation().x == x) && (toMove == Direction.South)) | 88 | if ((toMove == Direction.South) && (checkForEventCollision(x, y+1))) |
115 | { | 89 | { |
116 | return true; | 90 | return true; |
117 | } | 91 | } |
118 | 92 | ||
119 | if ((Game.getHeroEvent().getLocation().x == (x + 1)) && (Game.getHeroEvent().getLocation().y == y) && (toMove == Direction.East)) | 93 | if ((toMove == Direction.East) && (checkForEventCollision(x+1, y))) |
120 | { | 94 | { |
121 | return true; | 95 | return true; |
122 | } | 96 | } |
@@ -156,6 +130,27 @@ public abstract class Map { | |||
156 | 130 | ||
157 | return false; | 131 | return false; |
158 | } | 132 | } |
133 | |||
134 | private boolean checkForEventCollision(int x, int y) | ||
135 | { | ||
136 | for (LayerEvent ev : events) | ||
137 | { | ||
138 | if (ev.getLayer() == Layer.Middle) | ||
139 | { | ||
140 | if (ev.isOccupyingSpace(x, y)) | ||
141 | { | ||
142 | return true; | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
147 | if (Game.getHeroEvent().isOccupyingSpace(x, y)) | ||
148 | { | ||
149 | return true; | ||
150 | } | ||
151 | |||
152 | return false; | ||
153 | } | ||
159 | 154 | ||
160 | private String chipSet; | 155 | private String chipSet; |
161 | public String getChipSet() { | 156 | public String getChipSet() { |