diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-17 10:36:37 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-17 10:36:37 -0500 |
commit | 69b495c392bffe96dab97306a42466edd4b2474e (patch) | |
tree | 2adccc01f4027bcb76bbefee03bb6a9622ce3e00 /src/com/fourisland/fourpuzzle/gamestate | |
parent | 4c768483aecd687529b9abb48ed42950fabc886f (diff) | |
download | fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.gz fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.bz2 fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.zip |
Imported sources
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate')
35 files changed, 2168 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java new file mode 100644 index 0000000..ebff457 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Audio; | ||
9 | import com.fourisland.fourpuzzle.Display; | ||
10 | import com.fourisland.fourpuzzle.Game; | ||
11 | import com.fourisland.fourpuzzle.SaveFile; | ||
12 | import com.fourisland.fourpuzzle.transition.SquareTransition; | ||
13 | import com.fourisland.fourpuzzle.util.ObjectLoader; | ||
14 | import java.awt.Graphics2D; | ||
15 | import java.awt.event.KeyEvent; | ||
16 | import java.util.logging.Level; | ||
17 | import java.util.logging.Logger; | ||
18 | |||
19 | /** | ||
20 | * | ||
21 | * @author hatkirby | ||
22 | */ | ||
23 | public class GameOverGameState implements GameState { | ||
24 | |||
25 | public void initalize() throws Exception | ||
26 | { | ||
27 | Audio.playMusic("GameOver"); | ||
28 | } | ||
29 | |||
30 | public void deinitalize() throws Exception | ||
31 | { | ||
32 | Audio.stopMusic(); | ||
33 | } | ||
34 | |||
35 | public void processInput() throws Exception { | ||
36 | if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) | ||
37 | { | ||
38 | Game.setSaveFile(new SaveFile()); | ||
39 | //Display.transition(SquareTransition.class, this, new TitleScreenGameState()); | ||
40 | Display.transition(new SquareTransition(true), new Runnable() { | ||
41 | public void run() { | ||
42 | try { | ||
43 | Game.setGameState(new TitleScreenGameState()); | ||
44 | } catch (Exception ex) { | ||
45 | Logger.getLogger(GameOverGameState.class.getName()).log(Level.SEVERE, null, ex); | ||
46 | } | ||
47 | } | ||
48 | }); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | public void doGameCycle() throws Exception { | ||
53 | // Do nothing | ||
54 | } | ||
55 | |||
56 | public void render(Graphics2D g) throws Exception { | ||
57 | g.drawImage(ObjectLoader.getImage("Picture", "GameOver"), 0, 0, null); | ||
58 | } | ||
59 | |||
60 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameState.java new file mode 100644 index 0000000..362631d --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/GameState.java | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate; | ||
7 | |||
8 | import java.awt.Graphics2D; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public interface GameState { | ||
15 | |||
16 | public void initalize() throws Exception; | ||
17 | public void deinitalize() throws Exception; | ||
18 | |||
19 | public void processInput() throws Exception; | ||
20 | public void doGameCycle() throws Exception; | ||
21 | public void render(Graphics2D g) throws Exception; | ||
22 | |||
23 | } | ||
24 | |||
25 | /* | ||
26 | TitleScreen | ||
27 | MapView | ||
28 | Battle | ||
29 | GameOver | ||
30 | Menu | ||
31 | LoadFile | ||
32 | SaveFile | ||
33 | Transition | ||
34 | */ \ No newline at end of file | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java new file mode 100644 index 0000000..1f9c376 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.*; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; | ||
10 | import com.fourisland.fourpuzzle.util.ObjectLoader; | ||
11 | import java.awt.Graphics2D; | ||
12 | import java.awt.event.KeyEvent; | ||
13 | |||
14 | /** | ||
15 | * | ||
16 | * @author hatkirby | ||
17 | */ | ||
18 | public class TitleScreenGameState implements GameState { | ||
19 | |||
20 | public void initalize() throws Exception | ||
21 | { | ||
22 | Audio.playMusic("Opening"); | ||
23 | } | ||
24 | |||
25 | public void deinitalize() throws Exception | ||
26 | { | ||
27 | Audio.stopMusic(); | ||
28 | } | ||
29 | |||
30 | public void processInput() throws Exception { | ||
31 | if (Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) | ||
32 | { | ||
33 | Game.setSaveFile(new SaveFile()); | ||
34 | Game.setGameState(new MapViewGameState("TestMap", 1, 2)); | ||
35 | //Game.setGameState(new SquareTransition(this, new MapViewGameState("TestMap", 0, 0))); | ||
36 | //Game.setGameState(new TransitionGameState(this, this)); | ||
37 | //Game.setGameState(new GameOverGameState()); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | public void doGameCycle() throws Exception { | ||
42 | // Do nothing, yet | ||
43 | } | ||
44 | |||
45 | public void render(Graphics2D g) throws Exception { | ||
46 | g.drawImage(ObjectLoader.getImage("Picture", "Title"), 0, 0, null); | ||
47 | } | ||
48 | |||
49 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java new file mode 100644 index 0000000..b6e23d6 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.*; | ||
9 | import com.fourisland.fourpuzzle.util.ObjectLoader; | ||
10 | import java.awt.image.BufferedImage; | ||
11 | |||
12 | /** | ||
13 | * | ||
14 | * @author hatkirby | ||
15 | */ | ||
16 | public class CharSet { | ||
17 | |||
18 | private BufferedImage charSetImage; | ||
19 | |||
20 | private CharSet() | ||
21 | { | ||
22 | } | ||
23 | |||
24 | public BufferedImage getImage(int offset, Direction direction, int step) | ||
25 | { | ||
26 | int sx = ((offset % 4) * 72) + (step * 24); | ||
27 | int sy = ((offset / 4) * 128) + (direction.ordinal() * 32); | ||
28 | |||
29 | return charSetImage.getSubimage(sx, sy, 24, 32); | ||
30 | } | ||
31 | |||
32 | public static CharSet getCharSet(String charSet) throws Exception { | ||
33 | CharSet temp = new CharSet(); | ||
34 | temp.charSetImage = ObjectLoader.getImage("CharSet", charSet); | ||
35 | return temp; | ||
36 | } | ||
37 | |||
38 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java new file mode 100644 index 0000000..6eb40cc --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.PuzzleApplication; | ||
9 | import com.fourisland.fourpuzzle.util.ObjectLoader; | ||
10 | import java.awt.Graphics; | ||
11 | import java.awt.Image; | ||
12 | import java.awt.image.BufferedImage; | ||
13 | import java.util.HashMap; | ||
14 | import java.util.Vector; | ||
15 | |||
16 | /** | ||
17 | * | ||
18 | * @author hatkirby | ||
19 | */ | ||
20 | public abstract class ChipSet { | ||
21 | |||
22 | public abstract void initalize(); | ||
23 | |||
24 | private BufferedImage chipSetImage; | ||
25 | public BufferedImage getImage(int offset) | ||
26 | { | ||
27 | int sx = (offset % 8) * 16; | ||
28 | int sy = (offset / 8) * 16; | ||
29 | |||
30 | return chipSetImage.getSubimage(sx, sy, 16, 16); | ||
31 | } | ||
32 | |||
33 | public static ChipSet getChipSet(String chipSet) throws Exception | ||
34 | { | ||
35 | Class chipSetClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.chipset." + chipSet); | ||
36 | Object chipSetObject = chipSetClass.newInstance(); | ||
37 | ChipSet temp = (ChipSet) chipSetObject; | ||
38 | temp.initalize(); | ||
39 | temp.chipSetImage = ObjectLoader.getImage("ChipSet", chipSet); | ||
40 | |||
41 | return temp; | ||
42 | } | ||
43 | |||
44 | private HashMap<Integer,ChipSetData> chipSetData = new HashMap<Integer,ChipSetData>(); //162 | ||
45 | public HashMap<Integer,ChipSetData> getChipSetData() | ||
46 | { | ||
47 | return chipSetData; | ||
48 | } | ||
49 | |||
50 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSetData.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSetData.java new file mode 100644 index 0000000..5379292 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSetData.java | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.*; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class ChipSetData { | ||
15 | |||
16 | private String terrain; | ||
17 | private Layer layer; | ||
18 | private boolean enableNorth; | ||
19 | private boolean enableWest; | ||
20 | private boolean enableSouth; | ||
21 | private boolean enableEast; | ||
22 | |||
23 | public ChipSetData(String terrain, Layer layer) | ||
24 | { | ||
25 | this.terrain = terrain; | ||
26 | this.layer = layer; | ||
27 | |||
28 | if (layer == Layer.Middle) | ||
29 | { | ||
30 | enableNorth = false; | ||
31 | enableWest = false; | ||
32 | enableSouth = false; | ||
33 | enableEast = false; | ||
34 | } else { | ||
35 | enableNorth = true; | ||
36 | enableWest = true; | ||
37 | enableSouth = true; | ||
38 | enableEast = true; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | public ChipSetData(String terrain, boolean enableNorth, boolean enableWest, boolean enableSouth, boolean enableEast) | ||
43 | { | ||
44 | this.terrain = terrain; | ||
45 | |||
46 | if (!enableNorth && !enableWest && !enableSouth && !enableEast) | ||
47 | { | ||
48 | layer = Layer.Middle; | ||
49 | } else { | ||
50 | layer = Layer.Below; | ||
51 | } | ||
52 | |||
53 | this.enableNorth = enableNorth; | ||
54 | this.enableWest = enableWest; | ||
55 | this.enableSouth = enableSouth; | ||
56 | this.enableEast = enableEast; | ||
57 | } | ||
58 | |||
59 | public String getTerrain() { | ||
60 | return terrain; | ||
61 | } | ||
62 | |||
63 | public Layer getLayer() { | ||
64 | return layer; | ||
65 | } | ||
66 | |||
67 | public boolean isEnableNorth() { | ||
68 | return enableNorth; | ||
69 | } | ||
70 | |||
71 | public boolean isEnableWest() { | ||
72 | return enableWest; | ||
73 | } | ||
74 | |||
75 | public boolean isEnableSouth() { | ||
76 | return enableSouth; | ||
77 | } | ||
78 | |||
79 | public boolean isEnableEast() { | ||
80 | return enableEast; | ||
81 | } | ||
82 | |||
83 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java new file mode 100644 index 0000000..bcc2ed7 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.*; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; | ||
10 | import java.awt.Dimension; | ||
11 | import java.util.ArrayList; | ||
12 | import java.util.HashMap; | ||
13 | import java.util.Vector; | ||
14 | |||
15 | /** | ||
16 | * | ||
17 | * @author hatkirby | ||
18 | */ | ||
19 | public abstract class Map { | ||
20 | |||
21 | public abstract void initalize() throws Exception; | ||
22 | |||
23 | public void initalize(Dimension size) | ||
24 | { | ||
25 | setSize(size); | ||
26 | mapData = new Vector<HashMap<Integer,Integer>>(); | ||
27 | } | ||
28 | |||
29 | private Dimension size; | ||
30 | public Dimension getSize() | ||
31 | { | ||
32 | return size; | ||
33 | } | ||
34 | public void setSize(Dimension size) | ||
35 | { | ||
36 | if ((size.width < 20) || (size.height < 15)) | ||
37 | { | ||
38 | this.size = new Dimension(20,15); | ||
39 | } else { | ||
40 | this.size = size; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | private ArrayList<LayerEvent> events = new ArrayList<LayerEvent>(); | ||
45 | public ArrayList<LayerEvent> getEvents() | ||
46 | { | ||
47 | return events; | ||
48 | } | ||
49 | public LayerEvent getEvent(String event) | ||
50 | { | ||
51 | int i=0; | ||
52 | for (i=0;i<events.size();i++) | ||
53 | { | ||
54 | if (events.get(i).getLabel().equals(event)) | ||
55 | { | ||
56 | return events.get(i); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | return null; | ||
61 | } | ||
62 | |||
63 | public boolean checkForCollision(int x, int y, Direction toMove) throws Exception | ||
64 | { | ||
65 | if ((toMove == Direction.North) && (y == 0)) | ||
66 | { | ||
67 | return true; | ||
68 | } else if ((toMove == Direction.West) && (x == 0)) | ||
69 | { | ||
70 | return true; | ||
71 | } else if ((toMove == Direction.South) && (y == (size.height - 1))) | ||
72 | { | ||
73 | return true; | ||
74 | } else if ((toMove == Direction.East) && (x == (size.width - 1))) | ||
75 | { | ||
76 | return true; | ||
77 | } | ||
78 | |||
79 | int i=0; | ||
80 | for (i=0;i<events.size();i++) | ||
81 | { | ||
82 | if (events.get(i).getLayer() == Layer.Middle) | ||
83 | { | ||
84 | if ((events.get(i).getLocation().y == (y - 1)) && (events.get(i).getLocation().x == x) && (toMove == Direction.North)) | ||
85 | { | ||
86 | return true; | ||
87 | } | ||
88 | |||
89 | if ((events.get(i).getLocation().x == (x - 1)) && (events.get(i).getLocation().y == y) && (toMove == Direction.West)) | ||
90 | { | ||
91 | return true; | ||
92 | } | ||
93 | |||
94 | if ((events.get(i).getLocation().y == (y + 1)) && (events.get(i).getLocation().x == x) && (toMove == Direction.South)) | ||
95 | { | ||
96 | return true; | ||
97 | } | ||
98 | |||
99 | if ((events.get(i).getLocation().x == (x + 1)) && (events.get(i).getLocation().y == y) && (toMove == Direction.East)) | ||
100 | { | ||
101 | return true; | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | |||
106 | if ((Game.getHeroEvent().getLocation().y == (y - 1)) && (Game.getHeroEvent().getLocation().x == x) && (toMove == Direction.North)) | ||
107 | { | ||
108 | return true; | ||
109 | } | ||
110 | |||
111 | if ((Game.getHeroEvent().getLocation().x == (x - 1)) && (Game.getHeroEvent().getLocation().y == y) && (toMove == Direction.West)) | ||
112 | { | ||
113 | return true; | ||
114 | } | ||
115 | |||
116 | if ((Game.getHeroEvent().getLocation().y == (y + 1)) && (Game.getHeroEvent().getLocation().x == x) && (toMove == Direction.South)) | ||
117 | { | ||
118 | return true; | ||
119 | } | ||
120 | |||
121 | if ((Game.getHeroEvent().getLocation().x == (x + 1)) && (Game.getHeroEvent().getLocation().y == y) && (toMove == Direction.East)) | ||
122 | { | ||
123 | return true; | ||
124 | } | ||
125 | |||
126 | ChipSet cSI = ChipSet.getChipSet(chipSet); | ||
127 | HashMap<Integer,ChipSetData> cSID = cSI.getChipSetData(); | ||
128 | for (i=0;i<getMapData().size();i++) | ||
129 | { | ||
130 | if ((toMove == Direction.North) && (!cSID.get(mapData.get(i).get(x+((y-1)*getSize().width))).isEnableSouth())) | ||
131 | { | ||
132 | return true; | ||
133 | } else if ((toMove == Direction.West) && (!cSID.get(mapData.get(i).get(x-1+(y*getSize().width))).isEnableEast())) | ||
134 | { | ||
135 | return true; | ||
136 | } else if ((toMove == Direction.South) && (!cSID.get(mapData.get(i).get(x+((y+1)*getSize().width))).isEnableNorth())) | ||
137 | { | ||
138 | return true; | ||
139 | } else if ((toMove == Direction.East) && (!cSID.get(mapData.get(i).get(x+1+(y*getSize().width))).isEnableWest())) | ||
140 | { | ||
141 | return true; | ||
142 | } | ||
143 | |||
144 | if ((toMove == Direction.North) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableNorth())) | ||
145 | { | ||
146 | return true; | ||
147 | } else if ((toMove == Direction.West) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableWest())) | ||
148 | { | ||
149 | return true; | ||
150 | } else if ((toMove == Direction.South) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableSouth())) | ||
151 | { | ||
152 | return true; | ||
153 | } else if ((toMove == Direction.East) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableEast())) | ||
154 | { | ||
155 | return true; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | return false; | ||
160 | } | ||
161 | |||
162 | private String chipSet; | ||
163 | public String getChipSet() { | ||
164 | return chipSet; | ||
165 | } | ||
166 | public void setChipSet(String chipSet) { | ||
167 | this.chipSet = chipSet; | ||
168 | } | ||
169 | |||
170 | private Vector<HashMap<Integer,Integer>> mapData; | ||
171 | public Vector<HashMap<Integer, Integer>> getMapData() { | ||
172 | return mapData; | ||
173 | } | ||
174 | |||
175 | private String music; | ||
176 | public String getMusic() | ||
177 | { | ||
178 | return music; | ||
179 | } | ||
180 | public void setMusic(String music) | ||
181 | { | ||
182 | this.music = music; | ||
183 | } | ||
184 | |||
185 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java new file mode 100644 index 0000000..0e5ec44 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java | |||
@@ -0,0 +1,226 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Audio; | ||
9 | import com.fourisland.fourpuzzle.gamestate.*; | ||
10 | import com.fourisland.fourpuzzle.Direction; | ||
11 | import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; | ||
12 | import com.fourisland.fourpuzzle.Game; | ||
13 | import com.fourisland.fourpuzzle.Layer; | ||
14 | import com.fourisland.fourpuzzle.PuzzleApplication; | ||
15 | import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime; | ||
16 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; | ||
17 | import java.awt.Graphics2D; | ||
18 | import java.awt.event.KeyEvent; | ||
19 | import java.util.ArrayList; | ||
20 | |||
21 | /** | ||
22 | * | ||
23 | * @author hatkirby | ||
24 | */ | ||
25 | public class MapViewGameState implements GameState { | ||
26 | |||
27 | boolean debugWalkthrough = false; | ||
28 | boolean processInput = true; | ||
29 | Map currentMap; | ||
30 | |||
31 | public MapViewGameState(String map, int x, int y) throws Exception | ||
32 | { | ||
33 | //currentMap = ObjectLoader.getMap(map); | ||
34 | setCurrentMap(map); | ||
35 | Game.getSaveFile().getHero().setLocation(x, y); | ||
36 | } | ||
37 | |||
38 | public void initalize() throws Exception | ||
39 | { | ||
40 | //if (!currentMap.getMusic().equals("")) | ||
41 | { | ||
42 | // Audio.playMusic(currentMap.getMusic()); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | public void deinitalize() throws Exception | ||
47 | { | ||
48 | //if (!currentMap.getMusic().equals("")) | ||
49 | { | ||
50 | Audio.stopMusic(); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | public void processInput() throws Exception | ||
55 | { | ||
56 | if (processInput) | ||
57 | { | ||
58 | HeroEvent hero = Game.getSaveFile().getHero(); | ||
59 | |||
60 | if (Game.getKey().isControlDown() && !debugWalkthrough) | ||
61 | { | ||
62 | if (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) | ||
63 | { | ||
64 | debugWalkthrough = true; | ||
65 | } | ||
66 | } else { | ||
67 | debugWalkthrough = false; | ||
68 | } | ||
69 | |||
70 | if (!hero.isMoving()) | ||
71 | { | ||
72 | Direction toMove = null; | ||
73 | Boolean letsMove = false; | ||
74 | |||
75 | switch (Game.getKey().getKeyCode()) | ||
76 | { | ||
77 | case KeyEvent.VK_UP: | ||
78 | toMove = Direction.North; | ||
79 | letsMove = true; | ||
80 | break; | ||
81 | case KeyEvent.VK_RIGHT: | ||
82 | toMove = Direction.East; | ||
83 | letsMove = true; | ||
84 | break; | ||
85 | case KeyEvent.VK_DOWN: | ||
86 | toMove = Direction.South; | ||
87 | letsMove = true; | ||
88 | break; | ||
89 | case KeyEvent.VK_LEFT: | ||
90 | toMove = Direction.West; | ||
91 | letsMove = true; | ||
92 | break; | ||
93 | } | ||
94 | |||
95 | if (letsMove) | ||
96 | { | ||
97 | if (debugWalkthrough || (!currentMap.checkForCollision(hero.getLocation().x, hero.getLocation().y, toMove))) | ||
98 | { | ||
99 | hero.startMoving(toMove); | ||
100 | } else { | ||
101 | hero.setDirection(toMove); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) | ||
106 | { | ||
107 | int i=0; | ||
108 | for (i=0;i<currentMap.getEvents().size();i++) | ||
109 | { | ||
110 | LayerEvent ev = currentMap.getEvents().get(i); | ||
111 | |||
112 | if (ev.getCalltime() == EventCallTime.PushKey) | ||
113 | { | ||
114 | if ((hero.getDirection() == Direction.North) && (ev.getLocation().x == hero.getLocation().x) && (ev.getLocation().y == (hero.getLocation().y - 1))) | ||
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 | { | ||
124 | ev.setDirection(Direction.North); | ||
125 | ev.getCallback().run(); | ||
126 | } else if ((hero.getDirection() == Direction.East) && (ev.getLocation().x == (hero.getLocation().x + 1)) && (ev.getLocation().y == hero.getLocation().y)) | ||
127 | { | ||
128 | ev.setDirection(Direction.West); | ||
129 | ev.getCallback().run(); | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | |||
134 | Game.getKey().setKeyCode(KeyEvent.VK_UNDEFINED); | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | public void doGameCycle() throws Exception | ||
141 | { | ||
142 | HeroEvent hero = Game.getSaveFile().getHero(); | ||
143 | if (hero.isMoving()) | ||
144 | { | ||
145 | hero.processMoving(); | ||
146 | } | ||
147 | |||
148 | int i=0; | ||
149 | for (i=0;i<currentMap.getEvents().size();i++) | ||
150 | { | ||
151 | if (!currentMap.getEvents().get(i).isMoving()) | ||
152 | { | ||
153 | currentMap.getEvents().get(i).startMoving(currentMap); | ||
154 | } else { | ||
155 | currentMap.getEvents().get(i).processMoving(); | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | |||
160 | public void render(Graphics2D g) throws Exception | ||
161 | { | ||
162 | ChipSet chipSet = ChipSet.getChipSet(currentMap.getChipSet()); | ||
163 | int i,x,y; | ||
164 | for (i=0;i<currentMap.getMapData().size();i++) | ||
165 | { | ||
166 | for (y=0;y<currentMap.getSize().height;y++) | ||
167 | { | ||
168 | for (x=0;x<currentMap.getSize().width;x++) | ||
169 | { | ||
170 | int tile = currentMap.getMapData().get(i).get(x+(y*currentMap.getSize().width)); | ||
171 | if (chipSet.getChipSetData().get(tile).getLayer() != Layer.Above) | ||
172 | { | ||
173 | g.drawImage(chipSet.getImage(tile), x*16, y*16, null); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | /* | ||
179 | MapViewer mv = new MapViewer(currentMap, new com.alienfactory.javamappy.viewer.render.J2SE14Renderer(currentMap), Game.WIDTH, Game.HEIGHT); | ||
180 | mv.setBlockX(Game.getSaveFile().getHero().getLocation().x); | ||
181 | mv.setBlockY(Game.getSaveFile().getHero().getLocation().y); | ||
182 | mv.setPixelX((4 - Game.getSaveFile().getHero().getMoveTimer()) * 4); | ||
183 | mv.draw(g, true);*/ | ||
184 | Game.getSaveFile().getHero().render(g); | ||
185 | |||
186 | ArrayList<LayerEvent> events = currentMap.getEvents(); | ||
187 | for (i=0;i<events.size();i++) | ||
188 | { | ||
189 | events.get(i).render(g); | ||
190 | } | ||
191 | |||
192 | for (i=0;i<currentMap.getMapData().size();i++) | ||
193 | { | ||
194 | for (y=0;y<currentMap.getSize().height;y++) | ||
195 | { | ||
196 | for (x=0;x<currentMap.getSize().width;x++) | ||
197 | { | ||
198 | int tile = currentMap.getMapData().get(i).get(x+(y*currentMap.getSize().width)); | ||
199 | if (chipSet.getChipSetData().get(tile).getLayer() == Layer.Above) | ||
200 | { | ||
201 | g.drawImage(chipSet.getImage(tile), x*16, y*16, null); | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | |||
208 | public void initCurrentMap(String mapName) throws Exception | ||
209 | { | ||
210 | Class mapClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.map." + mapName); | ||
211 | Object mapObject = mapClass.newInstance(); | ||
212 | Map map = (Map) mapObject; | ||
213 | map.initalize(); | ||
214 | currentMap = map; | ||
215 | } | ||
216 | public void setCurrentMap(String mapName) throws Exception | ||
217 | { | ||
218 | Game.getSaveFile().setCurrentMap(mapName); | ||
219 | initCurrentMap(mapName); | ||
220 | } | ||
221 | public Map getCurrentMap() | ||
222 | { | ||
223 | return currentMap; | ||
224 | } | ||
225 | |||
226 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java new file mode 100644 index 0000000..e7901df --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | /** | ||
9 | * | ||
10 | * @author hatkirby | ||
11 | */ | ||
12 | public enum AnimationType { | ||
13 | CommonWithoutStepping, | ||
14 | CommonWithStepping, | ||
15 | WithoutStepping, | ||
16 | FixedGraphic, | ||
17 | TurnLeft, | ||
18 | TurnRight | ||
19 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java new file mode 100644 index 0000000..edfdb8f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition; | ||
9 | import java.util.ArrayList; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class CommonEvent { | ||
16 | |||
17 | private ArrayList<Precondition> preconditions; | ||
18 | private EventCallTime calltime; | ||
19 | private EventCall callback; | ||
20 | |||
21 | public CommonEvent() | ||
22 | { | ||
23 | calltime = EventCallTime.ParallelProcess; | ||
24 | callback = EventCall.getEmptyEventCall(); | ||
25 | |||
26 | preconditions = new ArrayList<Precondition>(); | ||
27 | } | ||
28 | |||
29 | public void addPrecondition(Precondition precondition) | ||
30 | { | ||
31 | preconditions.add(precondition); | ||
32 | } | ||
33 | |||
34 | public Precondition getPrecondition(int i) | ||
35 | { | ||
36 | return preconditions.get(i); | ||
37 | } | ||
38 | |||
39 | public int preconditions() | ||
40 | { | ||
41 | return preconditions.size(); | ||
42 | } | ||
43 | |||
44 | public EventCall getCallback() | ||
45 | { | ||
46 | return callback; | ||
47 | } | ||
48 | |||
49 | public void setCallback(EventCall callback) | ||
50 | { | ||
51 | this.callback = callback; | ||
52 | } | ||
53 | |||
54 | public EventCallTime getCalltime() { | ||
55 | return calltime; | ||
56 | } | ||
57 | |||
58 | public void setCalltime(EventCallTime calltime) { | ||
59 | this.calltime = calltime; | ||
60 | } | ||
61 | |||
62 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java new file mode 100644 index 0000000..1aa74c1 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import com.fourisland.fourpuzzle.Layer; | ||
10 | import java.awt.Graphics; | ||
11 | import java.awt.Point; | ||
12 | |||
13 | /** | ||
14 | * | ||
15 | * @author hatkirby | ||
16 | */ | ||
17 | public interface Event { | ||
18 | |||
19 | public String getLabel(); | ||
20 | |||
21 | public Point getLocation(); | ||
22 | |||
23 | public void setLocation(Point location); | ||
24 | public void setLocation(int x, int y); | ||
25 | |||
26 | public void render(Graphics g) throws Exception; | ||
27 | |||
28 | public Direction getDirection() throws Exception; | ||
29 | public void setDirection(Direction direction) throws Exception; | ||
30 | |||
31 | public boolean isMoving(); | ||
32 | public void startMoving(Direction direction) throws Exception; | ||
33 | |||
34 | public Layer getLayer() throws Exception; | ||
35 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java new file mode 100644 index 0000000..daca678 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | /** | ||
9 | * | ||
10 | * @author hatkirby | ||
11 | */ | ||
12 | public abstract class EventCall extends SpecialEvent implements Runnable { | ||
13 | |||
14 | public static EventCall getEmptyEventCall() | ||
15 | { | ||
16 | return new EventCall() { | ||
17 | @Override | ||
18 | public void run() { | ||
19 | } | ||
20 | }; | ||
21 | } | ||
22 | |||
23 | public abstract void run(); | ||
24 | |||
25 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java new file mode 100644 index 0000000..821f891 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java | |||
@@ -0,0 +1,16 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | /** | ||
9 | * | ||
10 | * @author hatkirby | ||
11 | */ | ||
12 | public enum EventCallTime { | ||
13 | PushKey, | ||
14 | OnHeroTouch, | ||
15 | ParallelProcess | ||
16 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java new file mode 100644 index 0000000..3bdb9de --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Layer; | ||
9 | import java.awt.Graphics; | ||
10 | import java.awt.Point; | ||
11 | import com.fourisland.fourpuzzle.Direction; | ||
12 | import com.fourisland.fourpuzzle.Game; | ||
13 | import com.fourisland.fourpuzzle.GameCharacter; | ||
14 | import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; | ||
15 | import com.fourisland.fourpuzzle.NoCharactersInPartyException; | ||
16 | |||
17 | /** | ||
18 | * | ||
19 | * @author hatkirby | ||
20 | */ | ||
21 | public class HeroEvent implements Event { | ||
22 | |||
23 | public HeroEvent() | ||
24 | { | ||
25 | location = new Point(); | ||
26 | } | ||
27 | |||
28 | public String getLabel() | ||
29 | { | ||
30 | return "Hero"; | ||
31 | } | ||
32 | |||
33 | private Point location; | ||
34 | public Point getLocation() | ||
35 | { | ||
36 | return location; | ||
37 | } | ||
38 | public void setLocation(Point location) | ||
39 | { | ||
40 | this.location = location; | ||
41 | } | ||
42 | public void setLocation(int x, int y) | ||
43 | { | ||
44 | location.setLocation(x, y); | ||
45 | } | ||
46 | |||
47 | public void render(Graphics g) throws Exception | ||
48 | { | ||
49 | int x = (location.x * 16) - 4; | ||
50 | int y = (location.y * 16) - 16; | ||
51 | |||
52 | if (moving) | ||
53 | { | ||
54 | if (moveDirection == Direction.North) | ||
55 | { | ||
56 | y -= (4 - moveTimer) * 4; | ||
57 | } else if (moveDirection == Direction.West) | ||
58 | { | ||
59 | x -= (4 - moveTimer) * 4; | ||
60 | } else if (moveDirection == Direction.South) | ||
61 | { | ||
62 | y += (4 - moveTimer) * 4; | ||
63 | } else if (moveDirection == Direction.East) | ||
64 | { | ||
65 | x += (4 - moveTimer) * 4; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | try | ||
70 | { | ||
71 | GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); | ||
72 | if (!toDraw.getGraphic().equals("blank")) | ||
73 | { | ||
74 | g.drawImage(CharSet.getCharSet(toDraw.getGraphic()).getImage(toDraw.getGraphicOffset(), direction, animationStep), x, y, null); | ||
75 | } | ||
76 | } catch (NoCharactersInPartyException ex) | ||
77 | { | ||
78 | } | ||
79 | } | ||
80 | |||
81 | |||
82 | private boolean moving = false; | ||
83 | public boolean isMoving() | ||
84 | { | ||
85 | return moving; | ||
86 | } | ||
87 | public void setMoving(boolean moving) | ||
88 | { | ||
89 | this.moving = moving; | ||
90 | } | ||
91 | |||
92 | private int moveTimer; | ||
93 | private Direction moveDirection; | ||
94 | public void startMoving(Direction toMove) throws Exception | ||
95 | { | ||
96 | setDirection(toMove); | ||
97 | setAnimationStep(2); | ||
98 | moveTimer = 4; | ||
99 | moving = true; | ||
100 | moveDirection = toMove; | ||
101 | } | ||
102 | public void processMoving() throws Exception | ||
103 | { | ||
104 | if (moving) | ||
105 | { | ||
106 | moveTimer--; | ||
107 | if (moveTimer == 2) | ||
108 | { | ||
109 | setAnimationStep(0); | ||
110 | } else if (moveTimer == 0) | ||
111 | { | ||
112 | setAnimationStep(1); | ||
113 | moving = false; | ||
114 | |||
115 | if (moveDirection == Direction.North) | ||
116 | { | ||
117 | setLocation(getLocation().x,getLocation().y-1); | ||
118 | } else if (moveDirection == Direction.West) | ||
119 | { | ||
120 | setLocation(getLocation().x-1,getLocation().y); | ||
121 | } else if (moveDirection == Direction.South) | ||
122 | { | ||
123 | setLocation(getLocation().x,getLocation().y+1); | ||
124 | } else if (moveDirection == Direction.East) | ||
125 | { | ||
126 | setLocation(getLocation().x+1,getLocation().y); | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | private Direction direction = Direction.South; | ||
133 | public Direction getDirection() | ||
134 | { | ||
135 | return direction; | ||
136 | } | ||
137 | public void setDirection(Direction direction) | ||
138 | { | ||
139 | this.direction = direction; | ||
140 | } | ||
141 | |||
142 | private int animationStep = 1; | ||
143 | public int getAnimationStep() | ||
144 | { | ||
145 | return animationStep; | ||
146 | } | ||
147 | public void setAnimationStep(int animationStep) | ||
148 | { | ||
149 | this.animationStep = animationStep; | ||
150 | } | ||
151 | |||
152 | public Layer getLayer() throws Exception | ||
153 | { | ||
154 | return Layer.Middle; | ||
155 | } | ||
156 | |||
157 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java new file mode 100644 index 0000000..92cfd54 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java | |||
@@ -0,0 +1,207 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Layer; | ||
9 | import java.awt.Graphics; | ||
10 | import java.awt.Point; | ||
11 | import java.util.ArrayList; | ||
12 | import com.fourisland.fourpuzzle.Direction; | ||
13 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | ||
14 | |||
15 | /** | ||
16 | * | ||
17 | * @author hatkirby | ||
18 | */ | ||
19 | public class LayerEvent implements Event { | ||
20 | |||
21 | /** Create a new Event instance | ||
22 | * | ||
23 | * @param x The horizontal location of the Event on the Map | ||
24 | * @param y The vertical location of the Event on the Map | ||
25 | */ | ||
26 | public LayerEvent(int x, int y) | ||
27 | { | ||
28 | location = new Point(x,y); | ||
29 | events = new ArrayList<PossibleEvent>(); | ||
30 | } | ||
31 | |||
32 | /** Create a new Event instance | ||
33 | * | ||
34 | * @param x The horizontal location of the Event on the Map | ||
35 | * @param y The vertical location of the Event on the Map | ||
36 | * @param label An identifying label for the Event | ||
37 | */ | ||
38 | public LayerEvent(int x, int y, String label) | ||
39 | { | ||
40 | this(x,y); | ||
41 | this.label = label; | ||
42 | } | ||
43 | |||
44 | private String label; | ||
45 | public String getLabel() | ||
46 | { | ||
47 | return label; | ||
48 | } | ||
49 | |||
50 | private Point location; | ||
51 | public Point getLocation() | ||
52 | { | ||
53 | return location; | ||
54 | } | ||
55 | public void setLocation(Point location) | ||
56 | { | ||
57 | this.location = location; | ||
58 | } | ||
59 | public void setLocation(int x, int y) | ||
60 | { | ||
61 | location.setLocation(x, y); | ||
62 | } | ||
63 | |||
64 | private ArrayList<PossibleEvent> events; | ||
65 | public void addEvent(PossibleEvent pe) | ||
66 | { | ||
67 | events.add(pe); | ||
68 | } | ||
69 | |||
70 | private PossibleEvent getPossibleEvent() throws Exception | ||
71 | { | ||
72 | int i; | ||
73 | for (i=(events.size()-1);i>-1;i--) | ||
74 | { | ||
75 | boolean good = true; | ||
76 | int j; | ||
77 | for (j=0;j<events.get(i).preconditions();j++) | ||
78 | { | ||
79 | good = (good ? events.get(i).getPrecondition(j).match() : false); | ||
80 | } | ||
81 | |||
82 | if (good) | ||
83 | { | ||
84 | return events.get(i); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | return new PossibleEvent(); | ||
89 | } | ||
90 | |||
91 | public void render(Graphics g) throws Exception | ||
92 | { | ||
93 | int x = (location.x * 16) - 4; | ||
94 | int y = (location.y * 16) - 16; | ||
95 | |||
96 | if (moving) | ||
97 | { | ||
98 | if (moveDirection == Direction.North) | ||
99 | { | ||
100 | y -= (4 - moveTimer) * 4; | ||
101 | } else if (moveDirection == Direction.West) | ||
102 | { | ||
103 | x -= (4 - moveTimer) * 4; | ||
104 | } else if (moveDirection == Direction.South) | ||
105 | { | ||
106 | y += (4 - moveTimer) * 4; | ||
107 | } else if (moveDirection == Direction.East) | ||
108 | { | ||
109 | x += (4 - moveTimer) * 4; | ||
110 | } | ||
111 | } | ||
112 | |||
113 | PossibleEvent toDraw = getPossibleEvent(); | ||
114 | if (!toDraw.getGraphic().equals("blank")) | ||
115 | { | ||
116 | g.drawImage(toDraw.getImage(), x, y, null); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | |||
121 | private boolean moving = false; | ||
122 | public boolean isMoving() | ||
123 | { | ||
124 | return moving; | ||
125 | } | ||
126 | public void setMoving(boolean moving) | ||
127 | { | ||
128 | this.moving = moving; | ||
129 | } | ||
130 | |||
131 | private int moveTimer; | ||
132 | private Direction moveDirection; | ||
133 | public void startMoving(Map map) throws Exception | ||
134 | { | ||
135 | Direction toMove = getPossibleEvent().getMovement().startMoving(); | ||
136 | |||
137 | if (toMove != null) | ||
138 | { | ||
139 | if (!map.checkForCollision(getLocation().x, getLocation().y, toMove)) | ||
140 | { | ||
141 | startMoving(toMove); | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | public void startMoving(Direction toMove) throws Exception | ||
146 | { | ||
147 | getPossibleEvent().setDirection(toMove); | ||
148 | getPossibleEvent().setAnimationStep(2); | ||
149 | moveTimer = 4; | ||
150 | moving = true; | ||
151 | moveDirection = toMove; | ||
152 | } | ||
153 | public void processMoving() throws Exception | ||
154 | { | ||
155 | if (moving) | ||
156 | { | ||
157 | moveTimer--; | ||
158 | if (moveTimer == 2) | ||
159 | { | ||
160 | getPossibleEvent().setAnimationStep(0); | ||
161 | } else if (moveTimer == 0) | ||
162 | { | ||
163 | getPossibleEvent().setAnimationStep(1); | ||
164 | moving = false; | ||
165 | |||
166 | if (moveDirection == Direction.North) | ||
167 | { | ||
168 | setLocation(getLocation().x,getLocation().y-1); | ||
169 | } else if (moveDirection == Direction.West) | ||
170 | { | ||
171 | setLocation(getLocation().x-1,getLocation().y); | ||
172 | } else if (moveDirection == Direction.South) | ||
173 | { | ||
174 | setLocation(getLocation().x,getLocation().y+1); | ||
175 | } else if (moveDirection == Direction.East) | ||
176 | { | ||
177 | setLocation(getLocation().x+1,getLocation().y); | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | |||
183 | public Direction getDirection() throws Exception | ||
184 | { | ||
185 | return getPossibleEvent().getDirection(); | ||
186 | } | ||
187 | public void setDirection(Direction direction) throws Exception | ||
188 | { | ||
189 | getPossibleEvent().setDirection(direction); | ||
190 | } | ||
191 | |||
192 | public Layer getLayer() throws Exception | ||
193 | { | ||
194 | return getPossibleEvent().getLayer(); | ||
195 | } | ||
196 | |||
197 | public EventCallTime getCalltime() throws Exception | ||
198 | { | ||
199 | return getPossibleEvent().getCalltime(); | ||
200 | } | ||
201 | |||
202 | public EventCall getCallback() throws Exception | ||
203 | { | ||
204 | return getPossibleEvent().getCallback(); | ||
205 | } | ||
206 | |||
207 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java new file mode 100644 index 0000000..ce9773f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Layer; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition; | ||
10 | import java.util.ArrayList; | ||
11 | import com.fourisland.fourpuzzle.Direction; | ||
12 | import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic; | ||
13 | import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.EventGraphic; | ||
14 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.MovementType; | ||
15 | import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.StayStillMovementType; | ||
16 | import com.fourisland.fourpuzzle.util.Functions; | ||
17 | import java.awt.image.BufferedImage; | ||
18 | |||
19 | /** | ||
20 | *w | ||
21 | * @author hatkirby | ||
22 | */ | ||
23 | public class PossibleEvent { | ||
24 | |||
25 | private EventGraphic graphic; | ||
26 | private Layer layer; | ||
27 | private AnimationType animation; | ||
28 | private MovementType movement; | ||
29 | private EventCallTime calltime; | ||
30 | private EventCall callback; | ||
31 | private ArrayList<Precondition> preconditions; | ||
32 | |||
33 | private Direction direction; | ||
34 | private int animationStep; | ||
35 | |||
36 | public PossibleEvent() | ||
37 | { | ||
38 | graphic = new BlankEventGraphic(); | ||
39 | layer = Layer.Below; | ||
40 | animation = AnimationType.CommonWithStepping; | ||
41 | movement = new StayStillMovementType(); | ||
42 | calltime = EventCallTime.PushKey; | ||
43 | callback = EventCall.getEmptyEventCall(); | ||
44 | preconditions = new ArrayList<Precondition>(); | ||
45 | |||
46 | direction = Direction.South; | ||
47 | animationStep = 1; | ||
48 | } | ||
49 | |||
50 | public BufferedImage getImage() throws Exception | ||
51 | { | ||
52 | return graphic.getImage(); | ||
53 | } | ||
54 | |||
55 | public EventGraphic getGraphic() { | ||
56 | return graphic; | ||
57 | } | ||
58 | |||
59 | public void setGraphic(EventGraphic graphic) { | ||
60 | this.graphic = graphic; | ||
61 | } | ||
62 | |||
63 | public Layer getLayer() { | ||
64 | return layer; | ||
65 | } | ||
66 | |||
67 | public void setLayer(Layer layer) { | ||
68 | this.layer = layer; | ||
69 | } | ||
70 | |||
71 | public AnimationType getAnimation() { | ||
72 | return animation; | ||
73 | } | ||
74 | |||
75 | public void setAnimation(AnimationType animation) { | ||
76 | this.animation = animation; | ||
77 | } | ||
78 | |||
79 | public MovementType getMovement() { | ||
80 | return movement; | ||
81 | } | ||
82 | |||
83 | public void setMovement(MovementType movement) { | ||
84 | this.movement = movement; | ||
85 | } | ||
86 | |||
87 | public Direction getDirection() { | ||
88 | return direction; | ||
89 | } | ||
90 | |||
91 | public void setDirection(Direction direction) throws Exception { | ||
92 | if (Functions.canTurn(this)) | ||
93 | { | ||
94 | this.direction = direction; | ||
95 | graphic.setDirection(direction); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public int getAnimationStep() { | ||
100 | return animationStep; | ||
101 | } | ||
102 | |||
103 | public void setAnimationStep(int animationStep) { | ||
104 | this.animationStep = animationStep; | ||
105 | graphic.setAnimationStep(animationStep); | ||
106 | } | ||
107 | |||
108 | public void addPrecondition(Precondition precondition) | ||
109 | { | ||
110 | preconditions.add(precondition); | ||
111 | } | ||
112 | |||
113 | public Precondition getPrecondition(int i) | ||
114 | { | ||
115 | return preconditions.get(i); | ||
116 | } | ||
117 | |||
118 | public int preconditions() | ||
119 | { | ||
120 | return preconditions.size(); | ||
121 | } | ||
122 | |||
123 | public EventCall getCallback() | ||
124 | { | ||
125 | return callback; | ||
126 | } | ||
127 | |||
128 | public void setCallback(EventCall callback) | ||
129 | { | ||
130 | this.callback = callback; | ||
131 | } | ||
132 | |||
133 | public EventCallTime getCalltime() { | ||
134 | return calltime; | ||
135 | } | ||
136 | |||
137 | public void setCalltime(EventCallTime calltime) { | ||
138 | this.calltime = calltime; | ||
139 | } | ||
140 | |||
141 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java new file mode 100644 index 0000000..26f89c7 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java | |||
@@ -0,0 +1,173 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.*; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; | ||
10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; | ||
11 | import java.util.concurrent.BrokenBarrierException; | ||
12 | import java.util.concurrent.CyclicBarrier; | ||
13 | import java.util.logging.Level; | ||
14 | import java.util.logging.Logger; | ||
15 | |||
16 | /** | ||
17 | * | ||
18 | * @author hatkirby | ||
19 | */ | ||
20 | public class SpecialEvent { | ||
21 | |||
22 | /** | ||
23 | * Display a message on the screen. | ||
24 | * | ||
25 | * Usually used for dialogue. If SetFace() is | ||
26 | * | ||
27 | * used prior to this, the face set is displayed | ||
28 | * on the left side. | ||
29 | * | ||
30 | * Display of the message area can be modified using | ||
31 | * MessageDisplaySettings(). | ||
32 | * | ||
33 | * This function also automatically splits your | ||
34 | * message up into blocks that will fit on | ||
35 | * the screen (breaks at spaces). If there are too | ||
36 | * many words, they will be held and displayed in | ||
37 | * the message area after the prior message has | ||
38 | * been read. | ||
39 | * | ||
40 | * @param message The message to display | ||
41 | */ | ||
42 | public void DisplayMessage(String message) | ||
43 | { | ||
44 | throw new UnsupportedOperationException("Not yet implemented"); | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * Sets the face used when displaying a message | ||
49 | * | ||
50 | * See DisplayMessage() for more info | ||
51 | * | ||
52 | * @param faceSet The name of the FaceSet to use | ||
53 | * @param face The number of the face in the FaceSet | ||
54 | * to use. The faces are numbered | ||
55 | * horizontally. | ||
56 | */ | ||
57 | public void SetFace(String faceSet, int face) | ||
58 | { | ||
59 | throw new UnsupportedOperationException("Not yet implemented"); | ||
60 | } | ||
61 | |||
62 | /** | ||
63 | * Clears the face used when displaying a message | ||
64 | * | ||
65 | * See DisplayMessage() for more info | ||
66 | */ | ||
67 | public void EraseFace() | ||
68 | { | ||
69 | throw new UnsupportedOperationException("Not yet implemented"); | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * Sets a Switch to a [boolean] value | ||
74 | * | ||
75 | * @param switchID The Switch to set | ||
76 | * @param value The value to set the Switch to | ||
77 | */ | ||
78 | public void SetSwitch(String switchID, boolean value) | ||
79 | { | ||
80 | Game.getSaveFile().getSwitches().put(switchID, value); | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Toggles a Switch's [boolean] value | ||
85 | * | ||
86 | * @param switchID The Switch to toggle | ||
87 | */ | ||
88 | public void ToggleSwitch(String switchID) | ||
89 | { | ||
90 | if (Game.getSaveFile().getSwitches().containsKey(switchID)) | ||
91 | { | ||
92 | Game.getSaveFile().getSwitches().put(switchID, !Game.getSaveFile().getSwitches().get(switchID)); | ||
93 | } else { | ||
94 | Game.getSaveFile().getSwitches().put(switchID, true); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * Performs actions on the hero | ||
100 | * | ||
101 | * @param actions An array of MoveEvents to perform on the hero | ||
102 | */ | ||
103 | public void MoveEvent(MoveEvent[] actions) | ||
104 | { | ||
105 | MoveEvent(actions, Game.getHeroEvent()); | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * Performs actions on an event | ||
110 | * | ||
111 | * @param actions An array of MoveEvents to perform on the event | ||
112 | * @param ev The event to act upon | ||
113 | */ | ||
114 | public void MoveEvent(MoveEvent[] actions, Event ev) | ||
115 | { | ||
116 | new Thread(new MoveEventThread(ev, actions)).start(); | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * Waits until all previously called MoveEvent()s have finished | ||
121 | */ | ||
122 | public void MoveEventWait() | ||
123 | { | ||
124 | try { | ||
125 | MoveEventThread.moveEventWait.await(); | ||
126 | } catch (InterruptedException ex) { | ||
127 | Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * Triggers the Game Over sequence | ||
133 | * @throws Exception | ||
134 | */ | ||
135 | public void GameOver() throws Exception | ||
136 | { | ||
137 | throw new UnsupportedOperationException("Not yet implemented"); | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * Returns the player to the Title Screen | ||
142 | * @throws Exception | ||
143 | */ | ||
144 | public void TitleScreen() throws Exception | ||
145 | { | ||
146 | throw new UnsupportedOperationException("Not yet implemented"); | ||
147 | } | ||
148 | |||
149 | /** | ||
150 | * Moves the player to a different map | ||
151 | * | ||
152 | * @param map The name of the map to move to | ||
153 | * @param x The X position on the map to move to | ||
154 | * @param y The Y position on the map to move to | ||
155 | * @throws java.lang.Exception | ||
156 | */ | ||
157 | public void Teleport(String map, int x, int y) throws Exception | ||
158 | { | ||
159 | throw new UnsupportedOperationException("Not yet implemented"); | ||
160 | } | ||
161 | |||
162 | /** | ||
163 | * Waits for a specified interval | ||
164 | * | ||
165 | * @param wait The time to wait in milliseconds | ||
166 | * @throws java.lang.InterruptedException | ||
167 | */ | ||
168 | public void Wait(int wait) throws InterruptedException | ||
169 | { | ||
170 | Thread.sleep(wait); | ||
171 | } | ||
172 | |||
173 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java new file mode 100644 index 0000000..592c8a7 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import java.awt.image.BufferedImage; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class BlankEventGraphic implements EventGraphic { | ||
16 | |||
17 | private Direction direction; | ||
18 | private int animationStep; | ||
19 | |||
20 | public BufferedImage getImage() throws Exception { | ||
21 | return null; | ||
22 | } | ||
23 | |||
24 | public Direction getDirection() { | ||
25 | return direction; | ||
26 | } | ||
27 | |||
28 | public void setDirection(Direction direction) { | ||
29 | this.direction = direction; | ||
30 | } | ||
31 | |||
32 | public int getAnimationStep() { | ||
33 | return animationStep; | ||
34 | } | ||
35 | |||
36 | public void setAnimationStep(int animationStep) { | ||
37 | this.animationStep = animationStep; | ||
38 | } | ||
39 | |||
40 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java new file mode 100644 index 0000000..b71a0b8 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; | ||
10 | import java.awt.image.BufferedImage; | ||
11 | |||
12 | /** | ||
13 | * | ||
14 | * @author hatkirby | ||
15 | */ | ||
16 | public class CharSetEventGraphic implements EventGraphic { | ||
17 | |||
18 | private Direction direction = Direction.South; | ||
19 | private int animationStep = 1; | ||
20 | private String graphic; | ||
21 | private int graphicOffset; | ||
22 | |||
23 | public CharSetEventGraphic(String graphic, int graphicOffset) | ||
24 | { | ||
25 | this.graphic = graphic; | ||
26 | this.graphicOffset = graphicOffset; | ||
27 | } | ||
28 | |||
29 | public BufferedImage getImage() throws Exception | ||
30 | { | ||
31 | return CharSet.getCharSet(getGraphic()).getImage(getGraphicOffset(), getDirection(), getAnimationStep()); | ||
32 | } | ||
33 | |||
34 | public Direction getDirection() | ||
35 | { | ||
36 | return direction; | ||
37 | } | ||
38 | |||
39 | public void setDirection(Direction direction) | ||
40 | { | ||
41 | this.direction = direction; | ||
42 | } | ||
43 | |||
44 | public String getGraphic() { | ||
45 | return graphic; | ||
46 | } | ||
47 | |||
48 | public void setGraphic(String graphic) { | ||
49 | this.graphic = graphic; | ||
50 | } | ||
51 | |||
52 | public int getGraphicOffset() { | ||
53 | return graphicOffset; | ||
54 | } | ||
55 | |||
56 | public void setGraphicOffset(int graphicOffset) { | ||
57 | this.graphicOffset = graphicOffset; | ||
58 | } | ||
59 | |||
60 | public int getAnimationStep() { | ||
61 | return animationStep; | ||
62 | } | ||
63 | |||
64 | public void setAnimationStep(int animationStep) { | ||
65 | this.animationStep = animationStep; | ||
66 | } | ||
67 | |||
68 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java new file mode 100644 index 0000000..60afca5 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import java.awt.image.BufferedImage; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public interface EventGraphic { | ||
16 | |||
17 | public BufferedImage getImage() throws Exception; | ||
18 | |||
19 | public Direction getDirection(); | ||
20 | public void setDirection(Direction direction); | ||
21 | |||
22 | public int getAnimationStep(); | ||
23 | public void setAnimationStep(int animationStep); | ||
24 | |||
25 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java new file mode 100644 index 0000000..3e3773f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class CustomMovementType implements MovementType { | ||
15 | |||
16 | private Direction[] moves; | ||
17 | private int step = 0; | ||
18 | |||
19 | public CustomMovementType(Direction[] moves) | ||
20 | { | ||
21 | this.moves = moves; | ||
22 | } | ||
23 | |||
24 | public Direction startMoving() throws Exception | ||
25 | { | ||
26 | if (step >= moves.length) | ||
27 | { | ||
28 | step = 0; | ||
29 | } | ||
30 | |||
31 | return moves[step++]; | ||
32 | } | ||
33 | |||
34 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java new file mode 100644 index 0000000..4911a54 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public interface MovementType { | ||
15 | |||
16 | public Direction startMoving() throws Exception; | ||
17 | |||
18 | } | ||
19 | |||
20 | /* | ||
21 | CycleUpDown | ||
22 | CycleLeftRight | ||
23 | StepTowardHero | ||
24 | StepAwayFromHero | ||
25 | */ \ No newline at end of file | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java new file mode 100644 index 0000000..d0d96ce --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import java.util.Random; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class RandomMovementType implements MovementType { | ||
16 | |||
17 | public Direction startMoving() throws Exception { | ||
18 | Random r = new Random(); | ||
19 | int ra = r.nextInt(1000); | ||
20 | Direction toMove = null; | ||
21 | boolean letsMove = false; | ||
22 | |||
23 | if (ra < 25) | ||
24 | { | ||
25 | toMove = Direction.North; | ||
26 | letsMove = true; | ||
27 | } else if (ra < 50) | ||
28 | { | ||
29 | toMove = Direction.West; | ||
30 | letsMove = true; | ||
31 | } else if (ra < 75) | ||
32 | { | ||
33 | toMove = Direction.South; | ||
34 | letsMove = true; | ||
35 | } else if (ra < 100) | ||
36 | { | ||
37 | toMove = Direction.East; | ||
38 | letsMove = true; | ||
39 | } | ||
40 | |||
41 | if (letsMove) | ||
42 | { | ||
43 | return toMove; | ||
44 | } | ||
45 | |||
46 | return null; | ||
47 | } | ||
48 | |||
49 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java new file mode 100644 index 0000000..a34a1f1 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class StayStillMovementType implements MovementType { | ||
15 | |||
16 | public Direction startMoving() throws Exception | ||
17 | { | ||
18 | return null; // Do nothing, stay still | ||
19 | } | ||
20 | |||
21 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java new file mode 100644 index 0000000..7700674 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Game; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class HeroInPartyPrecondition implements Precondition { | ||
15 | |||
16 | private String heroName; | ||
17 | |||
18 | public HeroInPartyPrecondition(String heroName) | ||
19 | { | ||
20 | this.heroName = heroName; | ||
21 | } | ||
22 | |||
23 | public boolean match() { | ||
24 | return Game.getSaveFile().getParty().exists(heroName); | ||
25 | } | ||
26 | |||
27 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java new file mode 100644 index 0000000..1b10e91 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Game; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class HeroLevelPrecondition implements Precondition { | ||
15 | |||
16 | private String heroName; | ||
17 | private int level; | ||
18 | |||
19 | public HeroLevelPrecondition(String heroName, int level) | ||
20 | { | ||
21 | this.heroName = heroName; | ||
22 | this.level = level; | ||
23 | } | ||
24 | |||
25 | public boolean match() throws Exception { | ||
26 | return (Game.getSaveFile().getParty().exists(heroName) && (Game.getSaveFile().getParty().get(heroName).getLevel() == level)); | ||
27 | } | ||
28 | |||
29 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java new file mode 100644 index 0000000..3f75984 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java | |||
@@ -0,0 +1,16 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
7 | |||
8 | /** | ||
9 | * | ||
10 | * @author hatkirby | ||
11 | */ | ||
12 | public interface Precondition { | ||
13 | |||
14 | public boolean match() throws Exception; | ||
15 | |||
16 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java new file mode 100644 index 0000000..794eae4 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Game; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class SwitchPrecondition implements Precondition { | ||
15 | |||
16 | private String switchID; | ||
17 | |||
18 | public SwitchPrecondition(String switchID) | ||
19 | { | ||
20 | this.switchID = switchID; | ||
21 | } | ||
22 | |||
23 | public boolean match() { | ||
24 | return (Game.getSaveFile().getSwitches().containsKey(switchID) && Game.getSaveFile().getSwitches().get(switchID)); | ||
25 | } | ||
26 | |||
27 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java new file mode 100644 index 0000000..a3ce086 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.util.Comparison; | ||
9 | import com.fourisland.fourpuzzle.Game; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class VariableNumberPrecondition implements Precondition { | ||
16 | |||
17 | private String variableID; | ||
18 | private Comparison comparison; | ||
19 | private int number; | ||
20 | |||
21 | public VariableNumberPrecondition(String variableID, Comparison comparison, int number) | ||
22 | { | ||
23 | this.variableID = variableID; | ||
24 | this.comparison = comparison; | ||
25 | this.number = number; | ||
26 | } | ||
27 | |||
28 | public boolean match() { | ||
29 | if (Game.getSaveFile().getVariables().containsKey(variableID)) | ||
30 | { | ||
31 | int n1 = Game.getSaveFile().getVariables().get(variableID); | ||
32 | int n2 = number; | ||
33 | |||
34 | switch (comparison) | ||
35 | { | ||
36 | case Less: return (n1 < n2); | ||
37 | case Greater: return (n1 > n2); | ||
38 | case Equal: return (n1 == n2); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | return false; | ||
43 | } | ||
44 | |||
45 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java new file mode 100644 index 0000000..1eb9b0c --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.util.Comparison; | ||
9 | import com.fourisland.fourpuzzle.Game; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class VariableVariablePrecondition implements Precondition { | ||
16 | |||
17 | private String variableID; | ||
18 | private Comparison comparison; | ||
19 | private String variableID2; | ||
20 | |||
21 | public VariableVariablePrecondition(String variableID, Comparison comparison, String variableID2) | ||
22 | { | ||
23 | this.variableID = variableID; | ||
24 | this.comparison = comparison; | ||
25 | this.variableID2 = variableID2; | ||
26 | } | ||
27 | |||
28 | public boolean match() { | ||
29 | if (Game.getSaveFile().getVariables().containsKey(variableID)) | ||
30 | { | ||
31 | int n1 = Game.getSaveFile().getVariables().get(variableID); | ||
32 | int n2 = Game.getSaveFile().getVariables().get(variableID2); | ||
33 | |||
34 | switch (comparison) | ||
35 | { | ||
36 | case Less: return (n1 < n2); | ||
37 | case Greater: return (n1 > n2); | ||
38 | case Equal: return (n1 == n2); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | return false; | ||
43 | } | ||
44 | |||
45 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java new file mode 100644 index 0000000..a9dc891 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class FaceMoveEvent implements MoveEvent { | ||
16 | |||
17 | Direction direction; | ||
18 | public FaceMoveEvent(Direction direction) | ||
19 | { | ||
20 | this.direction = direction; | ||
21 | } | ||
22 | |||
23 | public void doAction(Event ev) throws Exception | ||
24 | { | ||
25 | ev.setDirection(direction); | ||
26 | } | ||
27 | |||
28 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java new file mode 100644 index 0000000..66c9f6d --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java | |||
@@ -0,0 +1,19 @@ | |||
1 | |||
2 | /* | ||
3 | * To change this template, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | |||
7 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
8 | |||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public interface MoveEvent { | ||
16 | |||
17 | public void doAction(Event ev) throws Exception; | ||
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 new file mode 100644 index 0000000..4c16197 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
9 | import java.util.concurrent.CountDownLatch; | ||
10 | import java.util.concurrent.CyclicBarrier; | ||
11 | import java.util.logging.Level; | ||
12 | import java.util.logging.Logger; | ||
13 | |||
14 | /** | ||
15 | * | ||
16 | * @author hatkirby | ||
17 | */ | ||
18 | public class MoveEventThread implements Runnable { | ||
19 | |||
20 | public static volatile CountDownLatch moveEventWait = new CountDownLatch(0); | ||
21 | public static volatile int countMoveEventThreads = 0; | ||
22 | |||
23 | Event ev; | ||
24 | MoveEvent[] actions; | ||
25 | |||
26 | public MoveEventThread(Event ev, MoveEvent[] actions) | ||
27 | { | ||
28 | this.ev = ev; | ||
29 | this.actions = actions; | ||
30 | } | ||
31 | |||
32 | public void run() { | ||
33 | MoveEventThread.countMoveEventThreads++; | ||
34 | moveEventWait = new CountDownLatch(countMoveEventThreads); | ||
35 | |||
36 | int i=0; | ||
37 | for (i=0;i<actions.length;i++) | ||
38 | { | ||
39 | try { | ||
40 | actions[i].doAction(ev); | ||
41 | } catch (Exception ex) { | ||
42 | Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | MoveEventThread.countMoveEventThreads--; | ||
47 | moveEventWait.countDown(); | ||
48 | } | ||
49 | |||
50 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java new file mode 100644 index 0000000..12b2421 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.Direction; | ||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
10 | |||
11 | /** | ||
12 | * | ||
13 | * @author hatkirby | ||
14 | */ | ||
15 | public class StepMoveEvent implements MoveEvent { | ||
16 | |||
17 | Direction direction; | ||
18 | public StepMoveEvent(Direction direction) | ||
19 | { | ||
20 | this.direction = direction; | ||
21 | } | ||
22 | |||
23 | public void doAction(Event ev) throws Exception | ||
24 | { | ||
25 | ev.startMoving(direction); | ||
26 | |||
27 | while (ev.isMoving()) | ||
28 | { | ||
29 | Thread.sleep(2); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | } | ||
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java new file mode 100644 index 0000000..d9823d5 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | * @author hatkirby | ||
13 | */ | ||
14 | public class WaitMoveEvent implements MoveEvent { | ||
15 | |||
16 | int wait; | ||
17 | public WaitMoveEvent(int wait) | ||
18 | { | ||
19 | this.wait = wait; | ||
20 | } | ||
21 | |||
22 | public void doAction(Event ev) throws Exception | ||
23 | { | ||
24 | Thread.sleep(wait); | ||
25 | } | ||
26 | |||
27 | } | ||