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/gamestate/mapview/Map.java67
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java8
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java2
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java20
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java16
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java14
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java1
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java18
-rw-r--r--src/com/fourisland/fourpuzzle/util/Functions.java30
9 files changed, 133 insertions, 43 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() {
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 3d8d15d..48653c0 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -159,6 +159,14 @@ public class MapViewGameState implements GameState {
159 159
160 public void render(Graphics2D g) 160 public void render(Graphics2D g)
161 { 161 {
162 /* TODO Add code that checks to see if the map has been switched
163 * or if the hero has moved in such a way so as to move the
164 * viewpoint. If one or more of these conditions are filled, the
165 * already existing below code should run along with a snippet that
166 * saves a cache of the current viewpoint. If not, the previously
167 * mentioned cache should be displayed rather than re-rendering the
168 * map.
169 */
162 ChipSet chipSet = ChipSet.getChipSet(currentMap.getChipSet()); 170 ChipSet chipSet = ChipSet.getChipSet(currentMap.getChipSet());
163 int i,x,y; 171 int i,x,y;
164 for (i=0;i<currentMap.getMapData().size();i++) 172 for (i=0;i<currentMap.getMapData().size();i++)
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index fbcfd7a..71b507f 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java
@@ -32,4 +32,6 @@ public interface Event {
32 public void startMoving(Direction direction); 32 public void startMoving(Direction direction);
33 33
34 public Layer getLayer(); 34 public Layer getLayer();
35
36 public boolean isOccupyingSpace(int x, int y);
35} 37}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index 50e16c8..6e8c359 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java
@@ -12,6 +12,7 @@ import com.fourisland.fourpuzzle.Direction;
12import com.fourisland.fourpuzzle.Game; 12import com.fourisland.fourpuzzle.Game;
13import com.fourisland.fourpuzzle.GameCharacter; 13import com.fourisland.fourpuzzle.GameCharacter;
14import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; 14import com.fourisland.fourpuzzle.gamestate.mapview.CharSet;
15import com.fourisland.fourpuzzle.util.Functions;
15 16
16/** 17/**
17 * 18 *
@@ -65,6 +66,10 @@ public class HeroEvent implements Event {
65 } 66 }
66 } 67 }
67 68
69 /* TODO Change the specification of GameCharacter
70 * to require an EventGraphic instead of a graphic name
71 * and offset
72 */
68 GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); 73 GameCharacter toDraw = Game.getSaveFile().getParty().getLeader();
69 if (!toDraw.getGraphic().equals("blank")) 74 if (!toDraw.getGraphic().equals("blank"))
70 { 75 {
@@ -147,5 +152,20 @@ public class HeroEvent implements Event {
147 { 152 {
148 return Layer.Middle; 153 return Layer.Middle;
149 } 154 }
155
156 public boolean isOccupyingSpace(int x, int y)
157 {
158 if (getLocation().equals(new Point(x,y)))
159 {
160 return true;
161 }
162
163 if (Functions.isMovingTo(this, x, y))
164 {
165 return true;
166 }
167
168 return false;
169 }
150 170
151} 171}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 05192ce..4f8b51c 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java
@@ -11,6 +11,7 @@ import java.awt.Point;
11import java.util.ArrayList; 11import java.util.ArrayList;
12import com.fourisland.fourpuzzle.Direction; 12import com.fourisland.fourpuzzle.Direction;
13import com.fourisland.fourpuzzle.gamestate.mapview.Map; 13import com.fourisland.fourpuzzle.gamestate.mapview.Map;
14import com.fourisland.fourpuzzle.util.Functions;
14 15
15/** 16/**
16 * 17 *
@@ -209,4 +210,19 @@ public class LayerEvent implements Event {
209 this.label = string; 210 this.label = string;
210 } 211 }
211 212
213 public boolean isOccupyingSpace(int x, int y)
214 {
215 if (getLocation().equals(new Point(x,y)))
216 {
217 return true;
218 }
219
220 if (Functions.isMovingTo(this, x, y))
221 {
222 return true;
223 }
224
225 return false;
226 }
227
212} \ No newline at end of file 228} \ No newline at end of file
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 077f42e..52b75de 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -17,6 +17,14 @@ import java.util.logging.Logger;
17 * @author hatkirby 17 * @author hatkirby
18 */ 18 */
19public class SpecialEvent { 19public class SpecialEvent {
20
21 /* TODO Create a manager for SpecialEvent action threads that
22 * controls when they are executed and allows MapViewGameState
23 * to poll it to see if it is currently managing any action
24 * threads. If it is, MapViewGameState should be able to prevent
25 * certain actions from occuring (unless the action thread is
26 * ParallelProcess) such as keyboard input.
27 */
20 28
21 /** 29 /**
22 * Display a message on the screen. 30 * Display a message on the screen.
@@ -120,11 +128,7 @@ public class SpecialEvent {
120 */ 128 */
121 public void MoveEventWait() 129 public void MoveEventWait()
122 { 130 {
123 try { 131 MoveEventThread.moveAll();
124 MoveEventThread.moveEventWait.await();
125 } catch (InterruptedException ex) {
126 Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex);
127 }
128 } 132 }
129 133
130 /** 134 /**
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java index 5d5822e..7b9ee0c 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java
@@ -13,6 +13,7 @@ import com.fourisland.fourpuzzle.Direction;
13 */ 13 */
14public interface MovementType { 14public interface MovementType {
15 15
16 // TODO Rename the following method to getNextDirection
16 public Direction startMoving(); 17 public Direction startMoving();
17 18
18} 19}
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 ab160f1..2ee4dca 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java
@@ -20,9 +20,10 @@ import java.util.logging.Logger;
20 */ 20 */
21public class MoveEventThread implements Runnable { 21public class MoveEventThread implements Runnable {
22 22
23 public static volatile CountDownLatch moveEventWait = new CountDownLatch(0);
24 public static volatile int countMoveEventThreads = 0; 23 public static volatile int countMoveEventThreads = 0;
25 public static volatile List<Event> events = new Vector<Event>(); 24
25 static volatile List<Event> events = new Vector<Event>();
26 static volatile CountDownLatch moveEventWait = new CountDownLatch(0);
26 27
27 Event ev; 28 Event ev;
28 MoveEvent[] actions; 29 MoveEvent[] actions;
@@ -51,6 +52,10 @@ public class MoveEventThread implements Runnable {
51 moveEventWait.countDown(); 52 moveEventWait.countDown();
52 } 53 }
53 54
55 /* TODO Rename the two following methods (isHeroMoving and isOtherMoving)
56 * to isHeroActive and isOtherActive respectively.
57 */
58
54 public static boolean isHeroMoving() 59 public static boolean isHeroMoving()
55 { 60 {
56 return (events.contains(Game.getHeroEvent())); 61 return (events.contains(Game.getHeroEvent()));
@@ -60,5 +65,14 @@ public class MoveEventThread implements Runnable {
60 { 65 {
61 return (events.contains(event)); 66 return (events.contains(event));
62 } 67 }
68
69 public static void moveAll()
70 {
71 try {
72 moveEventWait.await();
73 } catch (InterruptedException ex) {
74 Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex);
75 }
76 }
63 77
64} 78}
diff --git a/src/com/fourisland/fourpuzzle/util/Functions.java b/src/com/fourisland/fourpuzzle/util/Functions.java index 038ca46..9966a2f 100644 --- a/src/com/fourisland/fourpuzzle/util/Functions.java +++ b/src/com/fourisland/fourpuzzle/util/Functions.java
@@ -48,6 +48,36 @@ public class Functions {
48 48
49 return false; 49 return false;
50 } 50 }
51
52 public static boolean isMovingTo(Event ev, int x, int y)
53 {
54 if (ev.isMoving() == false)
55 {
56 return false;
57 }
58
59 if ((ev.getDirection() == Direction.North) && ((ev.getLocation().y-1) == y) && (ev.getLocation().x == x))
60 {
61 return true;
62 }
63
64 if ((ev.getDirection() == Direction.West) && (ev.getLocation().y == y) && ((ev.getLocation().x-1) == x))
65 {
66 return true;
67 }
68
69 if ((ev.getDirection() == Direction.South) && ((ev.getLocation().y+1) == y) && (ev.getLocation().x == x))
70 {
71 return true;
72 }
73
74 if ((ev.getDirection() == Direction.East) && (ev.getLocation().y == y) && ((ev.getLocation().x+1) == x))
75 {
76 return true;
77 }
78
79 return false;
80 }
51 81
52 public static Direction oppositeDirection(Direction dir) 82 public static Direction oppositeDirection(Direction dir)
53 { 83 {