mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
added sources for Slick
Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054 Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
import org.newdawn.slick.opengl.renderer.SGL;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.util.MaskUtil;
|
||||
|
||||
/**
|
||||
* A transition that causes the previous state to rotate and scale down into
|
||||
* the new state.
|
||||
*
|
||||
* This is an enter transition
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class BlobbyTransition implements Transition {
|
||||
/** The renderer to use for all GL operations */
|
||||
protected static SGL GL = Renderer.get();
|
||||
|
||||
/** The previous state */
|
||||
private GameState prev;
|
||||
/** True if the state has finished */
|
||||
private boolean finish;
|
||||
/** The background applied under the previous state if any */
|
||||
private Color background;
|
||||
/** ArrayList blobs */
|
||||
private ArrayList blobs = new ArrayList();
|
||||
/** The time it will run for */
|
||||
private int timer = 1000;
|
||||
/** The number of blobs to create */
|
||||
private int blobCount = 10;
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*/
|
||||
public BlobbyTransition() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*
|
||||
* @param background The background colour to draw under the previous state
|
||||
*/
|
||||
public BlobbyTransition(Color background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#init(org.newdawn.slick.state.GameState, org.newdawn.slick.state.GameState)
|
||||
*/
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
prev = secondState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
MaskUtil.resetMask();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container,
|
||||
Graphics g) throws SlickException {
|
||||
prev.render(container, game, g);
|
||||
|
||||
MaskUtil.defineMask();
|
||||
for (int i=0;i<blobs.size();i++) {
|
||||
((Blob) blobs.get(i)).render(g);
|
||||
}
|
||||
MaskUtil.finishDefineMask();
|
||||
|
||||
MaskUtil.drawOnMask();
|
||||
if (background != null) {
|
||||
Color c = g.getColor();
|
||||
g.setColor(background);
|
||||
g.fillRect(0,0,container.getWidth(),container.getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
if (blobs.size() == 0) {
|
||||
for (int i=0;i<blobCount;i++) {
|
||||
blobs.add(new Blob(container));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<blobs.size();i++) {
|
||||
((Blob) blobs.get(i)).update(delta);
|
||||
}
|
||||
|
||||
timer -= delta;
|
||||
if (timer < 0) {
|
||||
finish = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A blob to show the new state
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
private class Blob {
|
||||
/** The x coordinate of the centre of this blob */
|
||||
private float x;
|
||||
/** The y coordinate of the centre of this blob */
|
||||
private float y;
|
||||
/** The speed at which this blob grows */
|
||||
private float growSpeed;
|
||||
/** The radius of this blob */
|
||||
private float rad;
|
||||
|
||||
/**
|
||||
* Create a new blob
|
||||
*
|
||||
* @param container The container for dimensions
|
||||
*/
|
||||
public Blob(GameContainer container) {
|
||||
x = (float) (Math.random() * container.getWidth());
|
||||
y = (float) (Math.random() * container.getWidth());
|
||||
growSpeed = (float) (1f + (Math.random() * 1f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the blob
|
||||
*
|
||||
* @param delta The change in time in milliseconds
|
||||
*/
|
||||
public void update(int delta) {
|
||||
rad += growSpeed * delta * 0.4f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the blob - i.e. the mask
|
||||
*
|
||||
* @param g The grphics context on which the mask should be drawn
|
||||
*/
|
||||
public void render(Graphics g) {
|
||||
g.fillOval(x-rad,y-rad,rad*2,rad*2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition thats built of a set of other transitions which are chained
|
||||
* together to build the overall effect.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class CombinedTransition implements Transition {
|
||||
/** The list of transitions to be combined */
|
||||
private ArrayList transitions = new ArrayList();
|
||||
|
||||
/**
|
||||
* Create an empty transition
|
||||
*/
|
||||
public CombinedTransition() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a transition to the list that will be combined to form
|
||||
* the final transition
|
||||
*
|
||||
* @param t The transition to add
|
||||
*/
|
||||
public void addTransition(Transition t) {
|
||||
transitions.add(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
for (int i=0;i<transitions.size();i++) {
|
||||
if (!((Transition) transitions.get(i)).isComplete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
for (int i=transitions.size()-1;i>=0;i--) {
|
||||
((Transition) transitions.get(i)).postRender(game, container, g);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
for (int i=0;i<transitions.size();i++) {
|
||||
((Transition) transitions.get(i)).postRender(game, container, g);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta) throws SlickException {
|
||||
for (int i=0;i<transitions.size();i++) {
|
||||
Transition t = (Transition) transitions.get(i);
|
||||
|
||||
if (!t.isComplete()) {
|
||||
t.update(game, container, delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
for (int i = transitions.size() - 1; i >= 0; i--) {
|
||||
((Transition)transitions.get(i)).init(firstState, secondState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition that will combine two states into one effect. The first state is
|
||||
* the one we're transitioning from. The second state is specified in the constructor.
|
||||
*
|
||||
* By default one state will simply be rendered over the other. Subclass this transition
|
||||
* overriding the preRenderFirstState and preRenderSecondState to setup the rendering
|
||||
* for each state (alpha or what ever). Note that it's also possible to use the
|
||||
* postRenderSecondState method to clean up your OpenGL setup.
|
||||
*
|
||||
* So these methods are called like so:
|
||||
*
|
||||
* preRenderFirstState()
|
||||
* = the first state is rendered
|
||||
* preRenderSecondState()
|
||||
* = the second state is rendered
|
||||
* postRenderSecondState()
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public abstract class CrossStateTransition implements Transition {
|
||||
/** The second state to cross with */
|
||||
private GameState secondState;
|
||||
|
||||
/**
|
||||
* Create a cross state transitions
|
||||
*
|
||||
* @param secondState The secondary state with combining with the
|
||||
* source state.
|
||||
*/
|
||||
public CrossStateTransition(GameState secondState) {
|
||||
this.secondState = secondState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public abstract boolean isComplete();
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
preRenderSecondState(game, container, g);
|
||||
secondState.render(container, game, g);
|
||||
postRenderSecondState(game, container, g);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
preRenderFirstState(game, container, g);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification that the transition is about to render the first state is the cross
|
||||
* transition.
|
||||
*
|
||||
* @param game The game being rendered
|
||||
* @param container The container holding the game
|
||||
* @param g The graphic context used to render
|
||||
* @throws SlickException Indicates a failure to setup the rendering state - throw for anything that goes wrong
|
||||
*/
|
||||
public void preRenderFirstState(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification that the transition is about to render the second state is the cross
|
||||
* transition.
|
||||
*
|
||||
* @param game The game being rendered
|
||||
* @param container The container holding the game
|
||||
* @param g The graphic context used to render
|
||||
* @throws SlickException Indicates a failure to setup the rendering state - throw for anything that goes wrong
|
||||
*/
|
||||
public void preRenderSecondState(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification that the transition is has just rendered the second state is the cross
|
||||
* transition.
|
||||
*
|
||||
* @param game The game being rendered
|
||||
* @param container The container holding the game
|
||||
* @param g The graphic context used to render
|
||||
* @throws SlickException Indicates a failure to setup the rendering state - throw for anything that goes wrong
|
||||
*/
|
||||
public void postRenderSecondState(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition that has no effect and instantly finishes. Used as a utility for the people
|
||||
* not using transitions
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class EmptyTransition implements Transition {
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
// no op
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
// no op
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta) throws SlickException {
|
||||
// no op
|
||||
}
|
||||
|
||||
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition to fade in from a given colour
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class FadeInTransition implements Transition {
|
||||
/** The color to fade to */
|
||||
private Color color;
|
||||
/** The time it takes to fade in */
|
||||
private int fadeTime = 500;
|
||||
|
||||
/**
|
||||
* Create a new fade in transition
|
||||
*/
|
||||
public FadeInTransition() {
|
||||
this(Color.black, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new fade in transition
|
||||
*
|
||||
* @param color The color we're going to fade in from
|
||||
*/
|
||||
public FadeInTransition(Color color) {
|
||||
this(color, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new fade in transition
|
||||
*
|
||||
* @param color The color we're going to fade in from
|
||||
* @param fadeTime The time it takes for the fade to occur
|
||||
*/
|
||||
public FadeInTransition(Color color, int fadeTime) {
|
||||
this.color = new Color(color);
|
||||
this.color.a = 1;
|
||||
this.fadeTime = fadeTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return (color.a <= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) {
|
||||
Color old = g.getColor();
|
||||
g.setColor(color);
|
||||
|
||||
g.fillRect(0, 0, container.getWidth()*2, container.getHeight()*2);
|
||||
g.setColor(old);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta) {
|
||||
color.a -= delta * (1.0f / fadeTime);
|
||||
if (color.a < 0) {
|
||||
color.a = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container, Graphics g) {
|
||||
}
|
||||
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition to fade out to a given colour
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class FadeOutTransition implements Transition {
|
||||
/** The color to fade to */
|
||||
private Color color;
|
||||
/** The time it takes the fade to happen */
|
||||
private int fadeTime;
|
||||
|
||||
/**
|
||||
* Create a new fade out transition
|
||||
*/
|
||||
public FadeOutTransition() {
|
||||
this(Color.black, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new fade out transition
|
||||
*
|
||||
* @param color The color we're going to fade out to
|
||||
*/
|
||||
public FadeOutTransition(Color color) {
|
||||
this(color, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new fade out transition
|
||||
*
|
||||
* @param color The color we're going to fade out to
|
||||
* @param fadeTime The time it takes the fade to occur
|
||||
*/
|
||||
public FadeOutTransition(Color color, int fadeTime) {
|
||||
this.color = new Color(color);
|
||||
this.color.a = 0;
|
||||
this.fadeTime = fadeTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return (color.a >= 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) {
|
||||
Color old = g.getColor();
|
||||
g.setColor(color);
|
||||
g.fillRect(0, 0, container.getWidth() * 2, container.getHeight() * 2);
|
||||
g.setColor(old);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta) {
|
||||
color.a += delta * (1.0f / fadeTime);
|
||||
if (color.a > 1) {
|
||||
color.a = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container, Graphics g) {
|
||||
}
|
||||
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
import org.newdawn.slick.opengl.renderer.SGL;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* Horitzonal split transition that causes the previous state to split horizontally
|
||||
* revealing the new state underneath.
|
||||
*
|
||||
* This state is an enter transition.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class HorizontalSplitTransition implements Transition {
|
||||
/** The renderer to use for all GL operations */
|
||||
protected static SGL GL = Renderer.get();
|
||||
|
||||
/** The previous game state */
|
||||
private GameState prev;
|
||||
/** The current offset */
|
||||
private float offset;
|
||||
/** True if the transition is finished */
|
||||
private boolean finish;
|
||||
/** The background to draw underneath the previous state (null for none) */
|
||||
private Color background;
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*/
|
||||
public HorizontalSplitTransition() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*
|
||||
* @param background The background colour to draw under the previous state
|
||||
*/
|
||||
public HorizontalSplitTransition(Color background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#init(org.newdawn.slick.state.GameState, org.newdawn.slick.state.GameState)
|
||||
*/
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
prev = secondState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
g.translate(-offset, 0);
|
||||
g.setClip((int)-offset,0,container.getWidth()/2,container.getHeight());
|
||||
if (background != null) {
|
||||
Color c = g.getColor();
|
||||
g.setColor(background);
|
||||
g.fillRect(0,0,container.getWidth(),container.getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
GL.glPushMatrix();
|
||||
prev.render(container, game, g);
|
||||
GL.glPopMatrix();
|
||||
g.clearClip();
|
||||
|
||||
g.translate(offset*2, 0);
|
||||
g.setClip((int)((container.getWidth()/2)+offset),0,container.getWidth()/2,container.getHeight());
|
||||
if (background != null) {
|
||||
Color c = g.getColor();
|
||||
g.setColor(background);
|
||||
g.fillRect(0,0,container.getWidth(),container.getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
GL.glPushMatrix();
|
||||
prev.render(container, game, g);
|
||||
GL.glPopMatrix();
|
||||
g.clearClip();
|
||||
g.translate(-offset, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container,
|
||||
Graphics g) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
offset += delta * 1f;
|
||||
if (offset > container.getWidth() / 2) {
|
||||
finish = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition that causes the previous state to rotate and scale down into
|
||||
* the new state.
|
||||
*
|
||||
* This is an enter transition
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class RotateTransition implements Transition {
|
||||
/** The previous state */
|
||||
private GameState prev;
|
||||
/** The current angle of rotation */
|
||||
private float ang;
|
||||
/** True if the state has finished */
|
||||
private boolean finish;
|
||||
/** The current scale */
|
||||
private float scale = 1;
|
||||
/** The background applied under the previous state if any */
|
||||
private Color background;
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*/
|
||||
public RotateTransition() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*
|
||||
* @param background The background colour to draw under the previous state
|
||||
*/
|
||||
public RotateTransition(Color background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#init(org.newdawn.slick.state.GameState, org.newdawn.slick.state.GameState)
|
||||
*/
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
prev = secondState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
g.translate(container.getWidth()/2, container.getHeight()/2);
|
||||
g.scale(scale,scale);
|
||||
g.rotate(0, 0, ang);
|
||||
g.translate(-container.getWidth()/2, -container.getHeight()/2);
|
||||
if (background != null) {
|
||||
Color c = g.getColor();
|
||||
g.setColor(background);
|
||||
g.fillRect(0,0,container.getWidth(),container.getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
prev.render(container, game, g);
|
||||
g.translate(container.getWidth()/2, container.getHeight()/2);
|
||||
g.rotate(0, 0, -ang);
|
||||
g.scale(1/scale,1/scale);
|
||||
g.translate(-container.getWidth()/2, -container.getHeight()/2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container,
|
||||
Graphics g) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
ang += delta * 0.5f;
|
||||
if (ang > 500) {
|
||||
finish = true;
|
||||
}
|
||||
scale -= delta * 0.001f;
|
||||
if (scale < 0) {
|
||||
scale = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
import org.newdawn.slick.opengl.renderer.SGL;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition that moves to the next as though it was selected by some background menu. Note
|
||||
* this transition is provided as an example more than intended for use. The values contained
|
||||
* are designed for 800x600 resolution.
|
||||
*
|
||||
* This is an enter transition
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class SelectTransition implements Transition {
|
||||
/** The renderer to use for all GL operations */
|
||||
protected static SGL GL = Renderer.get();
|
||||
|
||||
/** The previous state */
|
||||
private GameState prev;
|
||||
/** True if the state has finished */
|
||||
private boolean finish;
|
||||
/** The background applied under the previous state if any */
|
||||
private Color background;
|
||||
|
||||
/** The scale of the first state */
|
||||
private float scale1 = 1;
|
||||
/** The x coordinate to render the first state */
|
||||
private float xp1 = 0;
|
||||
/** The y coordinate to render the first state */
|
||||
private float yp1 = 0;
|
||||
/** The scale of the second state */
|
||||
private float scale2 = 0.4f;
|
||||
/** The x coordinate to render the second state */
|
||||
private float xp2 = 0;
|
||||
/** The y coordinate to render the second state */
|
||||
private float yp2 = 0;
|
||||
/** True if this transition has been initialised */
|
||||
private boolean init = false;
|
||||
|
||||
/** True if the move back of the first state is complete */
|
||||
private boolean moveBackDone = false;
|
||||
/** The length of the pause between selection */
|
||||
private int pause = 300;
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*/
|
||||
public SelectTransition() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*
|
||||
* @param background The background colour to draw under the previous state
|
||||
*/
|
||||
public SelectTransition(Color background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#init(org.newdawn.slick.state.GameState, org.newdawn.slick.state.GameState)
|
||||
*/
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
prev = secondState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
g.resetTransform();
|
||||
|
||||
if (!moveBackDone) {
|
||||
g.translate(xp1,yp1);
|
||||
g.scale(scale1, scale1);
|
||||
g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight()));
|
||||
prev.render(container, game, g);
|
||||
g.resetTransform();
|
||||
g.clearClip();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container,
|
||||
Graphics g) throws SlickException {
|
||||
if (moveBackDone) {
|
||||
g.translate(xp1,yp1);
|
||||
g.scale(scale1, scale1);
|
||||
g.setClip((int) xp1,(int) yp1,(int) (scale1*container.getWidth()),(int) (scale1*container.getHeight()));
|
||||
prev.render(container, game, g);
|
||||
g.resetTransform();
|
||||
g.clearClip();
|
||||
}
|
||||
|
||||
g.translate(xp2,yp2);
|
||||
g.scale(scale2, scale2);
|
||||
g.setClip((int) xp2,(int) yp2,(int) (scale2*container.getWidth()),(int) (scale2*container.getHeight()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
if (!init) {
|
||||
init = true;
|
||||
xp2 = (container.getWidth()/2)+50;
|
||||
yp2 = (container.getHeight()/4);
|
||||
}
|
||||
|
||||
if (!moveBackDone) {
|
||||
if (scale1 > 0.4f) {
|
||||
scale1 -= delta * 0.002f;
|
||||
if (scale1 <= 0.4f) {
|
||||
scale1 = 0.4f;
|
||||
}
|
||||
xp1 += delta * 0.3f;
|
||||
if (xp1 > 50) {
|
||||
xp1 = 50;
|
||||
}
|
||||
yp1 += delta * 0.5f;
|
||||
if (yp1 > (container.getHeight()/4)) {
|
||||
yp1 = (container.getHeight()/4);
|
||||
}
|
||||
} else {
|
||||
moveBackDone = true;
|
||||
}
|
||||
} else {
|
||||
pause -= delta;
|
||||
if (pause > 0) {
|
||||
return;
|
||||
}
|
||||
if (scale2 < 1) {
|
||||
scale2 += delta * 0.002f;
|
||||
if (scale2 >= 1) {
|
||||
scale2 = 1f;
|
||||
}
|
||||
xp2 -= delta * 1.5f;
|
||||
if (xp2 < 0) {
|
||||
xp2 = 0;
|
||||
}
|
||||
yp2 -= delta * 0.5f;
|
||||
if (yp2 < 0) {
|
||||
yp2 = 0;
|
||||
}
|
||||
} else {
|
||||
finish = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* A transition between two game states
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public interface Transition {
|
||||
/**
|
||||
* Update the transition. Cause what ever happens in the transition to happen
|
||||
*
|
||||
* @param game The game this transition is being rendered as part of
|
||||
* @param container The container holding the game
|
||||
* @param 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) throws SlickException;
|
||||
|
||||
/**
|
||||
* Render the transition before the existing state rendering
|
||||
*
|
||||
* @param game The game this transition is being rendered as part of
|
||||
* @param container The container holding the game
|
||||
* @param g The graphics context to use when rendering the transiton
|
||||
* @throws SlickException Indicates a failure occured during the render
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException;
|
||||
|
||||
/**
|
||||
* Render the transition over the existing state rendering
|
||||
*
|
||||
* @param game The game this transition is being rendered as part of
|
||||
* @param container The container holding the game
|
||||
* @param 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) throws SlickException;
|
||||
|
||||
/**
|
||||
* Check if this transtion has been completed
|
||||
*
|
||||
* @return True if the transition has been completed
|
||||
*/
|
||||
public boolean isComplete();
|
||||
|
||||
/**
|
||||
* Initialise the transition
|
||||
*
|
||||
* @param firstState The first state we're rendering (this will be rendered by the framework)
|
||||
* @param secondState The second stat we're transitioning to or from (this one won't be rendered)
|
||||
*/
|
||||
public void init(GameState firstState, GameState secondState);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package org.newdawn.slick.state.transition;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.opengl.renderer.Renderer;
|
||||
import org.newdawn.slick.opengl.renderer.SGL;
|
||||
import org.newdawn.slick.state.GameState;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
|
||||
/**
|
||||
* Vertical split transition that causes the previous state to split vertically
|
||||
* revealing the new state underneath.
|
||||
*
|
||||
* This state is an enter transition.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class VerticalSplitTransition implements Transition {
|
||||
/** The renderer to use for all GL operations */
|
||||
protected static SGL GL = Renderer.get();
|
||||
|
||||
/** The previous game state */
|
||||
private GameState prev;
|
||||
/** The current offset */
|
||||
private float offset;
|
||||
/** True if the transition is finished */
|
||||
private boolean finish;
|
||||
/** The background to draw underneath the previous state (null for none) */
|
||||
private Color background;
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*/
|
||||
public VerticalSplitTransition() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new transition
|
||||
*
|
||||
* @param background The background colour to draw under the previous state
|
||||
*/
|
||||
public VerticalSplitTransition(Color background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#init(org.newdawn.slick.state.GameState, org.newdawn.slick.state.GameState)
|
||||
*/
|
||||
public void init(GameState firstState, GameState secondState) {
|
||||
prev = secondState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#isComplete()
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return finish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
|
||||
g.translate(0, -offset);
|
||||
g.setClip(0,(int)-offset,container.getWidth(),container.getHeight()/2);
|
||||
if (background != null) {
|
||||
Color c = g.getColor();
|
||||
g.setColor(background);
|
||||
g.fillRect(0,0,container.getWidth(),container.getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
GL.glPushMatrix();
|
||||
prev.render(container, game, g);
|
||||
GL.glPopMatrix();
|
||||
g.clearClip();
|
||||
g.resetTransform();
|
||||
|
||||
g.translate(0, offset);
|
||||
g.setClip(0,(int)((container.getHeight()/2)+(offset)),container.getWidth(),container.getHeight()/2);
|
||||
if (background != null) {
|
||||
Color c = g.getColor();
|
||||
g.setColor(background);
|
||||
g.fillRect(0,0,container.getWidth(),container.getHeight());
|
||||
g.setColor(c);
|
||||
}
|
||||
GL.glPushMatrix();
|
||||
prev.render(container, game, g);
|
||||
GL.glPopMatrix();
|
||||
g.clearClip();
|
||||
g.translate(0,-offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#preRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public void preRender(StateBasedGame game, GameContainer container,
|
||||
Graphics g) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.transition.Transition#update(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public void update(StateBasedGame game, GameContainer container, int delta)
|
||||
throws SlickException {
|
||||
offset += delta * 1f;
|
||||
if (offset > container.getHeight() / 2) {
|
||||
finish = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user