summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java13
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java55
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java5
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java42
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java7
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java11
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java28
-rw-r--r--src/com/fourisland/fourpuzzle/util/Functions.java34
8 files changed, 147 insertions, 48 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index bcc2ed7..b17d7b3 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java
@@ -6,9 +6,9 @@
6package com.fourisland.fourpuzzle.gamestate.mapview; 6package com.fourisland.fourpuzzle.gamestate.mapview;
7 7
8import com.fourisland.fourpuzzle.*; 8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; 10import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
10import java.awt.Dimension; 11import java.awt.Dimension;
11import java.util.ArrayList;
12import java.util.HashMap; 12import java.util.HashMap;
13import java.util.Vector; 13import java.util.Vector;
14 14
@@ -41,19 +41,18 @@ public abstract class Map {
41 } 41 }
42 } 42 }
43 43
44 private ArrayList<LayerEvent> events = new ArrayList<LayerEvent>(); 44 private EventList events = new EventList();
45 public ArrayList<LayerEvent> getEvents() 45 public EventList getEvents()
46 { 46 {
47 return events; 47 return events;
48 } 48 }
49 public LayerEvent getEvent(String event) 49 public LayerEvent getEvent(String event)
50 { 50 {
51 int i=0; 51 for (LayerEvent ev : events)
52 for (i=0;i<events.size();i++)
53 { 52 {
54 if (events.get(i).getLabel().equals(event)) 53 if (ev.getLabel().equals(event))
55 { 54 {
56 return events.get(i); 55 return ev;
57 } 56 }
58 } 57 }
59 58
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 0e5ec44..6aeac83 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -13,10 +13,12 @@ import com.fourisland.fourpuzzle.Game;
13import com.fourisland.fourpuzzle.Layer; 13import com.fourisland.fourpuzzle.Layer;
14import com.fourisland.fourpuzzle.PuzzleApplication; 14import com.fourisland.fourpuzzle.PuzzleApplication;
15import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime; 15import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime;
16import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList;
16import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; 17import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
18import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
19import com.fourisland.fourpuzzle.util.Functions;
17import java.awt.Graphics2D; 20import java.awt.Graphics2D;
18import java.awt.event.KeyEvent; 21import java.awt.event.KeyEvent;
19import java.util.ArrayList;
20 22
21/** 23/**
22 * 24 *
@@ -67,7 +69,7 @@ public class MapViewGameState implements GameState {
67 debugWalkthrough = false; 69 debugWalkthrough = false;
68 } 70 }
69 71
70 if (!hero.isMoving()) 72 if (!hero.isMoving() && !MoveEventThread.isHeroMoving())
71 { 73 {
72 Direction toMove = null; 74 Direction toMove = null;
73 Boolean letsMove = false; 75 Boolean letsMove = false;
@@ -104,29 +106,22 @@ public class MapViewGameState implements GameState {
104 106
105 if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) 107 if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE))
106 { 108 {
107 int i=0; 109 for (LayerEvent ev : currentMap.getEvents())
108 for (i=0;i<currentMap.getEvents().size();i++)
109 { 110 {
110 LayerEvent ev = currentMap.getEvents().get(i);
111
112 if (ev.getCalltime() == EventCallTime.PushKey) 111 if (ev.getCalltime() == EventCallTime.PushKey)
113 { 112 {
114 if ((hero.getDirection() == Direction.North) && (ev.getLocation().x == hero.getLocation().x) && (ev.getLocation().y == (hero.getLocation().y - 1))) 113 if (ev.getLayer() == Layer.Middle)
115 {
116 ev.setDirection(Direction.South);
117 ev.getCallback().run();
118 } else if ((hero.getDirection() == Direction.West) && (ev.getLocation().x == (hero.getLocation().x - 1)) && (ev.getLocation().y == hero.getLocation().y))
119 {
120 ev.setDirection(Direction.East);
121 ev.getCallback().run();
122 } else if ((hero.getDirection() == Direction.South) && (ev.getLocation().x == hero.getLocation().x) && (ev.getLocation().y == (hero.getLocation().y + 1)))
123 { 114 {
124 ev.setDirection(Direction.North); 115 if (Functions.isFacing(hero, ev))
125 ev.getCallback().run(); 116 {
126 } else if ((hero.getDirection() == Direction.East) && (ev.getLocation().x == (hero.getLocation().x + 1)) && (ev.getLocation().y == hero.getLocation().y)) 117 ev.setDirection(Functions.oppositeDirection(hero.getDirection()));
127 { 118 ev.getCallback().activate();
128 ev.setDirection(Direction.West); 119 }
129 ev.getCallback().run(); 120 } else {
121 if (ev.getLocation().equals(hero.getLocation()))
122 {
123 ev.getCallback().activate();
124 }
130 } 125 }
131 } 126 }
132 } 127 }
@@ -145,14 +140,16 @@ public class MapViewGameState implements GameState {
145 hero.processMoving(); 140 hero.processMoving();
146 } 141 }
147 142
148 int i=0; 143 for (LayerEvent ev : currentMap.getEvents())
149 for (i=0;i<currentMap.getEvents().size();i++)
150 { 144 {
151 if (!currentMap.getEvents().get(i).isMoving()) 145 if (!ev.isMoving())
152 { 146 {
153 currentMap.getEvents().get(i).startMoving(currentMap); 147 if (!MoveEventThread.isOtherMoving(ev))
148 {
149 ev.startMoving(currentMap);
150 }
154 } else { 151 } else {
155 currentMap.getEvents().get(i).processMoving(); 152 ev.processMoving();
156 } 153 }
157 } 154 }
158 } 155 }
@@ -183,10 +180,10 @@ public class MapViewGameState implements GameState {
183 mv.draw(g, true);*/ 180 mv.draw(g, true);*/
184 Game.getSaveFile().getHero().render(g); 181 Game.getSaveFile().getHero().render(g);
185 182
186 ArrayList<LayerEvent> events = currentMap.getEvents(); 183 EventList events = currentMap.getEvents();
187 for (i=0;i<events.size();i++) 184 for (LayerEvent event : events)
188 { 185 {
189 events.get(i).render(g); 186 event.render(g);
190 } 187 }
191 188
192 for (i=0;i<currentMap.getMapData().size();i++) 189 for (i=0;i<currentMap.getMapData().size();i++)
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java index daca678..3bbde17 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java
@@ -22,4 +22,9 @@ public abstract class EventCall extends SpecialEvent implements Runnable {
22 22
23 public abstract void run(); 23 public abstract void run();
24 24
25 public void activate()
26 {
27 new Thread(this, "Special Event").start();
28 }
29
25} 30}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java new file mode 100644 index 0000000..a10aadc --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java
@@ -0,0 +1,42 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import java.util.Vector;
9
10/**
11 *
12 * @author hatkirby
13 */
14public class EventList extends Vector<LayerEvent> {
15
16 @Override
17 public boolean add(LayerEvent o)
18 {
19 if (o.getLabel().equals("Unlabelled"))
20 {
21 o.setLabel("Event" + (this.size()+1));
22 } else {
23 if ( (o.getLabel().equals("Hero")) ||
24 (o.getLabel().equals("Unlabelled")) ||
25 (o.getLabel().equals("")))
26 {
27 return false;
28 }
29
30 for (Event ev : this)
31 {
32 if (ev.getLabel().equals(o.getLabel()))
33 {
34 return false;
35 }
36 }
37 }
38
39 return super.add(o);
40 }
41
42}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 92cfd54..b67f2aa 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java
@@ -27,6 +27,7 @@ public class LayerEvent implements Event {
27 { 27 {
28 location = new Point(x,y); 28 location = new Point(x,y);
29 events = new ArrayList<PossibleEvent>(); 29 events = new ArrayList<PossibleEvent>();
30 label = "Unlabelled";
30 } 31 }
31 32
32 /** Create a new Event instance 33 /** Create a new Event instance
@@ -204,4 +205,8 @@ public class LayerEvent implements Event {
204 return getPossibleEvent().getCallback(); 205 return getPossibleEvent().getCallback();
205 } 206 }
206 207
207} 208 public void setLabel(String string) {
209 this.label = string;
210 }
211
212} \ 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 26f89c7..121bbe8 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -6,10 +6,9 @@
6package com.fourisland.fourpuzzle.gamestate.mapview.event; 6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7 7
8import com.fourisland.fourpuzzle.*; 8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; 10import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent;
10import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; 11import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
11import java.util.concurrent.BrokenBarrierException;
12import java.util.concurrent.CyclicBarrier;
13import java.util.logging.Level; 12import java.util.logging.Level;
14import java.util.logging.Logger; 13import java.util.logging.Logger;
15 14
@@ -102,18 +101,18 @@ public class SpecialEvent {
102 */ 101 */
103 public void MoveEvent(MoveEvent[] actions) 102 public void MoveEvent(MoveEvent[] actions)
104 { 103 {
105 MoveEvent(actions, Game.getHeroEvent()); 104 new Thread(new MoveEventThread(Game.getHeroEvent(), actions)).start();
106 } 105 }
107 106
108 /** 107 /**
109 * Performs actions on an event 108 * Performs actions on an event
110 * 109 *
111 * @param actions An array of MoveEvents to perform on the event 110 * @param actions An array of MoveEvents to perform on the event
112 * @param ev The event to act upon 111 * @param label The label of the event to act upon
113 */ 112 */
114 public void MoveEvent(MoveEvent[] actions, Event ev) 113 public void MoveEvent(MoveEvent[] actions, String label)
115 { 114 {
116 new Thread(new MoveEventThread(ev, actions)).start(); 115 new Thread(new MoveEventThread(((MapViewGameState) Game.getGameState()).getCurrentMap().getEvent(label), actions)).start();
117 } 116 }
118 117
119 /** 118 /**
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 4c16197..d6971f3 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java
@@ -5,9 +5,12 @@
5 5
6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; 6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove;
7 7
8import com.fourisland.fourpuzzle.Game;
8import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; 9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
10import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
11import java.util.List;
12import java.util.Vector;
9import java.util.concurrent.CountDownLatch; 13import java.util.concurrent.CountDownLatch;
10import java.util.concurrent.CyclicBarrier;
11import java.util.logging.Level; 14import java.util.logging.Level;
12import java.util.logging.Logger; 15import java.util.logging.Logger;
13 16
@@ -19,6 +22,7 @@ public class MoveEventThread implements Runnable {
19 22
20 public static volatile CountDownLatch moveEventWait = new CountDownLatch(0); 23 public static volatile CountDownLatch moveEventWait = new CountDownLatch(0);
21 public static volatile int countMoveEventThreads = 0; 24 public static volatile int countMoveEventThreads = 0;
25 public static volatile List<Event> events = new Vector<Event>();
22 26
23 Event ev; 27 Event ev;
24 MoveEvent[] actions; 28 MoveEvent[] actions;
@@ -29,22 +33,36 @@ public class MoveEventThread implements Runnable {
29 this.actions = actions; 33 this.actions = actions;
30 } 34 }
31 35
32 public void run() { 36 public void run()
37 {
38 events.add(ev);
39
33 MoveEventThread.countMoveEventThreads++; 40 MoveEventThread.countMoveEventThreads++;
34 moveEventWait = new CountDownLatch(countMoveEventThreads); 41 moveEventWait = new CountDownLatch(countMoveEventThreads);
35 42
36 int i=0; 43 for (MoveEvent action : actions)
37 for (i=0;i<actions.length;i++)
38 { 44 {
39 try { 45 try {
40 actions[i].doAction(ev); 46 action.doAction(ev);
41 } catch (Exception ex) { 47 } catch (Exception ex) {
42 Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); 48 Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex);
43 } 49 }
44 } 50 }
45 51
52 events.remove(ev);
53
46 MoveEventThread.countMoveEventThreads--; 54 MoveEventThread.countMoveEventThreads--;
47 moveEventWait.countDown(); 55 moveEventWait.countDown();
48 } 56 }
57
58 public static boolean isHeroMoving()
59 {
60 return (events.contains(Game.getHeroEvent()));
61 }
62
63 public static boolean isOtherMoving(LayerEvent event)
64 {
65 return (events.contains(event));
66 }
49 67
50} 68}
diff --git a/src/com/fourisland/fourpuzzle/util/Functions.java b/src/com/fourisland/fourpuzzle/util/Functions.java index 5eb70cd..d1995f9 100644 --- a/src/com/fourisland/fourpuzzle/util/Functions.java +++ b/src/com/fourisland/fourpuzzle/util/Functions.java
@@ -5,6 +5,8 @@
5 5
6package com.fourisland.fourpuzzle.util; 6package com.fourisland.fourpuzzle.util;
7 7
8import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
8import com.fourisland.fourpuzzle.gamestate.mapview.event.PossibleEvent; 10import com.fourisland.fourpuzzle.gamestate.mapview.event.PossibleEvent;
9 11
10/** 12/**
@@ -27,5 +29,37 @@ public class Functions {
27 29
28 return false; 30 return false;
29 } 31 }
32
33 public static boolean isFacing(Event ev1, Event ev2) throws Exception
34 {
35 if ((ev1.getDirection() == Direction.North) && (ev2.getLocation().x == ev1.getLocation().x) && (ev2.getLocation().y == (ev1.getLocation().y - 1)))
36 {
37 return true;
38 } else if ((ev1.getDirection() == Direction.West) && (ev2.getLocation().x == (ev1.getLocation().x - 1)) && (ev2.getLocation().y == ev1.getLocation().y))
39 {
40 return true;
41 } else if ((ev1.getDirection() == Direction.South) && (ev2.getLocation().x == ev1.getLocation().x) && (ev2.getLocation().y == (ev1.getLocation().y + 1)))
42 {
43 return true;
44 } else if ((ev1.getDirection() == Direction.East) && (ev2.getLocation().x == (ev1.getLocation().x + 1)) && (ev2.getLocation().y == ev1.getLocation().y))
45 {
46 return true;
47 }
48
49 return false;
50 }
51
52 public static Direction oppositeDirection(Direction dir)
53 {
54 switch (dir)
55 {
56 case North: return Direction.South;
57 case West: return Direction.East;
58 case South: return Direction.North;
59 case East: return Direction.West;
60 }
61
62 return null;
63 }
30 64
31} 65}