From d8cb6073cc7c5df28d7fbea8d86f3d70fe01e7a0 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Fri, 6 Feb 2009 15:12:43 -0500 Subject: Implemented SlideTransition --- src/com/fourisland/fourpuzzle/Display.java | 10 +- .../transition/DoNotEraseTransition.java | 6 + .../fourpuzzle/transition/InTransition.java | 1 - .../fourpuzzle/transition/SlideTransition.java | 140 +++++++++++++++++++++ .../fourpuzzle/transition/SquareTransition.java | 3 +- .../fourpuzzle/transition/Transition.java | 2 + 6 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/transition/SlideTransition.java diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 3e13aba..f513d31 100644 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java @@ -123,6 +123,10 @@ public class Display { postTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); Game.getGameState().render(postTransition.createGraphics()); temp.setPostTransition(postTransition); + } else { + BufferedImage preTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + Game.getGameState().render(preTransition.createGraphics()); + temp.setPreTransition(preTransition); } } else { if (startedTransition && !(transition instanceof InTransition)) @@ -135,11 +139,15 @@ public class Display { if (transition instanceof InTransition) { - ((InTransition) transition).setPreTransition(midTransition); + transition.setPreTransition(midTransition); postTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); Game.getGameState().render(postTransition.createGraphics()); ((InTransition) transition).setPostTransition(postTransition); + } else { + BufferedImage preTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + Game.getGameState().render(preTransition.createGraphics()); + transition.setPreTransition(preTransition); } } diff --git a/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java b/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java index 63c3ea3..ccdf3f2 100644 --- a/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java @@ -6,6 +6,7 @@ package com.fourisland.fourpuzzle.transition; import java.awt.Graphics2D; +import java.awt.image.BufferedImage; /** * @@ -18,4 +19,9 @@ public class DoNotEraseTransition implements OutTransition { return true; } + public void setPreTransition(BufferedImage preTransition) + { + // Do nothing + } + } diff --git a/src/com/fourisland/fourpuzzle/transition/InTransition.java b/src/com/fourisland/fourpuzzle/transition/InTransition.java index 0612bbb..6c07aa5 100644 --- a/src/com/fourisland/fourpuzzle/transition/InTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/InTransition.java @@ -13,7 +13,6 @@ import java.awt.image.BufferedImage; */ public interface InTransition extends Transition { - public void setPreTransition(BufferedImage preTransition); public void setPostTransition(BufferedImage postTransition); } diff --git a/src/com/fourisland/fourpuzzle/transition/SlideTransition.java b/src/com/fourisland/fourpuzzle/transition/SlideTransition.java new file mode 100644 index 0000000..e40ad99 --- /dev/null +++ b/src/com/fourisland/fourpuzzle/transition/SlideTransition.java @@ -0,0 +1,140 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle.transition; + +import com.fourisland.fourpuzzle.Direction; +import com.fourisland.fourpuzzle.Game; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +/** + * + * @author hatkirby + */ +public class SlideTransition implements MultidirectionalTransition { + + TransitionDirection direction; + Direction d; + public SlideTransition(TransitionDirection direction, Direction d) + { + this.direction = direction; + this.d = d; + + if (d == Direction.North) + { + max = -(Game.HEIGHT); + way = SlideDirection.UpOrDown; + } else if (d == Direction.West) + { + max = -(Game.WIDTH); + way = SlideDirection.SideToSide; + } else if (d == Direction.South) + { + max = Game.HEIGHT; + way = SlideDirection.UpOrDown; + } else if (d == Direction.East) + { + max = Game.WIDTH; + way = SlideDirection.SideToSide; + } + + wait = Math.round(max / (Game.FPS/2)); + } + + public TransitionDirection getDirection() + { + return direction; + } + + int tick; + int wait; + int max; + SlideDirection way; + public boolean render(Graphics2D g) + { + if (max > 0) + { + tick = Math.min(tick + wait, max); + } else { + tick = Math.max(tick + wait, max); + } + + if (direction == TransitionDirection.Out) + { + g.setColor(Color.BLACK); + + if (way == SlideDirection.SideToSide) + { + g.drawImage(preTransition, tick, 0, null); + + if (max > 0) + { + g.fillRect(0, 0, tick, Game.HEIGHT); + } else { + g.fillRect(Game.WIDTH+tick, 0, -tick, Game.HEIGHT); + } + } else { + g.drawImage(preTransition, 0, tick, null); + + if (max > 0) + { + g.fillRect(0, 0, Game.WIDTH, tick); + } else { + g.fillRect(0, Game.HEIGHT+tick, Game.WIDTH, -tick); + } + } + } else if (direction == TransitionDirection.In) + { + if (way == SlideDirection.SideToSide) + { + g.drawImage(preTransition, tick, 0, null); + + if (max > 0) + { + g.drawImage(postTransition, tick - Game.WIDTH, 0, null); + } else { + g.drawImage(postTransition, Game.WIDTH + tick, 0, null); + } + } else { + g.drawImage(preTransition, 0, tick, null); + + if (max > 0) + { + g.drawImage(postTransition, 0, tick - Game.HEIGHT, null); + } else { + g.drawImage(postTransition, 0, Game.HEIGHT + tick, null); + } + } + } + + if (tick == max) + { + return true; + } + + return false; + } + + private BufferedImage preTransition; + public void setPreTransition(BufferedImage preTransition) + { + this.preTransition = preTransition; + } + + private BufferedImage postTransition; + public void setPostTransition(BufferedImage postTransition) + { + this.postTransition = postTransition; + } + + private enum SlideDirection + { + SideToSide, + UpOrDown + } + +} diff --git a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java index fce70d1..8a74176 100644 --- a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java @@ -32,11 +32,12 @@ public class SquareTransition implements MultidirectionalTransition { public boolean render(Graphics2D g) { + g.drawImage(preTransition, 0, 0, null); + if (direction == TransitionDirection.In) { tick+=8; - g.drawImage(preTransition, 0, 0, null); g.drawImage(postTransition, 160-tick, 140-tick, tick*2+(160-tick), tick*2-40+(140-tick), 160-tick, 140-tick, tick*2+(160-tick), tick*2-40+(140-tick), null); } else { tick-=8; diff --git a/src/com/fourisland/fourpuzzle/transition/Transition.java b/src/com/fourisland/fourpuzzle/transition/Transition.java index 5b4dbe8..445d75d 100644 --- a/src/com/fourisland/fourpuzzle/transition/Transition.java +++ b/src/com/fourisland/fourpuzzle/transition/Transition.java @@ -6,6 +6,7 @@ package com.fourisland.fourpuzzle.transition; import java.awt.Graphics2D; +import java.awt.image.BufferedImage; /** * @@ -21,4 +22,5 @@ public interface Transition { */ public boolean render(Graphics2D g); + public void setPreTransition(BufferedImage preTransition); } \ No newline at end of file -- cgit 1.4.1