summary refs log tree commit diff stats
path: root/src/com
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-02-15 10:45:26 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-02-15 10:45:26 -0500
commitffba4e065710ce5d76872607d9bc4676feae6c28 (patch)
tree7c23655ba8c4b0fb15714ccca94fd7c593cc4858 /src/com
parente50f6fe85fd19d2f91a3877ac99eca234537aac2 (diff)
downloadfourpuzzle-ffba4e065710ce5d76872607d9bc4676feae6c28.tar.gz
fourpuzzle-ffba4e065710ce5d76872607d9bc4676feae6c28.tar.bz2
fourpuzzle-ffba4e065710ce5d76872607d9bc4676feae6c28.zip
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
Diffstat (limited to 'src/com')
-rw-r--r--src/com/fourisland/fourpuzzle/database/Transitions.java10
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java9
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java9
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java24
-rw-r--r--src/com/fourisland/fourpuzzle/transition/FadeTransition.java92
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/util/ObjectLoader.java4
-rw-r--r--src/com/fourisland/fourpuzzle/util/PauseTimer.java13
7 files changed, 148 insertions, 13 deletions
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 @@
5 5
6package com.fourisland.fourpuzzle.database; 6package com.fourisland.fourpuzzle.database;
7 7
8import com.fourisland.fourpuzzle.transition.FadeTransition;
8import com.fourisland.fourpuzzle.transition.InTransition; 9import com.fourisland.fourpuzzle.transition.InTransition;
9import com.fourisland.fourpuzzle.transition.MultidirectionalTransition; 10import com.fourisland.fourpuzzle.transition.MultidirectionalTransition;
10import com.fourisland.fourpuzzle.transition.OutTransition; 11import com.fourisland.fourpuzzle.transition.OutTransition;
@@ -18,8 +19,15 @@ import com.fourisland.fourpuzzle.transition.TransitionUnsupportedException;
18 * @author hatkirby 19 * @author hatkirby
19 */ 20 */
20public enum Transitions { 21public enum Transitions {
22 TitleExit(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)),
23 TitleToMap(TransitionDirection.In, new FadeTransition(TransitionDirection.In)),
21 MapExit(TransitionDirection.Out, new SquareTransition(TransitionDirection.Out)), 24 MapExit(TransitionDirection.Out, new SquareTransition(TransitionDirection.Out)),
22 MapEnter(TransitionDirection.In, new SquareTransition(TransitionDirection.In)); 25 MapEnter(TransitionDirection.In, new SquareTransition(TransitionDirection.In)),
26 MapToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)),
27 TitleEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)),
28 MapToGameOver(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out)),
29 GameOverEnter(TransitionDirection.In, new FadeTransition(TransitionDirection.In)),
30 GameOverToTitle(TransitionDirection.Out, new FadeTransition(TransitionDirection.Out));
23 31
24 private final TransitionDirection dir; 32 private final TransitionDirection dir;
25 private Transition trans; 33 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;
11import com.fourisland.fourpuzzle.Game; 11import com.fourisland.fourpuzzle.Game;
12import com.fourisland.fourpuzzle.SaveFile; 12import com.fourisland.fourpuzzle.SaveFile;
13import com.fourisland.fourpuzzle.database.Music; 13import com.fourisland.fourpuzzle.database.Music;
14import com.fourisland.fourpuzzle.database.Transitions;
14import com.fourisland.fourpuzzle.transition.SquareTransition; 15import com.fourisland.fourpuzzle.transition.SquareTransition;
15import com.fourisland.fourpuzzle.transition.TransitionDirection; 16import com.fourisland.fourpuzzle.transition.TransitionDirection;
16import com.fourisland.fourpuzzle.util.ObjectLoader; 17import com.fourisland.fourpuzzle.util.ObjectLoader;
@@ -42,12 +43,18 @@ public class GameOverGameState implements GameState {
42 new Thread(new Runnable() { 43 new Thread(new Runnable() {
43 public void run() { 44 public void run() {
44 try { 45 try {
45 Display.transition(new SquareTransition(TransitionDirection.Out)); 46 Display.transition(Database.getTransition(Transitions.GameOverToTitle));
46 } catch (InterruptedException ex) { 47 } catch (InterruptedException ex) {
47 Thread.currentThread().interrupt(); 48 Thread.currentThread().interrupt();
48 } 49 }
49 50
50 Game.setGameState(new TitleScreenGameState()); 51 Game.setGameState(new TitleScreenGameState());
52
53 try {
54 Display.transition(Database.getTransition(Transitions.TitleEnter));
55 } catch (InterruptedException ex) {
56 Thread.currentThread().interrupt();
57 }
51 } 58 }
52 }).start(); 59 }).start();
53 } 60 }
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;
9import com.fourisland.fourpuzzle.*; 9import com.fourisland.fourpuzzle.*;
10import com.fourisland.fourpuzzle.database.Music; 10import com.fourisland.fourpuzzle.database.Music;
11import com.fourisland.fourpuzzle.database.Sound; 11import com.fourisland.fourpuzzle.database.Sound;
12import com.fourisland.fourpuzzle.database.Transitions;
12import com.fourisland.fourpuzzle.database.Vocabulary; 13import com.fourisland.fourpuzzle.database.Vocabulary;
13import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; 14import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
14import com.fourisland.fourpuzzle.transition.SquareTransition;
15import com.fourisland.fourpuzzle.transition.TransitionDirection;
16import com.fourisland.fourpuzzle.util.ObjectLoader; 15import com.fourisland.fourpuzzle.util.ObjectLoader;
17import com.fourisland.fourpuzzle.util.PauseTimer; 16import com.fourisland.fourpuzzle.util.PauseTimer;
18import com.fourisland.fourpuzzle.window.ChoiceWindow; 17import com.fourisland.fourpuzzle.window.ChoiceWindow;
@@ -59,7 +58,7 @@ public class TitleScreenGameState implements GameState {
59 new Thread(new Runnable() { 58 new Thread(new Runnable() {
60 public void run() { 59 public void run() {
61 try { 60 try {
62 Display.transition(new SquareTransition(TransitionDirection.Out)); 61 Display.transition(Database.getTransition(Transitions.TitleExit));
63 } catch (InterruptedException ex) { 62 } catch (InterruptedException ex) {
64 Thread.currentThread().interrupt(); 63 Thread.currentThread().interrupt();
65 } 64 }
@@ -67,7 +66,7 @@ public class TitleScreenGameState implements GameState {
67 Game.setGameState(new MapViewGameState("TestMap", 1, 2)); 66 Game.setGameState(new MapViewGameState("TestMap", 1, 2));
68 67
69 try { 68 try {
70 Display.transition(new SquareTransition(TransitionDirection.In)); 69 Display.transition(Database.getTransition(Transitions.TitleToMap));
71 } catch (InterruptedException ex) { 70 } catch (InterruptedException ex) {
72 Thread.currentThread().interrupt(); 71 Thread.currentThread().interrupt();
73 } 72 }
@@ -81,7 +80,7 @@ public class TitleScreenGameState implements GameState {
81 new Thread(new Runnable() { 80 new Thread(new Runnable() {
82 public void run() { 81 public void run() {
83 try { 82 try {
84 Display.transition(new SquareTransition(TransitionDirection.Out)); 83 Display.transition(Database.getTransition(Transitions.TitleExit));
85 } catch (InterruptedException ex) { 84 } catch (InterruptedException ex) {
86 Thread.currentThread().interrupt(); 85 Thread.currentThread().interrupt();
87 } 86 }
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;
8import com.fourisland.fourpuzzle.database.Database; 8import com.fourisland.fourpuzzle.database.Database;
9import com.fourisland.fourpuzzle.*; 9import com.fourisland.fourpuzzle.*;
10import com.fourisland.fourpuzzle.database.Transitions; 10import com.fourisland.fourpuzzle.database.Transitions;
11import com.fourisland.fourpuzzle.gamestate.GameOverGameState;
12import com.fourisland.fourpuzzle.gamestate.TitleScreenGameState;
11import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; 13import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
12import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; 14import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent;
13import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; 15import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
@@ -148,18 +150,32 @@ public class SpecialEvent {
148 150
149 /** 151 /**
150 * Triggers the Game Over sequence 152 * Triggers the Game Over sequence
153 *
154 * @throws InterruptedException
151 */ 155 */
152 public void GameOver() 156 public void GameOver() throws InterruptedException
153 { 157 {
154 throw new UnsupportedOperationException("Not yet implemented"); 158 Display.transition(Database.getTransition(Transitions.MapToGameOver));
159
160 Audio.stopMusic();
161 Game.setGameState(new GameOverGameState());
162
163 Display.transition(Database.getTransition(Transitions.GameOverEnter));
155 } 164 }
156 165
157 /** 166 /**
158 * Returns the player to the Title Screen 167 * Returns the player to the Title Screen
168 *
169 * @throws InterruptedException
159 */ 170 */
160 public void TitleScreen() 171 public void TitleScreen() throws InterruptedException
161 { 172 {
162 throw new UnsupportedOperationException("Not yet implemented"); 173 Display.transition(Database.getTransition(Transitions.MapToTitle));
174
175 Audio.stopMusic();
176 Game.setGameState(new TitleScreenGameState());
177
178 Display.transition(Database.getTransition(Transitions.TitleEnter));
163 } 179 }
164 180
165 private boolean startedTransition = false; 181 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 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.transition;
7
8import com.fourisland.fourpuzzle.Display;
9import com.fourisland.fourpuzzle.Game;
10import com.fourisland.fourpuzzle.util.PauseTimer;
11import java.awt.Color;
12import java.awt.Graphics2D;
13import java.awt.image.BufferedImage;
14
15/**
16 *
17 * @author hatkirby
18 */
19public class FadeTransition implements MultidirectionalTransition {
20
21 private TransitionDirection direction;
22 public FadeTransition(TransitionDirection direction)
23 {
24 this.direction = direction;
25 }
26
27 public TransitionDirection getDirection()
28 {
29 return direction;
30 }
31
32 private int ticks = 750 / Game.FPS;
33 private PauseTimer pt = new PauseTimer(ticks);
34 public boolean render(Graphics2D g)
35 {
36 BufferedImage temp = Display.createCanvas(Game.WIDTH, Game.HEIGHT);
37 double alpha = 1.0 * pt.getTimer() / ticks * 0.75;
38
39 for (int i=0;i<Game.WIDTH;i++)
40 {
41 for (int j=0;j<Game.HEIGHT;j++)
42 {
43 if (direction == TransitionDirection.Out)
44 {
45 temp.setRGB(i, j, combine(preTransition.getRGB(i, j), Color.BLACK.getRGB(), alpha));
46 } else if (direction == TransitionDirection.In)
47 {
48 temp.setRGB(i, j, combine(preTransition.getRGB(i, j), postTransition.getRGB(i, j), alpha));
49 }
50 }
51 }
52
53 g.drawImage(temp, 0, 0, null);
54
55 if (pt.isElapsed())
56 {
57 return true;
58 }
59
60 return false;
61 }
62
63 public static int combine(int c1, int c2, double alpha)
64 {
65 Color co1 = new Color(c1);
66 Color co2 = new Color(c2);
67
68 int r = (int) (alpha * co1.getRed() + (1 - alpha) * co2.getRed());
69 int g = (int) (alpha * co1.getGreen() + (1 - alpha) * co2.getGreen());
70 int b = (int) (alpha * co1.getBlue() + (1 - alpha) * co2.getBlue());
71
72 return new Color(r, g, b).getRGB();
73 }
74
75 private BufferedImage preTransition;
76 public void setPreTransition(BufferedImage preTransition)
77 {
78 this.preTransition = preTransition;
79 }
80
81 public Transition copy()
82 {
83 return new FadeTransition(direction);
84 }
85
86 private BufferedImage postTransition;
87 public void setPostTransition(BufferedImage postTransition)
88 {
89 this.postTransition = postTransition;
90 }
91
92}
diff --git a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java index 6df3796..f1cb157 100755 --- a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java +++ b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java
@@ -86,14 +86,14 @@ public class ObjectLoader {
86 } 86 }
87 87
88 bImg.createGraphics().drawImage(bImg, 0, 0, new Color(transparencyColor, true), null); 88 bImg.createGraphics().drawImage(bImg, 0, 0, new Color(transparencyColor, true), null);
89 89
90 addToObjectCache(imageCache, type + "/" + name, bImg); 90 addToObjectCache(imageCache, type + "/" + name, bImg);
91 } 91 }
92 92
93 return imageCache.get(type + "/" + name); 93 return imageCache.get(type + "/" + name);
94 } 94 }
95 95
96 public static void addToObjectCache(Map cacheMap, String name, Object object) 96 public static <T> void addToObjectCache(Map<String, T> cacheMap, String name, T object)
97 { 97 {
98 if (cacheMap.size() >= 100) 98 if (cacheMap.size() >= 100)
99 { 99 {
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 {
37 { 37 {
38 this.ticks = ticks; 38 this.ticks = ticks;
39 } 39 }
40
41 public int getTimer()
42 {
43 if (in.isElapsed())
44 {
45 if (ticks > 0)
46 {
47 ticks--;
48 }
49 }
50
51 return ticks;
52 }
40 53
41} 54}