summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-01-17 10:36:37 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-01-17 10:36:37 -0500
commit69b495c392bffe96dab97306a42466edd4b2474e (patch)
tree2adccc01f4027bcb76bbefee03bb6a9622ce3e00 /src/com/fourisland
parent4c768483aecd687529b9abb48ed42950fabc886f (diff)
downloadfourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.gz
fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.tar.bz2
fourpuzzle-69b495c392bffe96dab97306a42466edd4b2474e.zip
Imported sources
Diffstat (limited to 'src/com/fourisland')
-rw-r--r--src/com/fourisland/fourpuzzle/Audio.java75
-rw-r--r--src/com/fourisland/fourpuzzle/Direction.java17
-rw-r--r--src/com/fourisland/fourpuzzle/Display.java105
-rw-r--r--src/com/fourisland/fourpuzzle/Game.java62
-rw-r--r--src/com/fourisland/fourpuzzle/GameCharacter.java68
-rw-r--r--src/com/fourisland/fourpuzzle/GameCharacters.java79
-rw-r--r--src/com/fourisland/fourpuzzle/Layer.java16
-rw-r--r--src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java14
-rw-r--r--src/com/fourisland/fourpuzzle/PuzzleApplication.java163
-rw-r--r--src/com/fourisland/fourpuzzle/SaveFile.java97
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java60
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/GameState.java34
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java49
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java38
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java50
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSetData.java83
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java185
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java226
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java19
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java62
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java35
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java25
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java16
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java157
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java207
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java141
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java173
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java40
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java68
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java25
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java34
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java25
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java49
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java21
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java27
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java29
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java16
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java27
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java45
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java45
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java28
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java19
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java50
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java33
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java27
-rw-r--r--src/com/fourisland/fourpuzzle/transition/SquareTransition.java50
-rw-r--r--src/com/fourisland/fourpuzzle/transition/Transition.java56
-rw-r--r--src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java40
-rw-r--r--src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java19
-rw-r--r--src/com/fourisland/fourpuzzle/util/Comparison.java20
-rw-r--r--src/com/fourisland/fourpuzzle/util/Functions.java31
-rw-r--r--src/com/fourisland/fourpuzzle/util/ObjectLoader.java92
-rw-r--r--src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java46
53 files changed, 3218 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/Audio.java b/src/com/fourisland/fourpuzzle/Audio.java new file mode 100644 index 0000000..99d4207 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/Audio.java
@@ -0,0 +1,75 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8import com.fourisland.fourpuzzle.util.ObjectLoader;
9import javax.sound.midi.MidiSystem;
10import javax.sound.midi.Sequencer;
11import javax.sound.midi.Track;
12
13/**
14 *
15 * @author hatkirby
16 */
17public class Audio {
18
19 private static Sequencer seq;
20
21 public static void init() throws Exception
22 {
23 seq = MidiSystem.getSequencer();
24 seq.open();
25
26 Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
27 public void run() {
28 if (seq.isRunning())
29 {
30 seq.stop();
31 }
32
33 seq.close();
34 }
35 }));
36 }
37
38 public static void playMusic(String file) throws Exception
39 {
40 playMusic(file, true, 1F);
41 }
42
43 public static void playMusic(String file, boolean loop) throws Exception
44 {
45 playMusic(file, loop, 1F);
46 }
47
48 public static void playMusic(String file, boolean loop, float speed) throws Exception
49 {
50 seq.setSequence(ObjectLoader.getMusic(file));
51
52 if (loop)
53 {
54 seq.setLoopCount(seq.LOOP_CONTINUOUSLY);
55 } else {
56 seq.setLoopCount(0);
57 }
58
59 seq.setTempoFactor(speed);
60
61 seq.start();
62 }
63
64 public static void stopMusic() throws Exception
65 {
66 if (seq == null)
67 {
68 init();
69 }
70
71 seq.stop();
72 }
73
74}
75
diff --git a/src/com/fourisland/fourpuzzle/Direction.java b/src/com/fourisland/fourpuzzle/Direction.java new file mode 100644 index 0000000..e3a6cb8 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/Direction.java
@@ -0,0 +1,17 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8/**
9 *
10 * @author hatkirby
11 */
12public enum Direction {
13 North,
14 East,
15 South,
16 West
17}
diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java new file mode 100644 index 0000000..45e6c22 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/Display.java
@@ -0,0 +1,105 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8import com.fourisland.fourpuzzle.transition.Transition;
9import com.fourisland.fourpuzzle.transition.TransitionCallbackThread;
10import java.awt.Graphics2D;
11import java.awt.Image;
12import java.awt.Toolkit;
13import java.awt.image.VolatileImage;
14import javax.swing.JDialog;
15
16/**
17 *
18 * @author hatkirby
19 */
20public class Display {
21
22 public static int tileAnimationFrame = 0;
23
24 public static void render(JDialog gameFrame) throws Exception
25 {
26 if (enabled)
27 {
28 VolatileImage vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
29 render(gameFrame, vImg);
30
31 Image img = null;
32 do
33 {
34 int returnCode = vImg.validate(gameFrame.getGraphicsConfiguration());
35 if (returnCode == VolatileImage.IMAGE_RESTORED)
36 {
37 render(gameFrame, vImg);
38 } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE)
39 {
40 vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
41 render(gameFrame, vImg);
42 }
43
44 img = vImg;
45 } while (vImg.contentsLost());
46
47 gameFrame.getContentPane().getGraphics().drawImage(img, 0, 0, gameFrame.getContentPane().getWidth(), gameFrame.getContentPane().getHeight(), gameFrame);
48 img.flush();
49 Toolkit.getDefaultToolkit().sync();
50
51 if (tileAnimationFrame == 15)
52 {
53 tileAnimationFrame = 0;
54 } else {
55 tileAnimationFrame++;
56 }
57 }
58 }
59
60 private static void render(JDialog gameFrame, VolatileImage vImg) throws Exception
61 {
62 if (vImg.validate(gameFrame.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE)
63 {
64 vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT);
65 }
66
67 Graphics2D g = vImg.createGraphics();
68
69 if (transition != null)
70 {
71 transition.render(g);
72 }
73
74 Game.getGameState().render(g);
75 g.dispose();
76 }
77
78 public static void transition(Transition transition, Runnable callback)
79 {
80 setTransition(transition);
81
82 new Thread(new TransitionCallbackThread(callback)).start();
83 }
84
85 private static Transition transition;
86 public static Transition getTransition()
87 {
88 return transition;
89 }
90 public static void setTransition(Transition transition)
91 {
92 Display.transition = transition;
93 }
94
95 private static boolean enabled = true;
96 public static boolean isEnabled()
97 {
98 return enabled;
99 }
100 public static void setEnabled(boolean aEnabled)
101 {
102 enabled = aEnabled;
103 }
104
105}
diff --git a/src/com/fourisland/fourpuzzle/Game.java b/src/com/fourisland/fourpuzzle/Game.java new file mode 100644 index 0000000..3e79dc5 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/Game.java
@@ -0,0 +1,62 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent;
9import com.fourisland.fourpuzzle.gamestate.GameState;
10import java.awt.event.KeyEvent;
11
12/**
13 *
14 * @author hatkirby
15 */
16public class Game {
17
18 public static final int WIDTH = 320;
19 public static final int HEIGHT = 240;
20
21 private static SaveFile saveFile;
22 public static SaveFile getSaveFile()
23 {
24 return saveFile;
25 }
26 public static void setSaveFile(SaveFile saveFile)
27 {
28 Game.saveFile = saveFile;
29 }
30
31 private static GameState gameState;
32 public static GameState getGameState()
33 {
34 return gameState;
35 }
36 public static void setGameState(GameState gameState) throws Exception
37 {
38 if (Game.gameState != null)
39 {
40 Game.gameState.deinitalize();
41 }
42
43 Game.gameState = gameState;
44 Game.gameState.initalize();
45 }
46
47 private static KeyEvent key;
48 public static KeyEvent getKey()
49 {
50 return key;
51 }
52 public static void setKey(KeyEvent key)
53 {
54 Game.key = key;
55 }
56
57 public static HeroEvent getHeroEvent()
58 {
59 return getSaveFile().getHero();
60 }
61
62}
diff --git a/src/com/fourisland/fourpuzzle/GameCharacter.java b/src/com/fourisland/fourpuzzle/GameCharacter.java new file mode 100644 index 0000000..da0ee9e --- /dev/null +++ b/src/com/fourisland/fourpuzzle/GameCharacter.java
@@ -0,0 +1,68 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8/**
9 *
10 * @author hatkirby
11 */
12public class GameCharacter {
13
14 public GameCharacter(String name)
15 {
16 this.name = name;
17 }
18
19 private String name;
20 public String getName()
21 {
22 return name;
23 }
24 public void setName(String name)
25 {
26 this.name = name;
27 }
28
29 private int level = 1;
30 public int getLevel() {
31 return level;
32 }
33 public void setLevel(int level)
34 {
35 this.level = level;
36 }
37
38 private boolean inParty = false;
39 public boolean isInParty()
40 {
41 return inParty;
42 }
43 public void setInParty(boolean inParty)
44 {
45 this.inParty = inParty;
46 }
47
48 private String graphic = "blank";
49 public String getGraphic()
50 {
51 return graphic;
52 }
53 public void setGraphic(String graphic)
54 {
55 this.graphic = graphic;
56 }
57
58 private int graphicOffset = 0;
59 public int getGraphicOffset()
60 {
61 return graphicOffset;
62 }
63 public void setGraphicOffset(int graphicOffset)
64 {
65 this.graphicOffset = graphicOffset;
66 }
67
68}
diff --git a/src/com/fourisland/fourpuzzle/GameCharacters.java b/src/com/fourisland/fourpuzzle/GameCharacters.java new file mode 100644 index 0000000..ef945c5 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/GameCharacters.java
@@ -0,0 +1,79 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8import com.fourisland.fourpuzzle.gamestate.GameOverGameState;
9import java.util.ArrayList;
10
11/**
12 *
13 * @author hatkirby
14 */
15public class GameCharacters implements Cloneable {
16
17 private GameCharacters()
18 {
19 }
20
21 public static GameCharacters INSTANCE = new GameCharacters();
22
23 public void add(GameCharacter e)
24 {
25 characters.add(e);
26 }
27
28 public GameCharacter getLeader() throws Exception
29 {
30 int i = 0;
31 for (i=0;i<characters.size();i++)
32 {
33 if (characters.get(i).isInParty())
34 {
35 return characters.get(i);
36 }
37 }
38
39 Game.setGameState(new GameOverGameState());
40 throw new NoCharactersInPartyException();
41 }
42 public GameCharacters newInstance() throws CloneNotSupportedException
43 {
44 return (GameCharacters) clone();
45 }
46
47 private ArrayList<GameCharacter> characters = new ArrayList<GameCharacter>();
48
49 public boolean exists(String heroName) {
50 int i=0;
51 for (i=0;i<characters.size();i++)
52 {
53 if (characters.get(i).getName().equals(heroName))
54 {
55 return true;
56 }
57 }
58
59 return false;
60 }
61
62 public GameCharacter get(Integer get) {
63 return characters.get(get);
64 }
65
66 public GameCharacter get(String heroName) throws NullPointerException {
67 int i=0;
68 for (i=0;i<characters.size();i++)
69 {
70 if (characters.get(i).getName().equals(heroName))
71 {
72 return characters.get(i);
73 }
74 }
75
76 throw new NullPointerException("Could not find character \"" + heroName + "\"");
77 }
78
79}
diff --git a/src/com/fourisland/fourpuzzle/Layer.java b/src/com/fourisland/fourpuzzle/Layer.java new file mode 100644 index 0000000..88b53ed --- /dev/null +++ b/src/com/fourisland/fourpuzzle/Layer.java
@@ -0,0 +1,16 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8/**
9 *
10 * @author hatkirby
11 */
12public enum Layer {
13 Above,
14 Middle,
15 Below
16}
diff --git a/src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java b/src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java new file mode 100644 index 0000000..5d6d457 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java
@@ -0,0 +1,14 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle;
7
8/**
9 *
10 * @author hatkirby
11 */
12public class NoCharactersInPartyException extends Exception {
13
14}
diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java new file mode 100644 index 0000000..7a9aa6f --- /dev/null +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java
@@ -0,0 +1,163 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package com.fourisland.fourpuzzle;
6
7import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState;
8import java.awt.GraphicsEnvironment;
9import java.awt.event.KeyAdapter;
10import java.awt.event.KeyEvent;
11import java.awt.event.WindowAdapter;
12import java.awt.event.WindowEvent;
13import javax.swing.JDialog;
14import javax.swing.JFrame;
15import javax.swing.JLabel;
16import org.jdesktop.application.Application;
17
18/**
19 *
20 * @author hatkirby
21 */
22public class PuzzleApplication extends Application {
23
24 public static PuzzleApplication INSTANCE;
25 public static JDialog gameFrame;
26 public static boolean debugSpeed = false;
27 public static boolean stretchScreen = true;
28 public static boolean gameSleep = false;
29
30 /**
31 * @param args the command line arguments
32 */
33 public static void main(String[] args) {
34 launch(PuzzleApplication.class, args);
35 }
36
37 @Override
38 protected void startup() {
39 INSTANCE = this;
40
41 gameFrame = new JDialog(new JFrame(), false);
42 gameFrame.setTitle("The Hat");
43 gameFrame.setSize(Game.WIDTH * 2, Game.HEIGHT * 2);
44 gameFrame.setResizable(false);
45 gameFrame.addWindowListener(new WindowAdapter() {
46 @Override
47 public void windowClosing(WindowEvent e) {
48 System.exit(0);
49 }
50
51 @Override
52 public void windowActivated(WindowEvent e) {
53 gameSleep = false;
54 }
55
56 @Override
57 public void windowDeactivated(WindowEvent e) {
58 gameSleep = true;
59 }
60 });
61 gameFrame.addKeyListener(new KeyAdapter() {
62 @Override
63 public void keyPressed(KeyEvent e)
64 {
65 if (e.getKeyCode() == KeyEvent.VK_F4)
66 {
67 GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(gameFrame);
68 } else if (e.getKeyCode() == KeyEvent.VK_F5)
69 {
70 stretchScreen = !stretchScreen;
71
72 if (stretchScreen)
73 {
74 gameFrame.setSize(Game.WIDTH * 2, Game.HEIGHT * 2);
75 } else {
76 gameFrame.setSize(Game.WIDTH, Game.HEIGHT);
77 }
78 } else if (e.getKeyCode() == KeyEvent.VK_SHIFT)
79 {
80 if (INSTANCE.getContext().getResourceMap().getBoolean("debugMode"))
81 {
82 debugSpeed = true;
83 }
84 } else {
85 Game.setKey(e);
86 }
87 }
88
89 @Override
90 public void keyReleased(KeyEvent e)
91 {
92 if (e.getKeyCode() == KeyEvent.VK_SHIFT)
93 {
94 debugSpeed = false;
95 } else {
96 e.setKeyCode(KeyEvent.VK_UNDEFINED);
97 Game.setKey(e);
98 }
99 }
100 });
101 gameFrame.setVisible(true);
102
103 new Thread(new Runnable() {
104 public void run() {
105 try {
106 Audio.init();
107 Game.setGameState(new TitleScreenGameState());
108
109 long iTickCount = System.currentTimeMillis();
110 int iTickDelay = (1000 / 20); // 20 fps
111 long iTickTrigger = iTickCount + iTickDelay;
112
113 while (true)
114 {
115 iTickCount = System.currentTimeMillis();
116
117 if ((iTickCount > iTickTrigger) && (!gameSleep))
118 {
119 if (Game.getKey() != null)
120 {
121 Game.getGameState().processInput();
122 }
123
124 Game.getGameState().doGameCycle();
125 Display.render(gameFrame);
126
127 if (!debugSpeed)
128 {
129 iTickTrigger = iTickCount + iTickDelay;
130 }
131 }
132 }
133 } catch (Throwable ex) {
134 JFrame errorBox = new JFrame(ex.getClass().getSimpleName());
135 JLabel text = new JLabel();
136 text.setText("<HTML><CENTER>I'm sorry, but " + INSTANCE.getContext().getResourceMap().getString("Application.title") +
137 " has run into an error and been forced to quit.<BR>Your save file has not been kept. The error was:<BR><BR>" +
138 ex.getMessage() + "</CENTER>");
139 if (ex instanceof Error)
140 {
141 text.setText(text.getText() + "<P><CENTER>We have identified this problem as a serious error in the game.");
142 }
143 errorBox.add(text);
144 errorBox.addWindowListener(new WindowAdapter() {
145 @Override
146 public void windowClosing(WindowEvent e) {
147 System.exit(0);
148 }
149 });
150 errorBox.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
151 errorBox.pack();
152 errorBox.setVisible(true);
153 ex.printStackTrace();
154 }
155 }
156 },"GameCycle").start();
157 }
158
159 public String getGamePackage()
160 {
161 return INSTANCE.getContext().getResourceMap().getString("Application.package");
162 }
163}
diff --git a/src/com/fourisland/fourpuzzle/SaveFile.java b/src/com/fourisland/fourpuzzle/SaveFile.java new file mode 100644 index 0000000..b4f2d68 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/SaveFile.java
@@ -0,0 +1,97 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package com.fourisland.fourpuzzle;
6
7import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent;
8import java.io.IOException;
9import java.io.InputStream;
10import java.io.ObjectInputStream;
11import java.io.ObjectOutputStream;
12import java.io.OutputStream;
13import java.io.Serializable;
14import java.util.HashMap;
15
16/**
17 *
18 * @author hatkirby
19 */
20public class SaveFile implements Serializable {
21
22 /**
23 * Creates a new SaveFile
24 * @throws java.lang.CloneNotSupportedException
25 */
26 public SaveFile() throws CloneNotSupportedException
27 {
28 switches = new HashMap<String, Boolean>();
29 party = GameCharacters.INSTANCE.newInstance();
30 variables = new HashMap<String, Integer>();
31 currentMap = new String();
32 hero = new HeroEvent();
33 }
34
35 /**
36 * Loads a SaveFile
37 * @param file The ID of the SaveFile to load
38 * @throws java.io.IOException
39 * @throws java.lang.ClassNotFoundException
40 */
41 public SaveFile(int file) throws IOException, ClassNotFoundException
42 {
43 InputStream is = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openInputFile("Save" + file + ".sav");
44 ObjectInputStream ois = new ObjectInputStream(is);
45 SaveFile temp = (SaveFile) ois.readObject();
46
47 switches = temp.getSwitches();
48 variables = temp.getVariables();
49 party = temp.getParty();
50 currentMap = temp.getCurrentMap();
51
52 ois.close();
53 }
54
55 public void saveGame(int file) throws IOException
56 {
57 OutputStream os = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openOutputFile("Save" + file + ".sav");
58 ObjectOutputStream oos = new ObjectOutputStream(os);
59 oos.writeObject(this);
60 oos.close();
61 }
62
63 private HashMap<String, Boolean> switches;
64 public HashMap<String, Boolean> getSwitches() {
65 return switches;
66 }
67
68 private GameCharacters party;
69 public GameCharacters getParty() {
70 return party;
71 }
72
73 private HashMap<String, Integer> variables;
74 public HashMap<String, Integer> getVariables() {
75 return variables;
76 }
77
78 private String currentMap;
79 public String getCurrentMap()
80 {
81 return currentMap;
82 }
83 public void setCurrentMap(String currentMap)
84 {
85 this.currentMap = currentMap;
86 }
87
88 private HeroEvent hero;
89 public HeroEvent getHero()
90 {
91 return hero;
92 }
93 public void setHero(HeroEvent hero)
94 {
95 this.hero = hero;
96 }
97}
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
6package com.fourisland.fourpuzzle.gamestate;
7
8import com.fourisland.fourpuzzle.Audio;
9import com.fourisland.fourpuzzle.Display;
10import com.fourisland.fourpuzzle.Game;
11import com.fourisland.fourpuzzle.SaveFile;
12import com.fourisland.fourpuzzle.transition.SquareTransition;
13import com.fourisland.fourpuzzle.util.ObjectLoader;
14import java.awt.Graphics2D;
15import java.awt.event.KeyEvent;
16import java.util.logging.Level;
17import java.util.logging.Logger;
18
19/**
20 *
21 * @author hatkirby
22 */
23public 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
6package com.fourisland.fourpuzzle.gamestate;
7
8import java.awt.Graphics2D;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate;
7
8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
10import com.fourisland.fourpuzzle.util.ObjectLoader;
11import java.awt.Graphics2D;
12import java.awt.event.KeyEvent;
13
14/**
15 *
16 * @author hatkirby
17 */
18public 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
6package com.fourisland.fourpuzzle.gamestate.mapview;
7
8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.util.ObjectLoader;
10import java.awt.image.BufferedImage;
11
12/**
13 *
14 * @author hatkirby
15 */
16public 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
6package com.fourisland.fourpuzzle.gamestate.mapview;
7
8import com.fourisland.fourpuzzle.PuzzleApplication;
9import com.fourisland.fourpuzzle.util.ObjectLoader;
10import java.awt.Graphics;
11import java.awt.Image;
12import java.awt.image.BufferedImage;
13import java.util.HashMap;
14import java.util.Vector;
15
16/**
17 *
18 * @author hatkirby
19 */
20public 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
6package com.fourisland.fourpuzzle.gamestate.mapview;
7
8import com.fourisland.fourpuzzle.*;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate.mapview;
7
8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
10import java.awt.Dimension;
11import java.util.ArrayList;
12import java.util.HashMap;
13import java.util.Vector;
14
15/**
16 *
17 * @author hatkirby
18 */
19public 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
6package com.fourisland.fourpuzzle.gamestate.mapview;
7
8import com.fourisland.fourpuzzle.Audio;
9import com.fourisland.fourpuzzle.gamestate.*;
10import com.fourisland.fourpuzzle.Direction;
11import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent;
12import com.fourisland.fourpuzzle.Game;
13import com.fourisland.fourpuzzle.Layer;
14import com.fourisland.fourpuzzle.PuzzleApplication;
15import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime;
16import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
17import java.awt.Graphics2D;
18import java.awt.event.KeyEvent;
19import java.util.ArrayList;
20
21/**
22 *
23 * @author hatkirby
24 */
25public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8/**
9 *
10 * @author hatkirby
11 */
12public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition;
9import java.util.ArrayList;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.Layer;
10import java.awt.Graphics;
11import java.awt.Point;
12
13/**
14 *
15 * @author hatkirby
16 */
17public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8/**
9 *
10 * @author hatkirby
11 */
12public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8/**
9 *
10 * @author hatkirby
11 */
12public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import com.fourisland.fourpuzzle.Layer;
9import java.awt.Graphics;
10import java.awt.Point;
11import com.fourisland.fourpuzzle.Direction;
12import com.fourisland.fourpuzzle.Game;
13import com.fourisland.fourpuzzle.GameCharacter;
14import com.fourisland.fourpuzzle.gamestate.mapview.CharSet;
15import com.fourisland.fourpuzzle.NoCharactersInPartyException;
16
17/**
18 *
19 * @author hatkirby
20 */
21public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import com.fourisland.fourpuzzle.Layer;
9import java.awt.Graphics;
10import java.awt.Point;
11import java.util.ArrayList;
12import com.fourisland.fourpuzzle.Direction;
13import com.fourisland.fourpuzzle.gamestate.mapview.Map;
14
15/**
16 *
17 * @author hatkirby
18 */
19public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import com.fourisland.fourpuzzle.Layer;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.precondition.Precondition;
10import java.util.ArrayList;
11import com.fourisland.fourpuzzle.Direction;
12import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic;
13import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.EventGraphic;
14import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.MovementType;
15import com.fourisland.fourpuzzle.gamestate.mapview.event.movement.StayStillMovementType;
16import com.fourisland.fourpuzzle.util.Functions;
17import java.awt.image.BufferedImage;
18
19/**
20 *w
21 * @author hatkirby
22 */
23public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent;
10import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
11import java.util.concurrent.BrokenBarrierException;
12import java.util.concurrent.CyclicBarrier;
13import java.util.logging.Level;
14import java.util.logging.Logger;
15
16/**
17 *
18 * @author hatkirby
19 */
20public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic;
7
8import com.fourisland.fourpuzzle.Direction;
9import java.awt.image.BufferedImage;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic;
7
8import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.gamestate.mapview.CharSet;
10import java.awt.image.BufferedImage;
11
12/**
13 *
14 * @author hatkirby
15 */
16public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic;
7
8import com.fourisland.fourpuzzle.Direction;
9import java.awt.image.BufferedImage;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.movement;
7
8import com.fourisland.fourpuzzle.Direction;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.movement;
7
8import com.fourisland.fourpuzzle.Direction;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.movement;
7
8import com.fourisland.fourpuzzle.Direction;
9import java.util.Random;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.movement;
7
8import com.fourisland.fourpuzzle.Direction;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition;
7
8import com.fourisland.fourpuzzle.Game;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition;
7
8import com.fourisland.fourpuzzle.Game;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition;
7
8/**
9 *
10 * @author hatkirby
11 */
12public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition;
7
8import com.fourisland.fourpuzzle.Game;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition;
7
8import com.fourisland.fourpuzzle.util.Comparison;
9import com.fourisland.fourpuzzle.Game;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition;
7
8import com.fourisland.fourpuzzle.util.Comparison;
9import com.fourisland.fourpuzzle.Game;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove;
7
8import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
7package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove;
8
9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove;
7
8import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
9import java.util.concurrent.CountDownLatch;
10import java.util.concurrent.CyclicBarrier;
11import java.util.logging.Level;
12import java.util.logging.Logger;
13
14/**
15 *
16 * @author hatkirby
17 */
18public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove;
7
8import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
10
11/**
12 *
13 * @author hatkirby
14 */
15public 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
6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove;
7
8import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
9
10/**
11 *
12 * @author hatkirby
13 */
14public 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}
diff --git a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java new file mode 100644 index 0000000..dc17844 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java
@@ -0,0 +1,50 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8import java.awt.Color;
9import java.awt.Graphics2D;
10
11/**
12 *
13 * @author hatkirby
14 */
15public class SquareTransition extends Transition {
16
17 private int tick;
18 public SquareTransition(boolean from) throws TransitionUnsupportedException
19 {
20 setDirection(from);
21
22 if (from)
23 {
24 tick = 160;
25 } else {
26 tick = 0;
27 }
28 }
29
30 public void render(Graphics2D g)
31 {
32 if (((!getDirection()) && (tick == 0)) || ((getDirection()) && (tick == 160)))
33 {
34 setRunning(false);
35 return;
36 }
37
38 if (getDirection())
39 {
40 tick+=8;
41 } else {
42 tick-=8;
43 }
44
45 g.setBackground(Color.BLACK);
46 g.fillRect(0, 0, 320, 240);
47 g.setClip(160-tick, 140-tick, tick*2, tick*2-40);
48 }
49
50}
diff --git a/src/com/fourisland/fourpuzzle/transition/Transition.java b/src/com/fourisland/fourpuzzle/transition/Transition.java new file mode 100644 index 0000000..83cec17 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/Transition.java
@@ -0,0 +1,56 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8import java.awt.Graphics2D;
9
10/**
11 *
12 * @author hatkirby
13 */
14public abstract class Transition {
15
16 private boolean way;
17 protected void setDirection(boolean from) throws TransitionUnsupportedException
18 {
19 if ((from) && !(isFromSupported()))
20 {
21 throw new TransitionUnsupportedException(this.getClass().getSimpleName(), "From");
22 } else if ((!from) && !(isToSupported()))
23 {
24 throw new TransitionUnsupportedException(this.getClass().getSimpleName(), "To");
25 } else {
26 way = from;
27 }
28 }
29 public boolean getDirection()
30 {
31 return way;
32 }
33
34 public boolean isFromSupported()
35 {
36 return true;
37 }
38
39 public boolean isToSupported()
40 {
41 return true;
42 }
43
44 public abstract void render(Graphics2D g);
45
46 private boolean running = true;
47 public boolean isRunning()
48 {
49 return running;
50 }
51 public void setRunning(boolean running)
52 {
53 this.running = running;
54 }
55
56}
diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java b/src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java new file mode 100644 index 0000000..58ea0b5 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java
@@ -0,0 +1,40 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8import com.fourisland.fourpuzzle.Display;
9import java.util.logging.Level;
10import java.util.logging.Logger;
11
12/**
13 *
14 * @author hatkirby
15 */
16public class TransitionCallbackThread implements Runnable {
17
18 private Runnable callback;
19 public TransitionCallbackThread(Runnable callback)
20 {
21 this.callback = callback;
22 }
23
24 public void run()
25 {
26 while (Display.getTransition().isRunning())
27 {
28 try {
29 Thread.sleep(300);
30 } catch (InterruptedException ex) {
31 Logger.getLogger(TransitionCallbackThread.class.getName()).log(Level.SEVERE, null, ex);
32 }
33 }
34
35 //Display.setEnabled(false);
36
37 callback.run();
38 }
39
40}
diff --git a/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java b/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java new file mode 100644 index 0000000..a3d28ef --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java
@@ -0,0 +1,19 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8/**
9 *
10 * @author hatkirby
11 */
12public class TransitionUnsupportedException extends Exception {
13
14 public TransitionUnsupportedException(String className, String direction)
15 {
16 super("Transition \"" + className + "\" does not support the " + direction + " direction");
17 }
18
19}
diff --git a/src/com/fourisland/fourpuzzle/util/Comparison.java b/src/com/fourisland/fourpuzzle/util/Comparison.java new file mode 100644 index 0000000..9e5ef54 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/util/Comparison.java
@@ -0,0 +1,20 @@
1package com.fourisland.fourpuzzle.util;
2
3/*
4 * To change this template, choose Tools | Templates
5 * and open the template in the editor.
6 */
7
8
9
10/**
11 *
12 * @author hatkirby
13 */
14public enum Comparison {
15
16 Less,
17 Greater,
18 Equal
19
20}
diff --git a/src/com/fourisland/fourpuzzle/util/Functions.java b/src/com/fourisland/fourpuzzle/util/Functions.java new file mode 100644 index 0000000..5eb70cd --- /dev/null +++ b/src/com/fourisland/fourpuzzle/util/Functions.java
@@ -0,0 +1,31 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.util;
7
8import com.fourisland.fourpuzzle.gamestate.mapview.event.PossibleEvent;
9
10/**
11 *
12 * @author hatkirby
13 */
14public class Functions {
15
16 public static boolean canTurn(PossibleEvent ev) throws Exception
17 {
18 switch (ev.getAnimation())
19 {
20 case CommonWithoutStepping: return true;
21 case CommonWithStepping: return true;
22 case WithoutStepping: return true;
23 case FixedGraphic: return false;
24 case TurnLeft: return false;
25 case TurnRight: return false;
26 }
27
28 return false;
29 }
30
31}
diff --git a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java new file mode 100644 index 0000000..c14a8a1 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java
@@ -0,0 +1,92 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.util;
7
8//import com.alienfactory.javamappy.loader.MapLoader;
9import com.fourisland.fourpuzzle.PuzzleApplication;
10import java.awt.Image;
11import java.awt.Toolkit;
12import java.awt.image.BufferedImage;
13import java.awt.image.FilteredImageSource;
14import java.util.HashMap;
15import javax.imageio.ImageIO;
16import javax.sound.midi.MidiSystem;
17import javax.sound.midi.Sequence;
18import org.jdesktop.application.ResourceMap;
19
20/**
21 *
22 * @author hatkirby
23 */
24public class ObjectLoader {
25
26 private static HashMap<String,Object> objectCache = new HashMap<String,Object>();
27
28 public static BufferedImage getImage(String type, String name) throws Exception
29 {
30 if (!objectCache.containsKey(type + "/" + name))
31 {
32 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
33 String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png";
34 BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename));
35
36 addToObjectCache(type,name,bImg);
37 }
38
39 return (BufferedImage) objectCache.get(type + "/" + name);
40 }
41
42 public static BufferedImage getImage(String type, String name, int transparencyColor) throws Exception
43 {
44 if (!objectCache.containsKey(type + "/" + name))
45 {
46 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
47 String filename = rm.getResourcesDir() + type + "/" + name + ".png";
48 BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename));
49 bImg = new BufferedImage(bImg.getWidth(), bImg.getHeight(), BufferedImage.TYPE_INT_RGB);
50 Image image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(bImg.getSource(), new TransparentImageFilter(transparencyColor)));
51 bImg.createGraphics().drawImage(image, 0, 0, null);
52
53 addToObjectCache(type,name,bImg);
54 }
55
56 return (BufferedImage) objectCache.get(type + "/" + name);
57 }
58
59 /*public static com.alienfactory.javamappy.Map getMap(String name) throws Exception
60 {
61 ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap();
62 String filename = rm.getResourcesDir() + "mapdata/" + name + ".fmp";
63
64 //com.alienfactory.javamappy.Map map = MapLoader.loadMap(rm.getClassLoader().getResourceAsStream(filename));
65 return map;
66 }*/
67
68 public static void addToObjectCache(String type, String name, Object object) throws Exception
69 {
70 if (objectCache.size() >= 100)
71 {
72 objectCache.clear();
73 }
74
75 objectCache.put(type + "/" + name, object);
76 }
77
78 public static Sequence getMusic(String name) throws Exception
79 {
80 if (!objectCache.containsKey("Music/" + name))
81 {
82 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap();
83 String filename = rm.getResourcesDir() + "music/" + name + ".mid";
84 Sequence seq = MidiSystem.getSequence(rm.getClassLoader().getResourceAsStream(filename));
85
86 addToObjectCache("Music", name, seq);
87 }
88
89 return (Sequence) objectCache.get("Music/" + name);
90 }
91
92}
diff --git a/src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java b/src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java new file mode 100644 index 0000000..bd830cc --- /dev/null +++ b/src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java
@@ -0,0 +1,46 @@
1/*
2 * Tiled Map Editor, (c) 2004-2006
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * Adam Turk <aturk@biggeruniverse.com>
10 * Bjorn Lindeijer <b.lindeijer@xs4all.nl>
11 */
12
13package com.fourisland.fourpuzzle.util;
14
15import java.awt.image.RGBImageFilter;
16
17/**
18 * This filter is used for filtering out a given "transparent" color from an
19 * image. Sometimes known as magic pink.
20 */
21public class TransparentImageFilter extends RGBImageFilter
22{
23 int trans;
24
25 /**
26 * @param col the color to make transparent
27 */
28 public TransparentImageFilter(int col) {
29 trans = col;
30
31 // The filter doesn't depend on pixel location
32 canFilterIndexColorModel = true;
33 }
34
35 /**
36 * Filters the given pixel. It returns a transparent pixel for pixels that
37 * match the transparency color, or the existing pixel for anything else.
38 */
39 public int filterRGB(int x, int y, int rgb) {
40 if (rgb == trans) {
41 return 0;
42 } else {
43 return rgb;
44 }
45 }
46} \ No newline at end of file