Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 10:11 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun May 18, 2008 7:43 am 
Offline

Joined: Tue May 13, 2008 11:24 pm
Posts: 6
Location: Ottawa, Canada
Didnt find it in Slick so i whipped one up...
(Quite laggy, especially on higher resolutions.... lemme know if there is workaround for faster proccesing or some way to improve it)

Code:
//////////////////////////////////////////////////////////////////
// ------------------------------------------------------------ //
//                                                              //
// Developer: David Krutsko                                     //
//                                                              //
//   Created: May 18, 2008                                      //
//  Modified: May 18, 2008                                      //
//                                                              //
//     Name: MosaicTransitionOut.java                           //
//  Purpose: A mosaic transition between two states             //
//                                                              //
//   Status: Open Source                                        //
//                                                              //
// ------------------------------------------------------------ //
//                   Developed for SLICK 2D                     //
//////////////////////////////////////////////////////////////////

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.state.GameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.Transition;

public class MosaicTransitionOut implements Transition
{
   private float Speed;      // Speed of the transition
   private float Multiplier; // Stage of the transition
   private boolean Complete; // Is transition comlpete
   
   // Create a new mosaic transition
   public MosaicTransitionOut()
   {
      this (450f);
   }
   
   // Create a new mosaic transition
   // Speed - The time it takes for the transition to finish
   public MosaicTransitionOut (float Speed)
   {
      Multiplier = 25;
      Complete = false;
      this.Speed = (float) 500 / Speed;
   }
   
   // Check if this transtion has been completed
   // Return - True if the transition has been completed
   public boolean isComplete()
   {
      return Complete;
   }
   
   // Render the transition over the existing state rendering
   // game - The game this transition is being rendered as part of
   // container - The container holding the game
   // g - The graphics context to use when rendering the transiton
   // Throws - SlickException: Indicates a failure occured during the render
   public void postRender (StateBasedGame game, GameContainer container, Graphics g)
   {
      for (int y = 0; y <= container.getHeight(); y += Multiplier)
         for (int x = 0; x <= container.getWidth(); x += Multiplier)
         {
            g.setColor (g.getPixel (x + 1, y + 1));
            g.fillRect (x, y, Multiplier, Multiplier);
         }
   }
   
   // Update the transition. Cause what ever happens in the transition to happen
   // game - The game this transition is being rendered as part of
   // container - The container holding the game
   // delta - The amount of time passed since last update
   // Throws - SlickException: Indicates a failure occured during the update
   public void update (StateBasedGame game, GameContainer container, int delta)
   {
      if (Multiplier < container.getWidth() && Multiplier < container.getHeight())
         Multiplier *= Speed;
      
      else Complete = true;
   }
   
   // Render the transition before the existing state rendering
   // game - The game this transition is being rendered as part of
   // container - The container holding the game
   // delta - The amount of time passed since last update
   // Throws - SlickException: Indicates a failure occured during the update
   public void preRender (StateBasedGame game, GameContainer container, Graphics g)
   {
   }
   
   // Initialise the transition
   // firstState - The first state we're rendering (this will be rendered by the framework)
   // secondState - The second stat we're transitioning to or from (this one won't be rendered)
   public void init (GameState firstState, GameState secondState)
   {
   }
}


Code:
//////////////////////////////////////////////////////////////////
// ------------------------------------------------------------ //
//                                                              //
// Developer: David Krutsko                                     //
//                                                              //
//   Created: May 18, 2008                                      //
//  Modified: May 18, 2008                                      //
//                                                              //
//     Name: MosaicTransitionIn.java                            //
//  Purpose: A mosaic transition between two states             //
//                                                              //
//   Status: Open Source                                        //
//                                                              //
// ------------------------------------------------------------ //
//                   Developed for SLICK 2D                     //
//////////////////////////////////////////////////////////////////

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.state.GameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.Transition;

public class MosaicTransitionIn implements Transition
{
   private float Speed;      // Speed of the transition
   private float Multiplier; // Stage of the transition
   private boolean Complete; // Is transition comlpete
   
   // Create a new mosaic transition
   // Size - Initial size of the multiplier
   public MosaicTransitionIn (float Size)
   {
      this (450f, Size);
   }
   
   // Create a new mosaic transition
   // Speed - The time it takes for the transition to finish
   // Size - Initial size of the multiplier
   public MosaicTransitionIn (float Speed, float Size)
   {
      Multiplier = Size;
      Complete = false;
      this.Speed = (float) 500 / Speed;
   }
   
   // Check if this transtion has been completed
   // Return - True if the transition has been completed
   public boolean isComplete()
   {
      return Complete;
   }
   
   // Render the transition over the existing state rendering
   // game - The game this transition is being rendered as part of
   // container - The container holding the game
   // g - The graphics context to use when rendering the transiton
   // Throws - SlickException: Indicates a failure occured during the render
   public void postRender (StateBasedGame game, GameContainer container, Graphics g)
   {
      for (int y = 0; y <= container.getHeight(); y += Multiplier)
         for (int x = 0; x <= container.getWidth(); x += Multiplier)
         {
            g.setColor (g.getPixel (x + 1, y + 1));
            g.fillRect (x, y, Multiplier, Multiplier);
         }
   }
   
   // Update the transition. Cause what ever happens in the transition to happen
   // game - The game this transition is being rendered as part of
   // container - The container holding the game
   // delta - The amount of time passed since last update
   // Throws - SlickException: Indicates a failure occured during the update
   public void update (StateBasedGame game, GameContainer container, int delta)
   {
      if (Multiplier > 25)
         Multiplier /= Speed;
      
      else Complete = true;
   }
   
   // Render the transition before the existing state rendering
   // game - The game this transition is being rendered as part of
   // container - The container holding the game
   // delta - The amount of time passed since last update
   // Throws - SlickException: Indicates a failure occured during the update
   public void preRender (StateBasedGame game, GameContainer container, Graphics g)
   {
   }
   
   // Initialise the transition
   // firstState - The first state we're rendering (this will be rendered by the framework)
   // secondState - The second stat we're transitioning to or from (this one won't be rendered)
   public void init (GameState firstState, GameState secondState)
   {
   }
}

_________________
David Krutsko
davidkrutsko@Hotmail.co
Biocom Research


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group