diff options
Diffstat (limited to 'src/com/fourisland')
7 files changed, 88 insertions, 51 deletions
| diff --git a/src/com/fourisland/fourpuzzle/Direction.java b/src/com/fourisland/fourpuzzle/Direction.java index 948b024..4742521 100644 --- a/src/com/fourisland/fourpuzzle/Direction.java +++ b/src/com/fourisland/fourpuzzle/Direction.java | |||
| @@ -16,6 +16,11 @@ public enum Direction { | |||
| 16 | West; | 16 | West; |
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| 19 | * TODO Find a way to serve the inverse of a Direction without using a | ||
| 20 | * switch, which is apparently bad practice | ||
| 21 | */ | ||
| 22 | |||
| 23 | /** | ||
| 19 | * Returns the direction opposite from the current one | 24 | * Returns the direction opposite from the current one |
| 20 | * @return A Direction representing the opposite direction | 25 | * @return A Direction representing the opposite direction |
| 21 | */ | 26 | */ |
| diff --git a/src/com/fourisland/fourpuzzle/Game.java b/src/com/fourisland/fourpuzzle/Game.java index 432d8ff..d2e8943 100644 --- a/src/com/fourisland/fourpuzzle/Game.java +++ b/src/com/fourisland/fourpuzzle/Game.java | |||
| @@ -17,7 +17,7 @@ public class Game { | |||
| 17 | 17 | ||
| 18 | public static final int WIDTH = 320; | 18 | public static final int WIDTH = 320; |
| 19 | public static final int HEIGHT = 240; | 19 | public static final int HEIGHT = 240; |
| 20 | public static final int FPS = (1000 / 20); // 20 fps | 20 | public static final int FPS = (1000 / 30); // 30 fps |
| 21 | 21 | ||
| 22 | private static SaveFile saveFile; | 22 | private static SaveFile saveFile; |
| 23 | public static SaveFile getSaveFile() | 23 | public static SaveFile getSaveFile() |
| diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index 80b6cd3..c8d4e5d 100644 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java | |||
| @@ -6,6 +6,7 @@ package com.fourisland.fourpuzzle; | |||
| 6 | 6 | ||
| 7 | import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; | 7 | import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; |
| 8 | import com.fourisland.fourpuzzle.gamestate.mapview.ChipSet; | 8 | import com.fourisland.fourpuzzle.gamestate.mapview.ChipSet; |
| 9 | import com.fourisland.fourpuzzle.util.Interval; | ||
| 9 | import java.awt.GraphicsEnvironment; | 10 | import java.awt.GraphicsEnvironment; |
| 10 | import java.awt.event.KeyAdapter; | 11 | import java.awt.event.KeyAdapter; |
| 11 | import java.awt.event.KeyEvent; | 12 | import java.awt.event.KeyEvent; |
| @@ -108,14 +109,10 @@ public class PuzzleApplication extends Application { | |||
| 108 | ChipSet.initalize(); | 109 | ChipSet.initalize(); |
| 109 | Game.setGameState(new TitleScreenGameState()); | 110 | Game.setGameState(new TitleScreenGameState()); |
| 110 | 111 | ||
| 111 | long iTickCount = System.currentTimeMillis(); | 112 | Interval in = Interval.createTickInterval(1); |
| 112 | long iTickTrigger = iTickCount + Game.FPS; | ||
| 113 | |||
| 114 | while (true) | 113 | while (true) |
| 115 | { | 114 | { |
| 116 | iTickCount = System.currentTimeMillis(); | 115 | if ((debugSpeed || in.isElapsed()) && !gameSleep) |
| 117 | |||
| 118 | if ((iTickCount > iTickTrigger) && (!gameSleep)) | ||
| 119 | { | 116 | { |
| 120 | if (!Display.isTransitionRunning()) | 117 | if (!Display.isTransitionRunning()) |
| 121 | { | 118 | { |
| @@ -128,11 +125,6 @@ public class PuzzleApplication extends Application { | |||
| 128 | } | 125 | } |
| 129 | 126 | ||
| 130 | Display.render(gameFrame); | 127 | Display.render(gameFrame); |
| 131 | |||
| 132 | if (!debugSpeed) | ||
| 133 | { | ||
| 134 | iTickTrigger = iTickCount + Game.FPS; | ||
| 135 | } | ||
| 136 | } | 128 | } |
| 137 | } | 129 | } |
| 138 | } catch (RuntimeException ex) { | 130 | } catch (RuntimeException ex) { |
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java index 20d6bfc..7824470 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; | 6 | package com.fourisland.fourpuzzle.gamestate.mapview.event; |
| 7 | 7 | ||
| 8 | import com.fourisland.fourpuzzle.util.Interval; | ||
| 9 | |||
| 8 | /** | 10 | /** |
| 9 | * | 11 | * |
| 10 | * @author hatkirby | 12 | * @author hatkirby |
| @@ -14,35 +16,44 @@ public enum AnimationType { | |||
| 14 | * The default AnimationType, it allows the Event to turn and to animate | 16 | * The default AnimationType, it allows the Event to turn and to animate |
| 15 | * while it walks, but it only animates while it moves. | 17 | * while it walks, but it only animates while it moves. |
| 16 | */ | 18 | */ |
| 17 | CommonWithoutStepping(true, true, false), | 19 | CommonWithoutStepping(true, true), |
| 18 | /** | 20 | /** |
| 19 | * An AnimationType which allows the Event to turn and to animate. It will | 21 | * An AnimationType which allows the Event to turn and to animate. It will |
| 20 | * animate at all times, even while stationary. | 22 | * animate at all times, even while stationary. |
| 21 | */ | 23 | */ |
| 22 | CommonWithStepping(true, true, true), | 24 | CommonWithStepping(true, true) |
| 25 | { | ||
| 26 | Interval in = Interval.createTickInterval(2); | ||
| 27 | |||
| 28 | @Override | ||
| 29 | public void tick(PossibleEvent pe) | ||
| 30 | { | ||
| 31 | if (in.isElapsed()) | ||
| 32 | { | ||
| 33 | if (pe.getAnimationStep() == 0) | ||
| 34 | { | ||
| 35 | pe.setAnimationStep(2); | ||
| 36 | } else { | ||
| 37 | pe.setAnimationStep(pe.getAnimationStep()-1); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
| 41 | }, | ||
| 23 | /** | 42 | /** |
| 24 | * An AnimationType that allows the Event to turn, but not to animate. | 43 | * An AnimationType that allows the Event to turn, but not to animate. |
| 25 | */ | 44 | */ |
| 26 | WithoutStepping(true, false, false), | 45 | WithoutStepping(true, false), |
| 27 | /** | 46 | /** |
| 28 | * An AnimationType that does not allow the Event to turn or animate. | 47 | * An AnimationType that does not allow the Event to turn or animate. |
| 29 | */ | 48 | */ |
| 30 | FixedGraphic(false, false, false); | 49 | FixedGraphic(false, false); |
| 31 | 50 | ||
| 32 | private boolean canTurn; | 51 | private boolean canTurn; |
| 33 | private boolean canStep; | 52 | private boolean canStep; |
| 34 | private boolean alwaysStepping; | 53 | private AnimationType(boolean canTurn, boolean canStep) |
| 35 | private AnimationType(boolean canTurn, boolean canStep, boolean alwaysStepping) | ||
| 36 | { | 54 | { |
| 37 | this.canTurn = canTurn; | 55 | this.canTurn = canTurn; |
| 38 | this.canStep = canStep; | 56 | this.canStep = canStep; |
| 39 | |||
| 40 | if (!canStep) | ||
| 41 | { | ||
| 42 | this.alwaysStepping = false; | ||
| 43 | } else { | ||
| 44 | this.alwaysStepping = alwaysStepping; | ||
| 45 | } | ||
| 46 | } | 57 | } |
| 47 | 58 | ||
| 48 | public boolean canTurn() | 59 | public boolean canTurn() |
| @@ -55,9 +66,9 @@ public enum AnimationType { | |||
| 55 | return canStep; | 66 | return canStep; |
| 56 | } | 67 | } |
| 57 | 68 | ||
| 58 | public boolean isAlwaysStepping() | 69 | public void tick(PossibleEvent pe) |
| 59 | { | 70 | { |
| 60 | return alwaysStepping; | 71 | // Do nothing |
| 61 | } | 72 | } |
| 62 | 73 | ||
| 63 | } | 74 | } \ No newline at end of file |
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java index 931c6ca..f31dcaf 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/PossibleEvent.java | |||
| @@ -97,25 +97,10 @@ public class PossibleEvent { | |||
| 97 | callback = builder.callback; | 97 | callback = builder.callback; |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | private boolean aSLC = false; | ||
| 101 | public EventGraphic getGraphic() | 100 | public EventGraphic getGraphic() |
| 102 | { | 101 | { |
| 103 | if (animation.isAlwaysStepping()) | 102 | animation.tick(this); |
| 104 | { | 103 | |
| 105 | if (aSLC) | ||
| 106 | { | ||
| 107 | aSLC = false; | ||
| 108 | |||
| 109 | if (animationStep == 0) | ||
| 110 | { | ||
| 111 | setAnimationStep(2); | ||
| 112 | } else { | ||
| 113 | setAnimationStep(animationStep-1); | ||
| 114 | } | ||
| 115 | } else { | ||
| 116 | aSLC = true; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | return graphic; | 104 | return graphic; |
| 120 | } | 105 | } |
| 121 | 106 | ||
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java index eac4b49..e6db32b 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | package com.fourisland.fourpuzzle.gamestate.mapview.viewpoint; | 6 | package com.fourisland.fourpuzzle.gamestate.mapview.viewpoint; |
| 7 | 7 | ||
| 8 | import com.fourisland.fourpuzzle.Game; | 8 | import com.fourisland.fourpuzzle.Game; |
| 9 | import com.fourisland.fourpuzzle.util.Interval; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * | 12 | * |
| @@ -20,10 +21,10 @@ public class MovingViewpoint implements Viewpoint { | |||
| 20 | private int dx; | 21 | private int dx; |
| 21 | private int dy; | 22 | private int dy; |
| 22 | private double speed; | 23 | private double speed; |
| 23 | private int last; | ||
| 24 | private int xdist; | 24 | private int xdist; |
| 25 | private int ydist; | 25 | private int ydist; |
| 26 | private Runnable callback; | 26 | private Runnable callback; |
| 27 | private Interval in; | ||
| 27 | 28 | ||
| 28 | public MovingViewpoint(int sx, int sy, int dx, int dy, Runnable callback) | 29 | public MovingViewpoint(int sx, int sy, int dx, int dy, Runnable callback) |
| 29 | { | 30 | { |
| @@ -39,10 +40,10 @@ public class MovingViewpoint implements Viewpoint { | |||
| 39 | this.dx = dx; | 40 | this.dx = dx; |
| 40 | this.dy = dy; | 41 | this.dy = dy; |
| 41 | this.speed = length / Game.FPS; | 42 | this.speed = length / Game.FPS; |
| 42 | this.last = (int) System.currentTimeMillis(); | ||
| 43 | this.xdist = dx - sx; | 43 | this.xdist = dx - sx; |
| 44 | this.ydist = dy - sy; | 44 | this.ydist = dy - sy; |
| 45 | this.callback = callback; | 45 | this.callback = callback; |
| 46 | this.in = Interval.createMillisInterval((int) speed); | ||
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | private void refresh() | 49 | private void refresh() |
| @@ -64,13 +65,11 @@ public class MovingViewpoint implements Viewpoint { | |||
| 64 | { | 65 | { |
| 65 | callback.run(); | 66 | callback.run(); |
| 66 | } | 67 | } |
| 67 | |||
| 68 | last = (int) System.currentTimeMillis(); | ||
| 69 | } | 68 | } |
| 70 | 69 | ||
| 71 | public int getX() | 70 | public int getX() |
| 72 | { | 71 | { |
| 73 | if (System.currentTimeMillis() + speed > last) | 72 | if (in.isElapsed()) |
| 74 | { | 73 | { |
| 75 | refresh(); | 74 | refresh(); |
| 76 | } | 75 | } |
| @@ -80,7 +79,7 @@ public class MovingViewpoint implements Viewpoint { | |||
| 80 | 79 | ||
| 81 | public int getY() | 80 | public int getY() |
| 82 | { | 81 | { |
| 83 | if (System.currentTimeMillis() + speed > last) | 82 | if (in.isElapsed()) |
| 84 | { | 83 | { |
| 85 | refresh(); | 84 | refresh(); |
| 86 | } | 85 | } |
| diff --git a/src/com/fourisland/fourpuzzle/util/Interval.java b/src/com/fourisland/fourpuzzle/util/Interval.java new file mode 100644 index 0000000..21a7a74 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/util/Interval.java | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.util; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.Game; | ||
| 9 | |||
| 10 | /** | ||
| 11 | * | ||
| 12 | * @author hatkirby | ||
| 13 | */ | ||
| 14 | public class Interval { | ||
| 15 | |||
| 16 | private int wait; | ||
| 17 | private Interval(int wait) | ||
| 18 | { | ||
| 19 | this.wait = wait; | ||
| 20 | } | ||
| 21 | |||
| 22 | public static Interval createTickInterval(int ticks) | ||
| 23 | { | ||
| 24 | return new Interval(Game.FPS*ticks); | ||
| 25 | } | ||
| 26 | |||
| 27 | public static Interval createMillisInterval(int millis) | ||
| 28 | { | ||
| 29 | return new Interval(millis); | ||
| 30 | } | ||
| 31 | |||
| 32 | private long last = System.currentTimeMillis(); | ||
| 33 | public boolean isElapsed() | ||
| 34 | { | ||
| 35 | if (last+wait < System.currentTimeMillis()) | ||
| 36 | { | ||
| 37 | last = System.currentTimeMillis(); | ||
| 38 | |||
| 39 | return true; | ||
| 40 | } | ||
| 41 | |||
| 42 | return false; | ||
| 43 | } | ||
| 44 | |||
| 45 | } | ||
