From ffba4e065710ce5d76872607d9bc4676feae6c28 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sun, 15 Feb 2009 10:45:26 -0500 Subject: Engine: Created Fade transitions Along with Fade Transitions, other things such as the GameOver and TitleScreen special events have been implemented. Also, an unchecked bug in ObjectLoader has been fixed. The current Fade implementation isn't currently that elegant. There should be a way to make it better, but it'll do for now. Closes #13 --- nbproject/project.properties | 4 +- .../fourpuzzle/database/Transitions.java | 10 ++- .../fourpuzzle/gamestate/GameOverGameState.java | 9 ++- .../fourpuzzle/gamestate/TitleScreenGameState.java | 9 +-- .../gamestate/mapview/event/SpecialEvent.java | 24 +++++- .../fourpuzzle/transition/FadeTransition.java | 92 ++++++++++++++++++++++ .../fourisland/fourpuzzle/util/ObjectLoader.java | 4 +- src/com/fourisland/fourpuzzle/util/PauseTimer.java | 13 +++ 8 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/transition/FadeTransition.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 30c65cb..b91a61d 100755 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,3 +1,5 @@ +application.title=Four Puzzle Library +application.vendor=hatkirby build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: @@ -21,7 +23,7 @@ jar.compress=false javac.classpath=\ ${libs.swing-app-framework.classpath} # Space-separated list of extra javac options -javac.compilerargs= +javac.compilerargs=-Xlint:unchecked javac.deprecation=false javac.source=1.5 javac.target=1.5 diff --git a/src/com/fourisland/fourpuzzle/database/Transitions.java b/src/com/fourisland/fourpuzzle/database/Transitions.java index e45ad6d..98345a9 100644 --- a/src/com/fourisland/fourpuzzle/database/Transitions.java +++ b/src/com/fourisland/fourpuzzle/database/Transitions.java @@ -5,6 +5,7 @@ package com.fourisland.fourpuzzle.database; +import com.fourisland.fourpuzzle.transition.FadeTransition; import com.fourisland.fourpuzzle.transition.InTransition; import com.fourisland.fourpuzzle.transition.MultidirectionalTransition; import com.fourisland.fourpuzzle.transition.OutTransition; @@ -18,8 +19,15 @@ import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException; * @author hatkirby */ public enum Transitions { + TitleExit(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), + TitleToMap(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), MapExit(TransitionDirection.Out, new SquareTransition(TransitionDirection.Out)), - MapEnter(TransitionDirection.In, new SquareTransition(TransitionDirection.In)); + MapEnter(TransitionDirection.In, new SquareTransition(TransitionDirection.In)), + MapToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), + TitleEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), + MapToGameOver(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)), + GameOverEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)), + GameOverToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)); private final TransitionDirection dir; private Transition trans; diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index 459f730..ab1b9bb 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java @@ -11,6 +11,7 @@ import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.Game; import com.fourisland.fourpuzzle.SaveFile; import com.fourisland.fourpuzzle.database.Music; +import com.fourisland.fourpuzzle.database.Transitions; import com.fourisland.fourpuzzle.transition.SquareTransition; import com.fourisland.fourpuzzle.transition.TransitionDirection; import com.fourisland.fourpuzzle.util.ObjectLoader; @@ -42,12 +43,18 @@ public class GameOverGameState implements GameState { new Thread(new Runnable() { public void run() { try { - Display.transition(new SquareTransition(TransitionDirection.Out)); + Display.transition(Database.getTransition(Transitions.GameOverToTitle)); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } Game.setGameState(new TitleScreenGameState()); + + try { + Display.transition(Database.getTransition(Transitions.TitleEnter)); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } } }).start(); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index d5b4f90..fe8b1ed 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -9,10 +9,9 @@ import com.fourisland.fourpuzzle.database.Database; import com.fourisland.fourpuzzle.*; import com.fourisland.fourpuzzle.database.Music; import com.fourisland.fourpuzzle.database.Sound; +import com.fourisland.fourpuzzle.database.Transitions; import com.fourisland.fourpuzzle.database.Vocabulary; import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; -import com.fourisland.fourpuzzle.transition.SquareTransition; -import com.fourisland.fourpuzzle.transition.TransitionDirection; import com.fourisland.fourpuzzle.util.ObjectLoader; import com.fourisland.fourpuzzle.util.PauseTimer; import com.fourisland.fourpuzzle.window.ChoiceWindow; @@ -59,7 +58,7 @@ public class TitleScreenGameState implements GameState { new Thread(new Runnable() { public void run() { try { - Display.transition(new SquareTransition(TransitionDirection.Out)); + Display.transition(Database.getTransition(Transitions.TitleExit)); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } @@ -67,7 +66,7 @@ public class TitleScreenGameState implements GameState { Game.setGameState(new MapViewGameState("TestMap", 1, 2)); try { - Display.transition(new SquareTransition(TransitionDirection.In)); + Display.transition(Database.getTransition(Transitions.TitleToMap)); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } @@ -81,7 +80,7 @@ public class TitleScreenGameState implements GameState { new Thread(new Runnable() { public void run() { try { - Display.transition(new SquareTransition(TransitionDirection.Out)); + Display.transition(Database.getTransition(Transitions.TitleExit)); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 94d2b16..9336616 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -8,6 +8,8 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; import com.fourisland.fourpuzzle.database.Database; import com.fourisland.fourpuzzle.*; import com.fourisland.fourpuzzle.database.Transitions; +import com.fourisland.fourpuzzle.gamestate.GameOverGameState; +import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState; import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; @@ -148,18 +150,32 @@ public class SpecialEvent { /** * Triggers the Game Over sequence + * + * @throws InterruptedException */ - public void GameOver() + public void GameOver() throws InterruptedException { - throw new UnsupportedOperationException("Not yet implemented"); + Display.transition(Database.getTransition(Transitions.MapToGameOver)); + + Audio.stopMusic(); + Game.setGameState(new GameOverGameState()); + + Display.transition(Database.getTransition(Transitions.GameOverEnter)); } /** * Returns the player to the Title Screen + * + * @throws InterruptedException */ - public void TitleScreen() + public void TitleScreen() throws InterruptedException { - throw new UnsupportedOperationException("Not yet implemented"); + Display.transition(Database.getTransition(Transitions.MapToTitle)); + + Audio.stopMusic(); + Game.setGameState(new TitleScreenGameState()); + + Display.transition(Database.getTransition(Transitions.TitleEnter)); } private boolean startedTransition = false; diff --git a/src/com/fourisland/fourpuzzle/transition/FadeTransition.java b/src/com/fourisland/fourpuzzle/transition/FadeTransition.java new file mode 100644 index 0000000..a571791 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/FadeTransition.java @@ -0,0 +1,92 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.transition; + +import com.fourisland.fourpuzzle.Display; +import com.fourisland.fourpuzzle.Game; +import com.fourisland.fourpuzzle.util.PauseTimer; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public class FadeTransition implements MultidirectionalTransition { + + private TransitionDirection direction; + public FadeTransition(TransitionDirection direction) + { + this.direction = direction; + } + + public TransitionDirection getDirection() + { + return direction; + } + + private int ticks = 750 / Game.FPS; + private PauseTimer pt = new PauseTimer(ticks); + public boolean render(Graphics2D g) + { + BufferedImage temp = Display.createCanvas(Game.WIDTH, Game.HEIGHT); + double alpha = 1.0 * pt.getTimer() / ticks * 0.75; + + for (int i=0;i void addToObjectCache(Map cacheMap, String name, T object) { if (cacheMap.size() >= 100) { diff --git a/src/com/fourisland/fourpuzzle/util/PauseTimer.java b/src/com/fourisland/fourpuzzle/util/PauseTimer.java index 0e52b0f..8ae7330 100644 --- a/src/com/fourisland/fourpuzzle/util/PauseTimer.java +++ b/src/com/fourisland/fourpuzzle/util/PauseTimer.java @@ -37,5 +37,18 @@ public class PauseTimer { { this.ticks = ticks; } + + public int getTimer() + { + if (in.isElapsed()) + { + if (ticks > 0) + { + ticks--; + } + } + + return ticks; + } } -- cgit 1.4.1