From 69b495c392bffe96dab97306a42466edd4b2474e Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 17 Jan 2009 10:36:37 -0500 Subject: Imported sources --- src/com/fourisland/fourpuzzle/Audio.java | 75 +++++++ src/com/fourisland/fourpuzzle/Direction.java | 17 ++ src/com/fourisland/fourpuzzle/Display.java | 105 ++++++++++ src/com/fourisland/fourpuzzle/Game.java | 62 ++++++ src/com/fourisland/fourpuzzle/GameCharacter.java | 68 +++++++ src/com/fourisland/fourpuzzle/GameCharacters.java | 79 +++++++ src/com/fourisland/fourpuzzle/Layer.java | 16 ++ .../fourpuzzle/NoCharactersInPartyException.java | 14 ++ .../fourisland/fourpuzzle/PuzzleApplication.java | 163 +++++++++++++++ src/com/fourisland/fourpuzzle/SaveFile.java | 97 +++++++++ .../fourpuzzle/gamestate/GameOverGameState.java | 60 ++++++ .../fourisland/fourpuzzle/gamestate/GameState.java | 34 ++++ .../fourpuzzle/gamestate/TitleScreenGameState.java | 49 +++++ .../fourpuzzle/gamestate/mapview/CharSet.java | 38 ++++ .../fourpuzzle/gamestate/mapview/ChipSet.java | 50 +++++ .../fourpuzzle/gamestate/mapview/ChipSetData.java | 83 ++++++++ .../fourpuzzle/gamestate/mapview/Map.java | 185 +++++++++++++++++ .../gamestate/mapview/MapViewGameState.java | 226 +++++++++++++++++++++ .../gamestate/mapview/event/AnimationType.java | 19 ++ .../gamestate/mapview/event/CommonEvent.java | 62 ++++++ .../fourpuzzle/gamestate/mapview/event/Event.java | 35 ++++ .../gamestate/mapview/event/EventCall.java | 25 +++ .../gamestate/mapview/event/EventCallTime.java | 16 ++ .../gamestate/mapview/event/HeroEvent.java | 157 ++++++++++++++ .../gamestate/mapview/event/LayerEvent.java | 207 +++++++++++++++++++ .../gamestate/mapview/event/PossibleEvent.java | 141 +++++++++++++ .../gamestate/mapview/event/SpecialEvent.java | 173 ++++++++++++++++ .../mapview/event/graphic/BlankEventGraphic.java | 40 ++++ .../mapview/event/graphic/CharSetEventGraphic.java | 68 +++++++ .../mapview/event/graphic/EventGraphic.java | 25 +++ .../mapview/event/movement/CustomMovementType.java | 34 ++++ .../mapview/event/movement/MovementType.java | 25 +++ .../mapview/event/movement/RandomMovementType.java | 49 +++++ .../event/movement/StayStillMovementType.java | 21 ++ .../precondition/HeroInPartyPrecondition.java | 27 +++ .../event/precondition/HeroLevelPrecondition.java | 29 +++ .../mapview/event/precondition/Precondition.java | 16 ++ .../event/precondition/SwitchPrecondition.java | 27 +++ .../precondition/VariableNumberPrecondition.java | 45 ++++ .../precondition/VariableVariablePrecondition.java | 45 ++++ .../mapview/event/specialmove/FaceMoveEvent.java | 28 +++ .../mapview/event/specialmove/MoveEvent.java | 19 ++ .../mapview/event/specialmove/MoveEventThread.java | 50 +++++ .../mapview/event/specialmove/StepMoveEvent.java | 33 +++ .../mapview/event/specialmove/WaitMoveEvent.java | 27 +++ .../fourpuzzle/transition/SquareTransition.java | 50 +++++ .../fourpuzzle/transition/Transition.java | 56 +++++ .../transition/TransitionCallbackThread.java | 40 ++++ .../transition/TransitionUnsupportedException.java | 19 ++ src/com/fourisland/fourpuzzle/util/Comparison.java | 20 ++ src/com/fourisland/fourpuzzle/util/Functions.java | 31 +++ .../fourisland/fourpuzzle/util/ObjectLoader.java | 92 +++++++++ .../fourpuzzle/util/TransparentImageFilter.java | 46 +++++ 53 files changed, 3218 insertions(+) create mode 100644 src/com/fourisland/fourpuzzle/Audio.java create mode 100644 src/com/fourisland/fourpuzzle/Direction.java create mode 100644 src/com/fourisland/fourpuzzle/Display.java create mode 100644 src/com/fourisland/fourpuzzle/Game.java create mode 100644 src/com/fourisland/fourpuzzle/GameCharacter.java create mode 100644 src/com/fourisland/fourpuzzle/GameCharacters.java create mode 100644 src/com/fourisland/fourpuzzle/Layer.java create mode 100644 src/com/fourisland/fourpuzzle/NoCharactersInPartyException.java create mode 100644 src/com/fourisland/fourpuzzle/PuzzleApplication.java create mode 100644 src/com/fourisland/fourpuzzle/SaveFile.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/GameState.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/CharSet.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSetData.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCallTime.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/BlankEventGraphic.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/CharSetEventGraphic.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/graphic/EventGraphic.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/RandomMovementType.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/StayStillMovementType.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroInPartyPrecondition.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/HeroLevelPrecondition.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/Precondition.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/SwitchPrecondition.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableNumberPrecondition.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/precondition/VariableVariablePrecondition.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/FaceMoveEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/WaitMoveEvent.java create mode 100644 src/com/fourisland/fourpuzzle/transition/SquareTransition.java create mode 100644 src/com/fourisland/fourpuzzle/transition/Transition.java create mode 100644 src/com/fourisland/fourpuzzle/transition/TransitionCallbackThread.java create mode 100644 src/com/fourisland/fourpuzzle/transition/TransitionUnsupportedException.java create mode 100644 src/com/fourisland/fourpuzzle/util/Comparison.java create mode 100644 src/com/fourisland/fourpuzzle/util/Functions.java create mode 100644 src/com/fourisland/fourpuzzle/util/ObjectLoader.java create mode 100644 src/com/fourisland/fourpuzzle/util/TransparentImageFilter.java (limited to 'src') 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle; + +import com.fourisland.fourpuzzle.util.ObjectLoader; +import javax.sound.midi.MidiSystem; +import javax.sound.midi.Sequencer; +import javax.sound.midi.Track; + +/** + * + * @author hatkirby + */ +public class Audio { + + private static Sequencer seq; + + public static void init() throws Exception + { + seq = MidiSystem.getSequencer(); + seq.open(); + + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + public void run() { + if (seq.isRunning()) + { + seq.stop(); + } + + seq.close(); + } + })); + } + + public static void playMusic(String file) throws Exception + { + playMusic(file, true, 1F); + } + + public static void playMusic(String file, boolean loop) throws Exception + { + playMusic(file, loop, 1F); + } + + public static void playMusic(String file, boolean loop, float speed) throws Exception + { + seq.setSequence(ObjectLoader.getMusic(file)); + + if (loop) + { + seq.setLoopCount(seq.LOOP_CONTINUOUSLY); + } else { + seq.setLoopCount(0); + } + + seq.setTempoFactor(speed); + + seq.start(); + } + + public static void stopMusic() throws Exception + { + if (seq == null) + { + init(); + } + + seq.stop(); + } + +} + 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle; + +/** + * + * @author hatkirby + */ +public enum Direction { + North, + East, + South, + West +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle; + +import com.fourisland.fourpuzzle.transition.Transition; +import com.fourisland.fourpuzzle.transition.TransitionCallbackThread; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Toolkit; +import java.awt.image.VolatileImage; +import javax.swing.JDialog; + +/** + * + * @author hatkirby + */ +public class Display { + + public static int tileAnimationFrame = 0; + + public static void render(JDialog gameFrame) throws Exception + { + if (enabled) + { + VolatileImage vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT); + render(gameFrame, vImg); + + Image img = null; + do + { + int returnCode = vImg.validate(gameFrame.getGraphicsConfiguration()); + if (returnCode == VolatileImage.IMAGE_RESTORED) + { + render(gameFrame, vImg); + } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) + { + vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT); + render(gameFrame, vImg); + } + + img = vImg; + } while (vImg.contentsLost()); + + gameFrame.getContentPane().getGraphics().drawImage(img, 0, 0, gameFrame.getContentPane().getWidth(), gameFrame.getContentPane().getHeight(), gameFrame); + img.flush(); + Toolkit.getDefaultToolkit().sync(); + + if (tileAnimationFrame == 15) + { + tileAnimationFrame = 0; + } else { + tileAnimationFrame++; + } + } + } + + private static void render(JDialog gameFrame, VolatileImage vImg) throws Exception + { + if (vImg.validate(gameFrame.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) + { + vImg = gameFrame.createVolatileImage(Game.WIDTH, Game.HEIGHT); + } + + Graphics2D g = vImg.createGraphics(); + + if (transition != null) + { + transition.render(g); + } + + Game.getGameState().render(g); + g.dispose(); + } + + public static void transition(Transition transition, Runnable callback) + { + setTransition(transition); + + new Thread(new TransitionCallbackThread(callback)).start(); + } + + private static Transition transition; + public static Transition getTransition() + { + return transition; + } + public static void setTransition(Transition transition) + { + Display.transition = transition; + } + + private static boolean enabled = true; + public static boolean isEnabled() + { + return enabled; + } + public static void setEnabled(boolean aEnabled) + { + enabled = aEnabled; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle; + +import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; +import com.fourisland.fourpuzzle.gamestate.GameState; +import java.awt.event.KeyEvent; + +/** + * + * @author hatkirby + */ +public class Game { + + public static final int WIDTH = 320; + public static final int HEIGHT = 240; + + private static SaveFile saveFile; + public static SaveFile getSaveFile() + { + return saveFile; + } + public static void setSaveFile(SaveFile saveFile) + { + Game.saveFile = saveFile; + } + + private static GameState gameState; + public static GameState getGameState() + { + return gameState; + } + public static void setGameState(GameState gameState) throws Exception + { + if (Game.gameState != null) + { + Game.gameState.deinitalize(); + } + + Game.gameState = gameState; + Game.gameState.initalize(); + } + + private static KeyEvent key; + public static KeyEvent getKey() + { + return key; + } + public static void setKey(KeyEvent key) + { + Game.key = key; + } + + public static HeroEvent getHeroEvent() + { + return getSaveFile().getHero(); + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle; + +/** + * + * @author hatkirby + */ +public class GameCharacter { + + public GameCharacter(String name) + { + this.name = name; + } + + private String name; + public String getName() + { + return name; + } + public void setName(String name) + { + this.name = name; + } + + private int level = 1; + public int getLevel() { + return level; + } + public void setLevel(int level) + { + this.level = level; + } + + private boolean inParty = false; + public boolean isInParty() + { + return inParty; + } + public void setInParty(boolean inParty) + { + this.inParty = inParty; + } + + private String graphic = "blank"; + public String getGraphic() + { + return graphic; + } + public void setGraphic(String graphic) + { + this.graphic = graphic; + } + + private int graphicOffset = 0; + public int getGraphicOffset() + { + return graphicOffset; + } + public void setGraphicOffset(int graphicOffset) + { + this.graphicOffset = graphicOffset; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle; + +import com.fourisland.fourpuzzle.gamestate.GameOverGameState; +import java.util.ArrayList; + +/** + * + * @author hatkirby + */ +public class GameCharacters implements Cloneable { + + private GameCharacters() + { + } + + public static GameCharacters INSTANCE = new GameCharacters(); + + public void add(GameCharacter e) + { + characters.add(e); + } + + public GameCharacter getLeader() throws Exception + { + int i = 0; + for (i=0;i characters = new ArrayList(); + + public boolean exists(String heroName) { + int i=0; + for (i=0;i iTickTrigger) && (!gameSleep)) + { + if (Game.getKey() != null) + { + Game.getGameState().processInput(); + } + + Game.getGameState().doGameCycle(); + Display.render(gameFrame); + + if (!debugSpeed) + { + iTickTrigger = iTickCount + iTickDelay; + } + } + } + } catch (Throwable ex) { + JFrame errorBox = new JFrame(ex.getClass().getSimpleName()); + JLabel text = new JLabel(); + text.setText("
I'm sorry, but " + INSTANCE.getContext().getResourceMap().getString("Application.title") + + " has run into an error and been forced to quit.
Your save file has not been kept. The error was:

" + + ex.getMessage() + "
"); + if (ex instanceof Error) + { + text.setText(text.getText() + "

We have identified this problem as a serious error in the game."); + } + errorBox.add(text); + errorBox.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + errorBox.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + errorBox.pack(); + errorBox.setVisible(true); + ex.printStackTrace(); + } + } + },"GameCycle").start(); + } + + public String getGamePackage() + { + return INSTANCE.getContext().getResourceMap().getString("Application.package"); + } +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.fourpuzzle; + +import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.util.HashMap; + +/** + * + * @author hatkirby + */ +public class SaveFile implements Serializable { + + /** + * Creates a new SaveFile + * @throws java.lang.CloneNotSupportedException + */ + public SaveFile() throws CloneNotSupportedException + { + switches = new HashMap(); + party = GameCharacters.INSTANCE.newInstance(); + variables = new HashMap(); + currentMap = new String(); + hero = new HeroEvent(); + } + + /** + * Loads a SaveFile + * @param file The ID of the SaveFile to load + * @throws java.io.IOException + * @throws java.lang.ClassNotFoundException + */ + public SaveFile(int file) throws IOException, ClassNotFoundException + { + InputStream is = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openInputFile("Save" + file + ".sav"); + ObjectInputStream ois = new ObjectInputStream(is); + SaveFile temp = (SaveFile) ois.readObject(); + + switches = temp.getSwitches(); + variables = temp.getVariables(); + party = temp.getParty(); + currentMap = temp.getCurrentMap(); + + ois.close(); + } + + public void saveGame(int file) throws IOException + { + OutputStream os = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openOutputFile("Save" + file + ".sav"); + ObjectOutputStream oos = new ObjectOutputStream(os); + oos.writeObject(this); + oos.close(); + } + + private HashMap switches; + public HashMap getSwitches() { + return switches; + } + + private GameCharacters party; + public GameCharacters getParty() { + return party; + } + + private HashMap variables; + public HashMap getVariables() { + return variables; + } + + private String currentMap; + public String getCurrentMap() + { + return currentMap; + } + public void setCurrentMap(String currentMap) + { + this.currentMap = currentMap; + } + + private HeroEvent hero; + public HeroEvent getHero() + { + return hero; + } + public void setHero(HeroEvent hero) + { + this.hero = hero; + } +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate; + +import com.fourisland.fourpuzzle.Audio; +import com.fourisland.fourpuzzle.Display; +import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.SaveFile; +import com.fourisland.fourpuzzle.transition.SquareTransition; +import com.fourisland.fourpuzzle.util.ObjectLoader; +import java.awt.Graphics2D; +import java.awt.event.KeyEvent; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +public class GameOverGameState implements GameState { + + public void initalize() throws Exception + { + Audio.playMusic("GameOver"); + } + + public void deinitalize() throws Exception + { + Audio.stopMusic(); + } + + public void processInput() throws Exception { + if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) + { + Game.setSaveFile(new SaveFile()); + //Display.transition(SquareTransition.class, this, new TitleScreenGameState()); + Display.transition(new SquareTransition(true), new Runnable() { + public void run() { + try { + Game.setGameState(new TitleScreenGameState()); + } catch (Exception ex) { + Logger.getLogger(GameOverGameState.class.getName()).log(Level.SEVERE, null, ex); + } + } + }); + } + } + + public void doGameCycle() throws Exception { + // Do nothing + } + + public void render(Graphics2D g) throws Exception { + g.drawImage(ObjectLoader.getImage("Picture", "GameOver"), 0, 0, null); + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate; + +import java.awt.Graphics2D; + +/** + * + * @author hatkirby + */ +public interface GameState { + + public void initalize() throws Exception; + public void deinitalize() throws Exception; + + public void processInput() throws Exception; + public void doGameCycle() throws Exception; + public void render(Graphics2D g) throws Exception; + +} + +/* + TitleScreen + MapView + Battle + GameOver + Menu + LoadFile + SaveFile + Transition +*/ \ 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate; + +import com.fourisland.fourpuzzle.*; +import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; +import com.fourisland.fourpuzzle.util.ObjectLoader; +import java.awt.Graphics2D; +import java.awt.event.KeyEvent; + +/** + * + * @author hatkirby + */ +public class TitleScreenGameState implements GameState { + + public void initalize() throws Exception + { + Audio.playMusic("Opening"); + } + + public void deinitalize() throws Exception + { + Audio.stopMusic(); + } + + public void processInput() throws Exception { + if (Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) + { + Game.setSaveFile(new SaveFile()); + Game.setGameState(new MapViewGameState("TestMap", 1, 2)); + //Game.setGameState(new SquareTransition(this, new MapViewGameState("TestMap", 0, 0))); + //Game.setGameState(new TransitionGameState(this, this)); + //Game.setGameState(new GameOverGameState()); + } + } + + public void doGameCycle() throws Exception { + // Do nothing, yet + } + + public void render(Graphics2D g) throws Exception { + g.drawImage(ObjectLoader.getImage("Picture", "Title"), 0, 0, null); + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview; + +import com.fourisland.fourpuzzle.*; +import com.fourisland.fourpuzzle.util.ObjectLoader; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public class CharSet { + + private BufferedImage charSetImage; + + private CharSet() + { + } + + public BufferedImage getImage(int offset, Direction direction, int step) + { + int sx = ((offset % 4) * 72) + (step * 24); + int sy = ((offset / 4) * 128) + (direction.ordinal() * 32); + + return charSetImage.getSubimage(sx, sy, 24, 32); + } + + public static CharSet getCharSet(String charSet) throws Exception { + CharSet temp = new CharSet(); + temp.charSetImage = ObjectLoader.getImage("CharSet", charSet); + return temp; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview; + +import com.fourisland.fourpuzzle.PuzzleApplication; +import com.fourisland.fourpuzzle.util.ObjectLoader; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.util.HashMap; +import java.util.Vector; + +/** + * + * @author hatkirby + */ +public abstract class ChipSet { + + public abstract void initalize(); + + private BufferedImage chipSetImage; + public BufferedImage getImage(int offset) + { + int sx = (offset % 8) * 16; + int sy = (offset / 8) * 16; + + return chipSetImage.getSubimage(sx, sy, 16, 16); + } + + public static ChipSet getChipSet(String chipSet) throws Exception + { + Class chipSetClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.chipset." + chipSet); + Object chipSetObject = chipSetClass.newInstance(); + ChipSet temp = (ChipSet) chipSetObject; + temp.initalize(); + temp.chipSetImage = ObjectLoader.getImage("ChipSet", chipSet); + + return temp; + } + + private HashMap chipSetData = new HashMap(); //162 + public HashMap getChipSetData() + { + return chipSetData; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview; + +import com.fourisland.fourpuzzle.*; + +/** + * + * @author hatkirby + */ +public class ChipSetData { + + private String terrain; + private Layer layer; + private boolean enableNorth; + private boolean enableWest; + private boolean enableSouth; + private boolean enableEast; + + public ChipSetData(String terrain, Layer layer) + { + this.terrain = terrain; + this.layer = layer; + + if (layer == Layer.Middle) + { + enableNorth = false; + enableWest = false; + enableSouth = false; + enableEast = false; + } else { + enableNorth = true; + enableWest = true; + enableSouth = true; + enableEast = true; + } + } + + public ChipSetData(String terrain, boolean enableNorth, boolean enableWest, boolean enableSouth, boolean enableEast) + { + this.terrain = terrain; + + if (!enableNorth && !enableWest && !enableSouth && !enableEast) + { + layer = Layer.Middle; + } else { + layer = Layer.Below; + } + + this.enableNorth = enableNorth; + this.enableWest = enableWest; + this.enableSouth = enableSouth; + this.enableEast = enableEast; + } + + public String getTerrain() { + return terrain; + } + + public Layer getLayer() { + return layer; + } + + public boolean isEnableNorth() { + return enableNorth; + } + + public boolean isEnableWest() { + return enableWest; + } + + public boolean isEnableSouth() { + return enableSouth; + } + + public boolean isEnableEast() { + return enableEast; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview; + +import com.fourisland.fourpuzzle.*; +import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; +import java.awt.Dimension; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Vector; + +/** + * + * @author hatkirby + */ +public abstract class Map { + + public abstract void initalize() throws Exception; + + public void initalize(Dimension size) + { + setSize(size); + mapData = new Vector>(); + } + + private Dimension size; + public Dimension getSize() + { + return size; + } + public void setSize(Dimension size) + { + if ((size.width < 20) || (size.height < 15)) + { + this.size = new Dimension(20,15); + } else { + this.size = size; + } + } + + private ArrayList events = new ArrayList(); + public ArrayList getEvents() + { + return events; + } + public LayerEvent getEvent(String event) + { + int i=0; + for (i=0;i cSID = cSI.getChipSetData(); + for (i=0;i> mapData; + public Vector> getMapData() { + return mapData; + } + + private String music; + public String getMusic() + { + return music; + } + public void setMusic(String music) + { + this.music = music; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview; + +import com.fourisland.fourpuzzle.Audio; +import com.fourisland.fourpuzzle.gamestate.*; +import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent; +import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.Layer; +import com.fourisland.fourpuzzle.PuzzleApplication; +import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime; +import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; +import java.awt.Graphics2D; +import java.awt.event.KeyEvent; +import java.util.ArrayList; + +/** + * + * @author hatkirby + */ +public class MapViewGameState implements GameState { + + boolean debugWalkthrough = false; + boolean processInput = true; + Map currentMap; + + public MapViewGameState(String map, int x, int y) throws Exception + { + //currentMap = ObjectLoader.getMap(map); + setCurrentMap(map); + Game.getSaveFile().getHero().setLocation(x, y); + } + + public void initalize() throws Exception + { + //if (!currentMap.getMusic().equals("")) + { + // Audio.playMusic(currentMap.getMusic()); + } + } + + public void deinitalize() throws Exception + { + //if (!currentMap.getMusic().equals("")) + { + Audio.stopMusic(); + } + } + + public void processInput() throws Exception + { + if (processInput) + { + HeroEvent hero = Game.getSaveFile().getHero(); + + if (Game.getKey().isControlDown() && !debugWalkthrough) + { + if (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) + { + debugWalkthrough = true; + } + } else { + debugWalkthrough = false; + } + + if (!hero.isMoving()) + { + Direction toMove = null; + Boolean letsMove = false; + + switch (Game.getKey().getKeyCode()) + { + case KeyEvent.VK_UP: + toMove = Direction.North; + letsMove = true; + break; + case KeyEvent.VK_RIGHT: + toMove = Direction.East; + letsMove = true; + break; + case KeyEvent.VK_DOWN: + toMove = Direction.South; + letsMove = true; + break; + case KeyEvent.VK_LEFT: + toMove = Direction.West; + letsMove = true; + break; + } + + if (letsMove) + { + if (debugWalkthrough || (!currentMap.checkForCollision(hero.getLocation().x, hero.getLocation().y, toMove))) + { + hero.startMoving(toMove); + } else { + hero.setDirection(toMove); + } + } + + if ((Game.getKey().getKeyCode() == KeyEvent.VK_ENTER) || (Game.getKey().getKeyCode() == KeyEvent.VK_SPACE)) + { + int i=0; + for (i=0;i events = currentMap.getEvents(); + for (i=0;i preconditions; + private EventCallTime calltime; + private EventCall callback; + + public CommonEvent() + { + calltime = EventCallTime.ParallelProcess; + callback = EventCall.getEmptyEventCall(); + + preconditions = new ArrayList(); + } + + public void addPrecondition(Precondition precondition) + { + preconditions.add(precondition); + } + + public Precondition getPrecondition(int i) + { + return preconditions.get(i); + } + + public int preconditions() + { + return preconditions.size(); + } + + public EventCall getCallback() + { + return callback; + } + + public void setCallback(EventCall callback) + { + this.callback = callback; + } + + public EventCallTime getCalltime() { + return calltime; + } + + public void setCalltime(EventCallTime calltime) { + this.calltime = calltime; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event; + +import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.Layer; +import java.awt.Graphics; +import java.awt.Point; + +/** + * + * @author hatkirby + */ +public interface Event { + + public String getLabel(); + + public Point getLocation(); + + public void setLocation(Point location); + public void setLocation(int x, int y); + + public void render(Graphics g) throws Exception; + + public Direction getDirection() throws Exception; + public void setDirection(Direction direction) throws Exception; + + public boolean isMoving(); + public void startMoving(Direction direction) throws Exception; + + public Layer getLayer() throws Exception; +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event; + +/** + * + * @author hatkirby + */ +public abstract class EventCall extends SpecialEvent implements Runnable { + + public static EventCall getEmptyEventCall() + { + return new EventCall() { + @Override + public void run() { + } + }; + } + + public abstract void run(); + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event; + +/** + * + * @author hatkirby + */ +public enum EventCallTime { + PushKey, + OnHeroTouch, + ParallelProcess +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event; + +import com.fourisland.fourpuzzle.Layer; +import java.awt.Graphics; +import java.awt.Point; +import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.GameCharacter; +import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; +import com.fourisland.fourpuzzle.NoCharactersInPartyException; + +/** + * + * @author hatkirby + */ +public class HeroEvent implements Event { + + public HeroEvent() + { + location = new Point(); + } + + public String getLabel() + { + return "Hero"; + } + + private Point location; + public Point getLocation() + { + return location; + } + public void setLocation(Point location) + { + this.location = location; + } + public void setLocation(int x, int y) + { + location.setLocation(x, y); + } + + public void render(Graphics g) throws Exception + { + int x = (location.x * 16) - 4; + int y = (location.y * 16) - 16; + + if (moving) + { + if (moveDirection == Direction.North) + { + y -= (4 - moveTimer) * 4; + } else if (moveDirection == Direction.West) + { + x -= (4 - moveTimer) * 4; + } else if (moveDirection == Direction.South) + { + y += (4 - moveTimer) * 4; + } else if (moveDirection == Direction.East) + { + x += (4 - moveTimer) * 4; + } + } + + try + { + GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); + if (!toDraw.getGraphic().equals("blank")) + { + g.drawImage(CharSet.getCharSet(toDraw.getGraphic()).getImage(toDraw.getGraphicOffset(), direction, animationStep), x, y, null); + } + } catch (NoCharactersInPartyException ex) + { + } + } + + + private boolean moving = false; + public boolean isMoving() + { + return moving; + } + public void setMoving(boolean moving) + { + this.moving = moving; + } + + private int moveTimer; + private Direction moveDirection; + public void startMoving(Direction toMove) throws Exception + { + setDirection(toMove); + setAnimationStep(2); + moveTimer = 4; + moving = true; + moveDirection = toMove; + } + public void processMoving() throws Exception + { + if (moving) + { + moveTimer--; + if (moveTimer == 2) + { + setAnimationStep(0); + } else if (moveTimer == 0) + { + setAnimationStep(1); + moving = false; + + if (moveDirection == Direction.North) + { + setLocation(getLocation().x,getLocation().y-1); + } else if (moveDirection == Direction.West) + { + setLocation(getLocation().x-1,getLocation().y); + } else if (moveDirection == Direction.South) + { + setLocation(getLocation().x,getLocation().y+1); + } else if (moveDirection == Direction.East) + { + setLocation(getLocation().x+1,getLocation().y); + } + } + } + } + + private Direction direction = Direction.South; + public Direction getDirection() + { + return direction; + } + public void setDirection(Direction direction) + { + this.direction = direction; + } + + private int animationStep = 1; + public int getAnimationStep() + { + return animationStep; + } + public void setAnimationStep(int animationStep) + { + this.animationStep = animationStep; + } + + public Layer getLayer() throws Exception + { + return Layer.Middle; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event; + +import com.fourisland.fourpuzzle.Layer; +import java.awt.Graphics; +import java.awt.Point; +import java.util.ArrayList; +import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.gamestate.mapview.Map; + +/** + * + * @author hatkirby + */ +public class LayerEvent implements Event { + + /** Create a new Event instance + * + * @param x The horizontal location of the Event on the Map + * @param y The vertical location of the Event on the Map + */ + public LayerEvent(int x, int y) + { + location = new Point(x,y); + events = new ArrayList(); + } + + /** Create a new Event instance + * + * @param x The horizontal location of the Event on the Map + * @param y The vertical location of the Event on the Map + * @param label An identifying label for the Event + */ + public LayerEvent(int x, int y, String label) + { + this(x,y); + this.label = label; + } + + private String label; + public String getLabel() + { + return label; + } + + private Point location; + public Point getLocation() + { + return location; + } + public void setLocation(Point location) + { + this.location = location; + } + public void setLocation(int x, int y) + { + location.setLocation(x, y); + } + + private ArrayList events; + public void addEvent(PossibleEvent pe) + { + events.add(pe); + } + + private PossibleEvent getPossibleEvent() throws Exception + { + int i; + for (i=(events.size()-1);i>-1;i--) + { + boolean good = true; + int j; + for (j=0;j preconditions; + + private Direction direction; + private int animationStep; + + public PossibleEvent() + { + graphic = new BlankEventGraphic(); + layer = Layer.Below; + animation = AnimationType.CommonWithStepping; + movement = new StayStillMovementType(); + calltime = EventCallTime.PushKey; + callback = EventCall.getEmptyEventCall(); + preconditions = new ArrayList(); + + direction = Direction.South; + animationStep = 1; + } + + public BufferedImage getImage() throws Exception + { + return graphic.getImage(); + } + + public EventGraphic getGraphic() { + return graphic; + } + + public void setGraphic(EventGraphic graphic) { + this.graphic = graphic; + } + + public Layer getLayer() { + return layer; + } + + public void setLayer(Layer layer) { + this.layer = layer; + } + + public AnimationType getAnimation() { + return animation; + } + + public void setAnimation(AnimationType animation) { + this.animation = animation; + } + + public MovementType getMovement() { + return movement; + } + + public void setMovement(MovementType movement) { + this.movement = movement; + } + + public Direction getDirection() { + return direction; + } + + public void setDirection(Direction direction) throws Exception { + if (Functions.canTurn(this)) + { + this.direction = direction; + graphic.setDirection(direction); + } + } + + public int getAnimationStep() { + return animationStep; + } + + public void setAnimationStep(int animationStep) { + this.animationStep = animationStep; + graphic.setAnimationStep(animationStep); + } + + public void addPrecondition(Precondition precondition) + { + preconditions.add(precondition); + } + + public Precondition getPrecondition(int i) + { + return preconditions.get(i); + } + + public int preconditions() + { + return preconditions.size(); + } + + public EventCall getCallback() + { + return callback; + } + + public void setCallback(EventCall callback) + { + this.callback = callback; + } + + public EventCallTime getCalltime() { + return calltime; + } + + public void setCalltime(EventCallTime calltime) { + this.calltime = calltime; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event; + +import com.fourisland.fourpuzzle.*; +import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; +import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +public class SpecialEvent { + + /** + * Display a message on the screen. + * + * Usually used for dialogue. If SetFace() is + * + * used prior to this, the face set is displayed + * on the left side. + * + * Display of the message area can be modified using + * MessageDisplaySettings(). + * + * This function also automatically splits your + * message up into blocks that will fit on + * the screen (breaks at spaces). If there are too + * many words, they will be held and displayed in + * the message area after the prior message has + * been read. + * + * @param message The message to display + */ + public void DisplayMessage(String message) + { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Sets the face used when displaying a message + * + * See DisplayMessage() for more info + * + * @param faceSet The name of the FaceSet to use + * @param face The number of the face in the FaceSet + * to use. The faces are numbered + * horizontally. + */ + public void SetFace(String faceSet, int face) + { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Clears the face used when displaying a message + * + * See DisplayMessage() for more info + */ + public void EraseFace() + { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Sets a Switch to a [boolean] value + * + * @param switchID The Switch to set + * @param value The value to set the Switch to + */ + public void SetSwitch(String switchID, boolean value) + { + Game.getSaveFile().getSwitches().put(switchID, value); + } + + /** + * Toggles a Switch's [boolean] value + * + * @param switchID The Switch to toggle + */ + public void ToggleSwitch(String switchID) + { + if (Game.getSaveFile().getSwitches().containsKey(switchID)) + { + Game.getSaveFile().getSwitches().put(switchID, !Game.getSaveFile().getSwitches().get(switchID)); + } else { + Game.getSaveFile().getSwitches().put(switchID, true); + } + } + + /** + * Performs actions on the hero + * + * @param actions An array of MoveEvents to perform on the hero + */ + public void MoveEvent(MoveEvent[] actions) + { + MoveEvent(actions, Game.getHeroEvent()); + } + + /** + * Performs actions on an event + * + * @param actions An array of MoveEvents to perform on the event + * @param ev The event to act upon + */ + public void MoveEvent(MoveEvent[] actions, Event ev) + { + new Thread(new MoveEventThread(ev, actions)).start(); + } + + /** + * Waits until all previously called MoveEvent()s have finished + */ + public void MoveEventWait() + { + try { + MoveEventThread.moveEventWait.await(); + } catch (InterruptedException ex) { + Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex); + } + } + + /** + * Triggers the Game Over sequence + * @throws Exception + */ + public void GameOver() throws Exception + { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Returns the player to the Title Screen + * @throws Exception + */ + public void TitleScreen() throws Exception + { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Moves the player to a different map + * + * @param map The name of the map to move to + * @param x The X position on the map to move to + * @param y The Y position on the map to move to + * @throws java.lang.Exception + */ + public void Teleport(String map, int x, int y) throws Exception + { + throw new UnsupportedOperationException("Not yet implemented"); + } + + /** + * Waits for a specified interval + * + * @param wait The time to wait in milliseconds + * @throws java.lang.InterruptedException + */ + public void Wait(int wait) throws InterruptedException + { + Thread.sleep(wait); + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; + +import com.fourisland.fourpuzzle.Direction; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public class BlankEventGraphic implements EventGraphic { + + private Direction direction; + private int animationStep; + + public BufferedImage getImage() throws Exception { + return null; + } + + public Direction getDirection() { + return direction; + } + + public void setDirection(Direction direction) { + this.direction = direction; + } + + public int getAnimationStep() { + return animationStep; + } + + public void setAnimationStep(int animationStep) { + this.animationStep = animationStep; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; + +import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public class CharSetEventGraphic implements EventGraphic { + + private Direction direction = Direction.South; + private int animationStep = 1; + private String graphic; + private int graphicOffset; + + public CharSetEventGraphic(String graphic, int graphicOffset) + { + this.graphic = graphic; + this.graphicOffset = graphicOffset; + } + + public BufferedImage getImage() throws Exception + { + return CharSet.getCharSet(getGraphic()).getImage(getGraphicOffset(), getDirection(), getAnimationStep()); + } + + public Direction getDirection() + { + return direction; + } + + public void setDirection(Direction direction) + { + this.direction = direction; + } + + public String getGraphic() { + return graphic; + } + + public void setGraphic(String graphic) { + this.graphic = graphic; + } + + public int getGraphicOffset() { + return graphicOffset; + } + + public void setGraphicOffset(int graphicOffset) { + this.graphicOffset = graphicOffset; + } + + public int getAnimationStep() { + return animationStep; + } + + public void setAnimationStep(int animationStep) { + this.animationStep = animationStep; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.graphic; + +import com.fourisland.fourpuzzle.Direction; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public interface EventGraphic { + + public BufferedImage getImage() throws Exception; + + public Direction getDirection(); + public void setDirection(Direction direction); + + public int getAnimationStep(); + public void setAnimationStep(int animationStep); + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; + +import com.fourisland.fourpuzzle.Direction; + +/** + * + * @author hatkirby + */ +public class CustomMovementType implements MovementType { + + private Direction[] moves; + private int step = 0; + + public CustomMovementType(Direction[] moves) + { + this.moves = moves; + } + + public Direction startMoving() throws Exception + { + if (step >= moves.length) + { + step = 0; + } + + return moves[step++]; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; + +import com.fourisland.fourpuzzle.Direction; + +/** + * + * @author hatkirby + */ +public interface MovementType { + + public Direction startMoving() throws Exception; + +} + +/* + CycleUpDown + CycleLeftRight + StepTowardHero + StepAwayFromHero +*/ \ 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; + +import com.fourisland.fourpuzzle.Direction; +import java.util.Random; + +/** + * + * @author hatkirby + */ +public class RandomMovementType implements MovementType { + + public Direction startMoving() throws Exception { + Random r = new Random(); + int ra = r.nextInt(1000); + Direction toMove = null; + boolean letsMove = false; + + if (ra < 25) + { + toMove = Direction.North; + letsMove = true; + } else if (ra < 50) + { + toMove = Direction.West; + letsMove = true; + } else if (ra < 75) + { + toMove = Direction.South; + letsMove = true; + } else if (ra < 100) + { + toMove = Direction.East; + letsMove = true; + } + + if (letsMove) + { + return toMove; + } + + return null; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; + +import com.fourisland.fourpuzzle.Direction; + +/** + * + * @author hatkirby + */ +public class StayStillMovementType implements MovementType { + + public Direction startMoving() throws Exception + { + return null; // Do nothing, stay still + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; + +import com.fourisland.fourpuzzle.Game; + +/** + * + * @author hatkirby + */ +public class HeroInPartyPrecondition implements Precondition { + + private String heroName; + + public HeroInPartyPrecondition(String heroName) + { + this.heroName = heroName; + } + + public boolean match() { + return Game.getSaveFile().getParty().exists(heroName); + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; + +import com.fourisland.fourpuzzle.Game; + +/** + * + * @author hatkirby + */ +public class HeroLevelPrecondition implements Precondition { + + private String heroName; + private int level; + + public HeroLevelPrecondition(String heroName, int level) + { + this.heroName = heroName; + this.level = level; + } + + public boolean match() throws Exception { + return (Game.getSaveFile().getParty().exists(heroName) && (Game.getSaveFile().getParty().get(heroName).getLevel() == level)); + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; + +/** + * + * @author hatkirby + */ +public interface Precondition { + + public boolean match() throws Exception; + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; + +import com.fourisland.fourpuzzle.Game; + +/** + * + * @author hatkirby + */ +public class SwitchPrecondition implements Precondition { + + private String switchID; + + public SwitchPrecondition(String switchID) + { + this.switchID = switchID; + } + + public boolean match() { + return (Game.getSaveFile().getSwitches().containsKey(switchID) && Game.getSaveFile().getSwitches().get(switchID)); + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; + +import com.fourisland.fourpuzzle.util.Comparison; +import com.fourisland.fourpuzzle.Game; + +/** + * + * @author hatkirby + */ +public class VariableNumberPrecondition implements Precondition { + + private String variableID; + private Comparison comparison; + private int number; + + public VariableNumberPrecondition(String variableID, Comparison comparison, int number) + { + this.variableID = variableID; + this.comparison = comparison; + this.number = number; + } + + public boolean match() { + if (Game.getSaveFile().getVariables().containsKey(variableID)) + { + int n1 = Game.getSaveFile().getVariables().get(variableID); + int n2 = number; + + switch (comparison) + { + case Less: return (n1 < n2); + case Greater: return (n1 > n2); + case Equal: return (n1 == n2); + } + } + + return false; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.precondition; + +import com.fourisland.fourpuzzle.util.Comparison; +import com.fourisland.fourpuzzle.Game; + +/** + * + * @author hatkirby + */ +public class VariableVariablePrecondition implements Precondition { + + private String variableID; + private Comparison comparison; + private String variableID2; + + public VariableVariablePrecondition(String variableID, Comparison comparison, String variableID2) + { + this.variableID = variableID; + this.comparison = comparison; + this.variableID2 = variableID2; + } + + public boolean match() { + if (Game.getSaveFile().getVariables().containsKey(variableID)) + { + int n1 = Game.getSaveFile().getVariables().get(variableID); + int n2 = Game.getSaveFile().getVariables().get(variableID2); + + switch (comparison) + { + case Less: return (n1 < n2); + case Greater: return (n1 > n2); + case Equal: return (n1 == n2); + } + } + + return false; + } + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; + +import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; + +/** + * + * @author hatkirby + */ +public class FaceMoveEvent implements MoveEvent { + + Direction direction; + public FaceMoveEvent(Direction direction) + { + this.direction = direction; + } + + public void doAction(Event ev) throws Exception + { + ev.setDirection(direction); + } + +} 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 @@ + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; + +import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; + +/** + * + * @author hatkirby + */ +public interface MoveEvent { + + public void doAction(Event ev) throws Exception; + +} 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 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; + +import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.CyclicBarrier; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +public class MoveEventThread implements Runnable { + + public static volatile CountDownLatch moveEventWait = new CountDownLatch(0); + public static volatile int countMoveEventThreads = 0; + + Event ev; + MoveEvent[] actions; + + public MoveEventThread(Event ev, MoveEvent[] actions) + { + this.ev = ev; + this.actions = actions; + } + + public void run() { + MoveEventThread.countMoveEventThreads++; + moveEventWait = new CountDownLatch(countMoveEventThreads); + + int i=0; + for (i=0;i objectCache = new HashMap(); + + public static BufferedImage getImage(String type, String name) throws Exception + { + if (!objectCache.containsKey(type + "/" + name)) + { + ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; + BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename)); + + addToObjectCache(type,name,bImg); + } + + return (BufferedImage) objectCache.get(type + "/" + name); + } + + public static BufferedImage getImage(String type, String name, int transparencyColor) throws Exception + { + if (!objectCache.containsKey(type + "/" + name)) + { + ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + String filename = rm.getResourcesDir() + type + "/" + name + ".png"; + BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename)); + bImg = new BufferedImage(bImg.getWidth(), bImg.getHeight(), BufferedImage.TYPE_INT_RGB); + Image image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(bImg.getSource(), new TransparentImageFilter(transparencyColor))); + bImg.createGraphics().drawImage(image, 0, 0, null); + + addToObjectCache(type,name,bImg); + } + + return (BufferedImage) objectCache.get(type + "/" + name); + } + + /*public static com.alienfactory.javamappy.Map getMap(String name) throws Exception + { + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); + String filename = rm.getResourcesDir() + "mapdata/" + name + ".fmp"; + + //com.alienfactory.javamappy.Map map = MapLoader.loadMap(rm.getClassLoader().getResourceAsStream(filename)); + return map; + }*/ + + public static void addToObjectCache(String type, String name, Object object) throws Exception + { + if (objectCache.size() >= 100) + { + objectCache.clear(); + } + + objectCache.put(type + "/" + name, object); + } + + public static Sequence getMusic(String name) throws Exception + { + if (!objectCache.containsKey("Music/" + name)) + { + ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + String filename = rm.getResourcesDir() + "music/" + name + ".mid"; + Sequence seq = MidiSystem.getSequence(rm.getClassLoader().getResourceAsStream(filename)); + + addToObjectCache("Music", name, seq); + } + + return (Sequence) objectCache.get("Music/" + name); + } + +} 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 @@ +/* + * Tiled Map Editor, (c) 2004-2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Adam Turk + * Bjorn Lindeijer + */ + +package com.fourisland.fourpuzzle.util; + +import java.awt.image.RGBImageFilter; + +/** + * This filter is used for filtering out a given "transparent" color from an + * image. Sometimes known as magic pink. + */ +public class TransparentImageFilter extends RGBImageFilter +{ + int trans; + + /** + * @param col the color to make transparent + */ + public TransparentImageFilter(int col) { + trans = col; + + // The filter doesn't depend on pixel location + canFilterIndexColorModel = true; + } + + /** + * Filters the given pixel. It returns a transparent pixel for pixels that + * match the transparency color, or the existing pixel for anything else. + */ + public int filterRGB(int x, int y, int rgb) { + if (rgb == trans) { + return 0; + } else { + return rgb; + } + } +} \ No newline at end of file -- cgit 1.4.1