mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 03:24:06 +09:00
added sources for Slick
Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054 Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
This commit is contained in:
166
lib/slick-source/org/newdawn/slick/state/BasicGameState.java
Normal file
166
lib/slick-source/org/newdawn/slick/state/BasicGameState.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package org.newdawn.slick.state;
|
||||
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A simple state used an adapter so we don't have to implement all the event methods
|
||||
* every time.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public abstract class BasicGameState implements GameState {
|
||||
/**
|
||||
* @see org.newdawn.slick.ControlledInputReciever#inputStarted()
|
||||
*/
|
||||
public void inputStarted() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#isAcceptingInput()
|
||||
*/
|
||||
public boolean isAcceptingInput() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#setInput(org.newdawn.slick.Input)
|
||||
*/
|
||||
public void setInput(Input input) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#inputEnded()
|
||||
*/
|
||||
public void inputEnded() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.GameState#getID()
|
||||
*/
|
||||
public abstract int getID();
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerButtonPressed(int, int)
|
||||
*/
|
||||
public void controllerButtonPressed(int controller, int button) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerButtonReleased(int, int)
|
||||
*/
|
||||
public void controllerButtonReleased(int controller, int button) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerDownPressed(int)
|
||||
*/
|
||||
public void controllerDownPressed(int controller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerDownReleased(int)
|
||||
*/
|
||||
public void controllerDownReleased(int controller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerLeftPressed(int)
|
||||
*/
|
||||
public void controllerLeftPressed(int controller) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerLeftReleased(int)
|
||||
*/
|
||||
public void controllerLeftReleased(int controller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerRightPressed(int)
|
||||
*/
|
||||
public void controllerRightPressed(int controller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerRightReleased(int)
|
||||
*/
|
||||
public void controllerRightReleased(int controller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerUpPressed(int)
|
||||
*/
|
||||
public void controllerUpPressed(int controller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerUpReleased(int)
|
||||
*/
|
||||
public void controllerUpReleased(int controller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseMoved(int, int, int, int)
|
||||
*/
|
||||
public void mouseMoved(int oldx, int oldy, int newx, int newy) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseDragged(int, int, int, int)
|
||||
*/
|
||||
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseClicked(int, int, int, int)
|
||||
*/
|
||||
public void mouseClicked(int button, int x, int y, int clickCount) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mousePressed(int, int, int)
|
||||
*/
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseReleased(int, int, int)
|
||||
*/
|
||||
public void mouseReleased(int button, int x, int y) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.GameState#enter(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame)
|
||||
*/
|
||||
public void enter(GameContainer container, StateBasedGame game) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.state.GameState#leave(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame)
|
||||
*/
|
||||
public void leave(GameContainer container, StateBasedGame game) throws SlickException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseWheelMoved(int)
|
||||
*/
|
||||
public void mouseWheelMoved(int newValue) {
|
||||
}
|
||||
|
||||
}
|
||||
71
lib/slick-source/org/newdawn/slick/state/GameState.java
Normal file
71
lib/slick-source/org/newdawn/slick/state/GameState.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package org.newdawn.slick.state;
|
||||
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.InputListener;
|
||||
import org.newdawn.slick.SlickException;
|
||||
|
||||
/**
|
||||
* A single state building up part of the game. The state include rendering, logic and input handling
|
||||
* for the state.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public interface GameState extends InputListener {
|
||||
/**
|
||||
* Get the ID of this state
|
||||
*
|
||||
* @return The game unique ID of this state
|
||||
*/
|
||||
public int getID();
|
||||
|
||||
/**
|
||||
* Initialise the state. It should load any resources it needs at this stage
|
||||
*
|
||||
* @param container The container holding the game
|
||||
* @param game The game holding this state
|
||||
* @throws SlickException Indicates a failure to initialise a resource for this state
|
||||
*/
|
||||
public void init(GameContainer container, StateBasedGame game) throws SlickException;
|
||||
|
||||
/**
|
||||
* Render this state to the game's graphics context
|
||||
*
|
||||
* @param container The container holding the game
|
||||
* @param game The game holding this state
|
||||
* @param g The graphics context to render to
|
||||
* @throws SlickException Indicates a failure to render an artifact
|
||||
*/
|
||||
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException;
|
||||
|
||||
/**
|
||||
* Update the state's logic based on the amount of time thats passed
|
||||
*
|
||||
* @param container The container holding the game
|
||||
* @param game The game holding this state
|
||||
* @param delta The amount of time thats passed in millisecond since last update
|
||||
* @throws SlickException Indicates an internal error that will be reported through the
|
||||
* standard framework mechanism
|
||||
*/
|
||||
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException ;
|
||||
|
||||
/**
|
||||
* Notification that we've entered this game state
|
||||
*
|
||||
* @param container The container holding the game
|
||||
* @param game The game holding this state
|
||||
* @throws SlickException Indicates an internal error that will be reported through the
|
||||
* standard framework mechanism
|
||||
*/
|
||||
public void enter(GameContainer container, StateBasedGame game) throws SlickException;
|
||||
|
||||
/**
|
||||
* Notification that we're leaving this game state
|
||||
*
|
||||
* @param container The container holding the game
|
||||
* @param game The game holding this state
|
||||
* @throws SlickException Indicates an internal error that will be reported through the
|
||||
* standard framework mechanism
|
||||
*/
|
||||
public void leave(GameContainer container, StateBasedGame game) throws SlickException;
|
||||
}
|
||||
541
lib/slick-source/org/newdawn/slick/state/StateBasedGame.java
Normal file
541
lib/slick-source/org/newdawn/slick/state/StateBasedGame.java
Normal file
@@ -0,0 +1,541 @@
|
||||
package org.newdawn.slick.state;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.newdawn.slick.Game;
|
||||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Graphics;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.InputListener;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.state.transition.EmptyTransition;
|
||||
import org.newdawn.slick.state.transition.Transition;
|
||||
|
||||
/**
|
||||
* A state based game isolated different stages of the game (menu, ingame, hiscores, etc) into
|
||||
* different states so they can be easily managed and maintained.
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public abstract class StateBasedGame implements Game, InputListener {
|
||||
/** The list of states making up this game */
|
||||
private HashMap states = new HashMap();
|
||||
/** The current state */
|
||||
private GameState currentState;
|
||||
/** The next state we're moving into */
|
||||
private GameState nextState;
|
||||
/** The container holding this game */
|
||||
private GameContainer container;
|
||||
/** The title of the game */
|
||||
private String title;
|
||||
|
||||
/** The transition being used to enter the state */
|
||||
private Transition enterTransition;
|
||||
/** The transition being used to leave the state */
|
||||
private Transition leaveTransition;
|
||||
|
||||
/**
|
||||
* Create a new state based game
|
||||
*
|
||||
* @param name The name of the game
|
||||
*/
|
||||
public StateBasedGame(String name) {
|
||||
this.title = name;
|
||||
|
||||
currentState = new BasicGameState() {
|
||||
public int getID() {
|
||||
return -1;
|
||||
}
|
||||
public void init(GameContainer container, StateBasedGame game) throws SlickException {
|
||||
}
|
||||
public void render(StateBasedGame game, Graphics g) throws SlickException {
|
||||
}
|
||||
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
|
||||
}
|
||||
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.ControlledInputReciever#inputStarted()
|
||||
*/
|
||||
public void inputStarted() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of states that have been added to this game
|
||||
*
|
||||
* @return The number of states that have been added to this game
|
||||
*/
|
||||
public int getStateCount() {
|
||||
return states.keySet().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the state the game is currently in
|
||||
*
|
||||
* @return The ID of the state the game is currently in
|
||||
*/
|
||||
public int getCurrentStateID() {
|
||||
return currentState.getID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state the game is currently in
|
||||
*
|
||||
* @return The state the game is currently in
|
||||
*/
|
||||
public GameState getCurrentState() {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#setInput(org.newdawn.slick.Input)
|
||||
*/
|
||||
public void setInput(Input input) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a state to the game. The state will be updated and maintained
|
||||
* by the game
|
||||
*
|
||||
* @param state The state to be added
|
||||
*/
|
||||
public void addState(GameState state) {
|
||||
states.put(new Integer(state.getID()), state);
|
||||
|
||||
if (currentState.getID() == -1) {
|
||||
currentState = state;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a state based on it's identifier
|
||||
*
|
||||
* @param id The ID of the state to retrieve
|
||||
* @return The state requested or null if no state with the specified ID exists
|
||||
*/
|
||||
public GameState getState(int id) {
|
||||
return (GameState) states.get(new Integer(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter a particular game state with no transition
|
||||
*
|
||||
* @param id The ID of the state to enter
|
||||
*/
|
||||
public void enterState(int id) {
|
||||
enterState(id, new EmptyTransition(), new EmptyTransition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter a particular game state with the transitions provided
|
||||
*
|
||||
* @param id The ID of the state to enter
|
||||
* @param leave The transition to use when leaving the current state
|
||||
* @param enter The transition to use when entering the new state
|
||||
*/
|
||||
public void enterState(int id, Transition leave, Transition enter) {
|
||||
if (leave == null) {
|
||||
leave = new EmptyTransition();
|
||||
}
|
||||
if (enter == null) {
|
||||
enter = new EmptyTransition();
|
||||
}
|
||||
leaveTransition = leave;
|
||||
enterTransition = enter;
|
||||
|
||||
nextState = getState(id);
|
||||
if (nextState == null) {
|
||||
throw new RuntimeException("No game state registered with the ID: "+id);
|
||||
}
|
||||
|
||||
leaveTransition.init(currentState, nextState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
|
||||
*/
|
||||
public final void init(GameContainer container) throws SlickException {
|
||||
this.container = container;
|
||||
initStatesList(container);
|
||||
|
||||
Iterator gameStates = states.values().iterator();
|
||||
|
||||
while (gameStates.hasNext()) {
|
||||
GameState state = (GameState) gameStates.next();
|
||||
|
||||
state.init(container, this);
|
||||
}
|
||||
|
||||
if (currentState != null) {
|
||||
currentState.enter(container, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the list of states making up this game
|
||||
*
|
||||
* @param container The container holding the game
|
||||
* @throws SlickException Indicates a failure to initialise the state based game resources
|
||||
*/
|
||||
public abstract void initStatesList(GameContainer container) throws SlickException;
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
|
||||
*/
|
||||
public final void render(GameContainer container, Graphics g) throws SlickException {
|
||||
preRenderState(container, g);
|
||||
|
||||
if (leaveTransition != null) {
|
||||
leaveTransition.preRender(this, container, g);
|
||||
} else if (enterTransition != null) {
|
||||
enterTransition.preRender(this, container, g);
|
||||
}
|
||||
|
||||
currentState.render(container, this, g);
|
||||
|
||||
if (leaveTransition != null) {
|
||||
leaveTransition.postRender(this, container, g);
|
||||
} else if (enterTransition != null) {
|
||||
enterTransition.postRender(this, container, g);
|
||||
}
|
||||
|
||||
postRenderState(container, g);
|
||||
}
|
||||
|
||||
/**
|
||||
* User hook for rendering at the before the current state
|
||||
* and/or transition have been rendered
|
||||
*
|
||||
* @param container The container in which the game is hosted
|
||||
* @param g The graphics context on which to draw
|
||||
* @throws SlickException Indicates a failure within render
|
||||
*/
|
||||
protected void preRenderState(GameContainer container, Graphics g) throws SlickException {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
/**
|
||||
* User hook for rendering at the game level after the current state
|
||||
* and/or transition have been rendered
|
||||
*
|
||||
* @param container The container in which the game is hosted
|
||||
* @param g The graphics context on which to draw
|
||||
* @throws SlickException Indicates a failure within render
|
||||
*/
|
||||
protected void postRenderState(GameContainer container, Graphics g) throws SlickException {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.BasicGame#update(org.newdawn.slick.GameContainer, int)
|
||||
*/
|
||||
public final void update(GameContainer container, int delta) throws SlickException {
|
||||
preUpdateState(container, delta);
|
||||
|
||||
if (leaveTransition != null) {
|
||||
leaveTransition.update(this, container, delta);
|
||||
if (leaveTransition.isComplete()) {
|
||||
currentState.leave(container, this);
|
||||
GameState prevState = currentState;
|
||||
currentState = nextState;
|
||||
nextState = null;
|
||||
leaveTransition = null;
|
||||
currentState.enter(container, this);
|
||||
if (enterTransition != null) {
|
||||
enterTransition.init(currentState, prevState);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (enterTransition != null) {
|
||||
enterTransition.update(this, container, delta);
|
||||
if (enterTransition.isComplete()) {
|
||||
enterTransition = null;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
currentState.update(container, this, delta);
|
||||
|
||||
postUpdateState(container, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* User hook for updating at the game before the current state
|
||||
* and/or transition have been updated
|
||||
*
|
||||
* @param container The container in which the game is hosted
|
||||
* @param delta The amount of time in milliseconds since last update
|
||||
* @throws SlickException Indicates a failure within render
|
||||
*/
|
||||
protected void preUpdateState(GameContainer container, int delta) throws SlickException {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
/**
|
||||
* User hook for rendering at the game level after the current state
|
||||
* and/or transition have been updated
|
||||
*
|
||||
* @param container The container in which the game is hosted
|
||||
* @param delta The amount of time in milliseconds since last update
|
||||
* @throws SlickException Indicates a failure within render
|
||||
*/
|
||||
protected void postUpdateState(GameContainer container, int delta) throws SlickException {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the game is transitioning between states
|
||||
*
|
||||
* @return True if we're transitioning between states
|
||||
*/
|
||||
private boolean transitioning() {
|
||||
return (leaveTransition != null) || (enterTransition != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#closeRequested()
|
||||
*/
|
||||
public boolean closeRequested() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.Game#getTitle()
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the container holding this game
|
||||
*
|
||||
* @return The game container holding this game
|
||||
*/
|
||||
public GameContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerButtonPressed(int, int)
|
||||
*/
|
||||
public void controllerButtonPressed(int controller, int button) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerButtonPressed(controller, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerButtonReleased(int, int)
|
||||
*/
|
||||
public void controllerButtonReleased(int controller, int button) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerButtonReleased(controller, button);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerDownPressed(int)
|
||||
*/
|
||||
public void controllerDownPressed(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerDownPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerDownReleased(int)
|
||||
*/
|
||||
public void controllerDownReleased(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerDownReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerLeftPressed(int)
|
||||
*/
|
||||
public void controllerLeftPressed(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerLeftPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerLeftReleased(int)
|
||||
*/
|
||||
public void controllerLeftReleased(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerLeftReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerRightPressed(int)
|
||||
*/
|
||||
public void controllerRightPressed(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerRightPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerRightReleased(int)
|
||||
*/
|
||||
public void controllerRightReleased(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerRightReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerUpPressed(int)
|
||||
*/
|
||||
public void controllerUpPressed(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerUpPressed(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#controllerUpReleased(int)
|
||||
*/
|
||||
public void controllerUpReleased(int controller) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.controllerUpReleased(controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#keyPressed(int, char)
|
||||
*/
|
||||
public void keyPressed(int key, char c) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.keyPressed(key, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#keyReleased(int, char)
|
||||
*/
|
||||
public void keyReleased(int key, char c) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.keyReleased(key, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseMoved(int, int, int, int)
|
||||
*/
|
||||
public void mouseMoved(int oldx, int oldy, int newx, int newy) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.mouseMoved(oldx, oldy, newx, newy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseDragged(int, int, int, int)
|
||||
*/
|
||||
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.mouseDragged(oldx, oldy, newx, newy);
|
||||
}
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseClicked(int, int, int, int)
|
||||
*/
|
||||
public void mouseClicked(int button, int x, int y, int clickCount) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.mouseClicked(button, x, y, clickCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mousePressed(int, int, int)
|
||||
*/
|
||||
public void mousePressed(int button, int x, int y) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.mousePressed(button, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseReleased(int, int, int)
|
||||
*/
|
||||
public void mouseReleased(int button, int x, int y) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.mouseReleased(button, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#isAcceptingInput()
|
||||
*/
|
||||
public boolean isAcceptingInput() {
|
||||
if (transitioning()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return currentState.isAcceptingInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#inputEnded()
|
||||
*/
|
||||
public void inputEnded() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.newdawn.slick.InputListener#mouseWheelMoved(int)
|
||||
*/
|
||||
public void mouseWheelMoved(int newValue) {
|
||||
if (transitioning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentState.mouseWheelMoved(newValue);
|
||||
}
|
||||
|
||||
}
|
||||
5
lib/slick-source/org/newdawn/slick/state/package.html
Normal file
5
lib/slick-source/org/newdawn/slick/state/package.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<BODY>
|
||||
State based games allow the game to be broken down into the different activities the player may
|
||||
take part in, for instance menu, highscores, play and credits. However, states can be used to simply
|
||||
segregate section on the play.
|
||||
</BODY>
|
||||
@@ -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