From fdcfd3a69e1e1a77d83f00a4c549704e725743f0 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Thu, 5 Feb 2009 21:31:48 -0500 Subject: Fixed Transition processing --- src/com/fourisland/fourpuzzle/Display.java | 38 ++++++++++++++++------ .../fourpuzzle/transition/InTransition.java | 1 + .../fourpuzzle/transition/SquareTransition.java | 30 ++++++++++++----- 3 files changed, 50 insertions(+), 19 deletions(-) (limited to 'src/com') diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index 4f1e730..3e13aba 100644 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java @@ -69,23 +69,30 @@ public class Display { Graphics2D g = vImg.createGraphics(); - if (transition != null) + if (transitionRunning) { - if (transition.render(g)) + Game.getGameState().render(g); + + if (transition != null) { - if (startedTransition) + if (transition.render(g)) { - midTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); - midTransition.getGraphics().drawImage(vImg, 0, 0, null); - } else { - midTransition = null; + if (startedTransition) + { + midTransition = vImg.getSnapshot(); + } else { + midTransition = null; + } + + transitionWait.countDown(); } - - transitionWait.countDown(); + } else { + g.drawImage(midTransition, 0, 0, null); } + } else { + Game.getGameState().render(g); } - Game.getGameState().render(g); g.dispose(); } @@ -94,6 +101,7 @@ public class Display { private static CountDownLatch transitionWait; private static boolean transitionRunning = false; private static BufferedImage midTransition = null; + private static BufferedImage postTransition = null; public static void transition(Transition transition) throws InterruptedException { if (transition instanceof MultidirectionalTransition) @@ -111,6 +119,10 @@ public class Display { if (temp.getDirection() == TransitionDirection.In) { temp.setPreTransition(midTransition); + + postTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + Game.getGameState().render(postTransition.createGraphics()); + temp.setPostTransition(postTransition); } } else { if (startedTransition && !(transition instanceof InTransition)) @@ -124,6 +136,10 @@ public class Display { if (transition instanceof InTransition) { ((InTransition) transition).setPreTransition(midTransition); + + postTransition = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + Game.getGameState().render(postTransition.createGraphics()); + ((InTransition) transition).setPostTransition(postTransition); } } @@ -134,6 +150,8 @@ public class Display { transitionWait = new CountDownLatch(1); transitionWait.await(); + transition = null; + if (!startedTransition) { transitionRunning = false; diff --git a/src/com/fourisland/fourpuzzle/transition/InTransition.java b/src/com/fourisland/fourpuzzle/transition/InTransition.java index a326f52..0612bbb 100644 --- a/src/com/fourisland/fourpuzzle/transition/InTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/InTransition.java @@ -14,5 +14,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/SquareTransition.java b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java index 1d8748a..fce70d1 100644 --- a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java @@ -5,6 +5,7 @@ package com.fourisland.fourpuzzle.transition; +import com.fourisland.fourpuzzle.Game; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; @@ -31,21 +32,26 @@ public class SquareTransition implements MultidirectionalTransition { public boolean render(Graphics2D g) { - if (((direction == TransitionDirection.Out) && (tick == 0)) || ((direction == TransitionDirection.In) && (tick == 160))) - { - return true; - } - 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; + tick-=8; + + g.setColor(Color.BLACK); + g.fillRect(0, 0, Game.WIDTH, 160-tick); + g.fillRect(0, 0, 160-tick, Game.HEIGHT); + g.fillRect(tick*2+(160-tick), 0, Game.WIDTH-(tick*2), Game.HEIGHT); + g.fillRect(0, tick*2-40+(140-tick), Game.WIDTH, Game.HEIGHT-(tick*2-40)); } - g.setBackground(Color.BLACK); - g.fillRect(0, 0, 320, 240); - g.setClip(160-tick, 140-tick, tick*2, tick*2-40); + if (((direction == TransitionDirection.Out) && (tick == 0)) || ((direction == TransitionDirection.In) && (tick == 160))) + { + return true; + } return false; } @@ -60,5 +66,11 @@ public class SquareTransition implements MultidirectionalTransition { { this.preTransition = preTransition; } + + private BufferedImage postTransition; + public void setPostTransition(BufferedImage postTransition) + { + this.postTransition = postTransition; + } } -- cgit 1.4.1