public abstract class CellGame
extends java.lang.Object
A CellGame is a game made with Cell2D. A certain number of times per second, a CellGame executes a frame, in which it processes input, updates the logic of the game, and renders visuals.
A CellGame has one or more CellGameStates, each with a non-negative integer ID that is unique within the CellGame. A CellGame is in exactly one of these CellGameStates at any given time, and can transition between them. Each CellGameState has its own actions to take every frame and in response to specific events, but it only takes these actions while the CellGame is in that state and it is thus active. If a CellGameState is created with an ID that another CellGameState of the same CellGame already has, the old CellGameState is replaced and can no longer be entered.
A CellGame renders visuals on a rectangular grid of pixels called its screen. Points on the screen have x-coordinates that increase from left to right, as well as y-coordinates that increase from top to bottom. The dimensions of the screen are not necessarily the same as the dimensions of the CellGame's program window, as the screen may be scaled to different apparent sizes using the CellGame's scale factor. A CellGame may be displayed in windowed or fullscreen mode.
While a CellGame is rendering visuals, the region of the Graphics context to which it is rendering that is outside its screen cannot be drawn to. When drawn to the Graphics context, shapes and Drawables will automatically be clipped so that they do not extend beyond the screen.
A CellGame processes input in the form of a fixed number of binary commands, numbered from 0 to getNumCommands() - 1 inclusive, as well as the position of the mouse cursor on the screen and the movement of the mouse wheel. Slick2D objects called Controls, which represent keys, mouse buttons, controller buttons, etc. may be bound to at most one command at a time so that when they are pressed, held, and released, so too are the commands to which they are bound. A CellGame also allows for the temporary processing of input as assignments of Controls to specific commands, or as the typing of text to a specific String.
A CellGame also controls the playing, looping, stopping, pausing, and fading of Music tracks. It contains a data structure called a music stack in which Music tracks may be assigned to different integer priority values. Only the Music track with the greatest priority will play; all others will be paused. If the currently playing Music track finishes, it will automatically be removed from the music stack and the Music track with the next greatest priority will begin playing.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
VERSION
The version number of Cell2D, currently 1.4.0.
|
Constructor and Description |
---|
CellGame(java.lang.String gamename,
int numCommands,
int fps,
int screenWidth,
int screenHeight,
double scaleFactor,
boolean fullscreen,
java.lang.String loadingImagePath)
Creates a new CellGame.
|
Modifier and Type | Method and Description |
---|---|
void |
beginTypingString(int maxLength)
Instructs this CellGame to interpret all inputs as typing a String with a
specified maximum length until further notice.
|
void |
beginTypingString(java.lang.String initialString,
int maxLength)
Instructs this CellGame to interpret all inputs as typing a String with a
specified initial value and maximum length until further notice.
|
void |
bindControl(int command,
org.newdawn.slick.command.Control control)
Binds the specified control to the specified command.
|
void |
cancelBindToCommand()
Cancels this CellGame's instruction to bind the next valid control
pressed to a specified command, if it has been instructed to do so.
|
void |
cancelTypingString()
Instructs this CellGame to stop interpreting inputs as typing a String,
if it was doing so, and consider the typing canceled.
|
void |
clearControls(int command)
Unbinds all of the specified command's controls from it.
|
void |
close()
Instructs this CellGame to close itself the next time it finishes a game
logic update.
|
boolean |
commandHeld(int command)
Returns whether the specified command is being held this frame.
|
boolean |
commandPressed(int command)
Returns whether the specified command was pressed this frame; that is,
whether it transitioned from not being held to being held.
|
boolean |
commandReleased(int command)
Returns whether the specified command was released this frame; that is,
whether it transitioned from being held to not being held.
|
void |
enterState(int id)
Instructs this CellGame to enter its CellGameState with the specified ID
at the end of the current frame.
|
void |
enterState(int id,
org.newdawn.slick.state.transition.Transition leave,
org.newdawn.slick.state.transition.Transition enter)
Instructs this CellGame to enter its CellGameState with the specified ID,
using the specified Transitions when leaving the current CellGameState
and entering the new one, at the end of the current frame.
|
void |
fadeMusicOut(double duration)
Instructs the music player to gradually fade the volume of the currently
playing music track to 0 over the specified duration, stopping the Music
track once it is silent, if a Music track is currently playing.
|
void |
fadeMusicVolume(double volume,
double duration)
Instructs the music player to gradually fade the volume of the currently
playing Music track to the specified volume over the specified duration,
if a Music track is currently playing.
|
void |
finishTypingString()
Instructs this CellGame to stop interpreting inputs as typing a String,
if it was doing so, and consider the String finished.
|
int |
getBindingCommand()
Returns the number of the command to which this CellGame has been
instructed to bind the next valid control pressed, or -1 if there is
none.
|
java.util.List<org.newdawn.slick.command.Control> |
getControlsFor(int command)
Returns all of the Controls that are bound to the specified command.
|
Music |
getCurrentMusic()
Returns the Music track that this CellGame is currently playing, or null
if there is none.
|
CellGameState |
getCurrentState()
Returns the CellGameState that this CellGame is currently in - in other
words, this CellGame's only active CellGameState.
|
int |
getCurrentStateID()
Returns the ID of this CellGame's current CellGameState.
|
int |
getFPS()
Returns the number of frames that this CellGame executes per second.
|
int |
getMouseWheelChange()
Returns the change in the position of the mouse wheel since last frame.
|
int |
getMouseX()
Returns the x-coordinate in pixels of the mouse cursor on this CellGame's
screen.
|
int |
getMouseY()
Returns the y-coordinate in pixels of the mouse cursor on this CellGame's
screen.
|
Music |
getMusic(int priority)
Returns the Music track in this CellGame's music stack at the specified
priority, or null if there is none.
|
double |
getMusicPosition()
Returns the music player's position in seconds in the currently playing
Music track, or 0 if no Music track is currently playing.
|
double |
getMusicVolume()
Returns the volume of the currently playing Music track, with 1
representing no volume change, or 0 if there is no Music track playing.
|
int |
getNumCommands()
Returns how many commands this CellGame has.
|
double |
getScaleFactor()
Returns the factor by which this CellGame's screen is scaled to make the
size of the program window.
|
int |
getScreenHeight()
Returns the height in pixels of this CellGame's screen.
|
int |
getScreenWidth()
Returns the width in pixels of this CellGame's screen.
|
CellGameState |
getState(int id)
Returns this CellGame's CellGameState with the specified ID, or null if
there is none.
|
java.lang.String |
getTypingString()
Returns the String that this CellGame is being used to type, or null if
there is none.
|
abstract void |
initActions()
Actions for this CellGame to take when initializing itself before
entering its first state.
|
boolean |
isFullscreen()
Returns whether this CellGame is in fullscreen mode.
|
static void |
loadNatives(java.lang.String path)
Loads the native libraries that are necessary for LWJGL 2, and thus
Slick2D, and thus Cell2D, to run.
|
void |
loopMusic(int priority,
Music music)
Loops the specified Music track indefinitely in this CellGame's music
stack at the specified priority.
|
void |
loopMusic(int priority,
Music music,
double pitch,
double volume)
Loops the specified Music track indefinitely in this CellGame's music
stack at the specified priority, pitch, and volume.
|
void |
loopMusic(Music music)
Loops the specified Music track indefinitely.
|
void |
loopMusic(Music music,
double pitch,
double volume)
Loops the specified Music track indefinitely at the specified pitch and
volume.
|
boolean |
musicIsPaused()
Returns whether this CellGame's music is paused.
|
void |
pauseMusic()
Pauses this CellGame's music if it is not already paused.
|
void |
playMusic(int priority,
Music music)
Plays the specified Music track once in this CellGame's music stack at
the specified priority.
|
void |
playMusic(int priority,
Music music,
double pitch,
double volume)
Plays the specified Music track once in this CellGame's music stack at
the specified priority, pitch, and volume.
|
void |
playMusic(Music music)
Plays the specified Music track once.
|
void |
playMusic(Music music,
double pitch,
double volume)
Plays the specified Music track once at the specified pitch and volume.
|
void |
renderActions(org.newdawn.slick.Graphics g,
int x1,
int y1,
int x2,
int y2)
Actions for this CellGame to take each frame to render visuals after its
current CellGameState has finished rendering.
|
void |
resumeMusic()
Resumes this CellGame's music if it is paused.
|
void |
setFPS(int fps)
Sets the number of frames that this CellGame executes per second to the
specified value.
|
void |
setFullscreen(boolean fullscreen)
Sets whether this CellGame is in fullscreen mode.
|
void |
setMusicPosition(double position)
Sets the music player's position in seconds in the currently playing
Music track, if there is one.
|
void |
setMusicVolume(double volume)
Sets the volume of the currently playing Music track, with 1 representing
no volume change, if a Music track is currently playing.
|
void |
setScaleFactor(double scaleFactor)
Sets the factor by which this CellGame's screen is scaled to make the
size of the program window to the specified value.
|
void |
setScreenHeight(int screenHeight)
Sets the height in pixels of this CellGame's screen to the specified
value.
|
void |
setScreenWidth(int screenWidth)
Sets the width in pixels of this CellGame's screen to the specified
value.
|
static void |
startGame(CellGame game)
Starts a CellGame.
|
void |
stopMusic()
Stops the Music track that this CellGame is currently playing, if there
is one.
|
void |
stopMusic(int priority)
Stops the Music track in this CellGame's music stack at the specified
priority, if there is one.
|
void |
stopMusic(int priority,
Music music)
Stops the specified Music track in this CellGame's music stack at the
specified priority if it is currently playing there.
|
void |
stopMusic(Music music)
Stops the specified Music track if this CellGame is currently playing it.
|
void |
unbindControl(org.newdawn.slick.command.Control control)
Unbinds the specified control from its command, if it is bound to one.
|
void |
waitToBindToCommand(int command)
Instructs this CellGame to bind the next valid control pressed to the
specified command.
|
public static final java.lang.String VERSION
public CellGame(java.lang.String gamename, int numCommands, int fps, int screenWidth, int screenHeight, double scaleFactor, boolean fullscreen, java.lang.String loadingImagePath)
gamename
- The name of this CellGame as seen on its program windownumCommands
- The total number of input commands that this CellGame
needs to keep track offps
- The number of frames that this CellGame will execute every
secondscreenWidth
- The initial width of this CellGame's screen in pixelsscreenHeight
- The initial height of this CellGame's screen in
pixelsscaleFactor
- The initial factor by which the screen should be
scaled to make the size of the program windowfullscreen
- Whether this CellGame should start in fullscreen modeloadingImagePath
- The relative path to the image that this CellGame
will display while loading before the first CellGameState is entered. If
this is null, no loading image will be displayed.public static final void loadNatives(java.lang.String path)
path
- The relative path to the folder containing the native
librariespublic static final void startGame(CellGame game)
game
- The CellGame to startpublic final void close()
public final CellGameState getState(int id)
id
- The ID of the CellGameState to returnpublic final CellGameState getCurrentState()
public final int getCurrentStateID()
public final void enterState(int id)
id
- The ID of the CellGameState to enterpublic final void enterState(int id, org.newdawn.slick.state.transition.Transition leave, org.newdawn.slick.state.transition.Transition enter)
id
- The ID of the CellGameState to enterleave
- The Transition to use when leaving the current CellGameStateenter
- The Transition to use when entering the new CellGameStatepublic abstract void initActions()
public void renderActions(org.newdawn.slick.Graphics g, int x1, int y1, int x2, int y2)
g
- The Graphics context to which this CellGame is rendering its
visuals this framex1
- The x-coordinate in pixels of the screen's left edge on the
Graphics contexty1
- The y-coordinate in pixels of the screen's top edge on the
Graphics contextx2
- The x-coordinate in pixels of the screen's right edge on the
screen on the Graphics contexty2
- The y-coordinate in pixels of the screen's bottom edge on the
Graphics contextpublic final int getNumCommands()
public final java.util.List<org.newdawn.slick.command.Control> getControlsFor(int command)
command
- The number of the command whose controls are to be
returnedpublic final void bindControl(int command, org.newdawn.slick.command.Control control)
command
- The command to bind the specified control tocontrol
- The control to bind to the specified commandpublic final void unbindControl(org.newdawn.slick.command.Control control)
control
- The control to be unboundpublic final void clearControls(int command)
command
- The number of the command whose controls are to be unboundpublic final int getBindingCommand()
public final void waitToBindToCommand(int command)
command
- The number of the command to which the next valid control
pressed should be boundpublic final void cancelBindToCommand()
public final boolean commandPressed(int command)
command
- The command to examinepublic final boolean commandHeld(int command)
command
- The command to examinepublic final boolean commandReleased(int command)
command
- The command to examinepublic final int getMouseX()
public final int getMouseY()
public final int getMouseWheelChange()
public final java.lang.String getTypingString()
public final void beginTypingString(int maxLength)
maxLength
- The maximum length in characters of the String to be
typedpublic final void beginTypingString(java.lang.String initialString, int maxLength)
initialString
- The initial value of the String to be typedmaxLength
- The maximum length in characters of the String to be
typedpublic final void finishTypingString()
public final void cancelTypingString()
public final int getFPS()
public final void setFPS(int fps)
fps
- The value to which the number of frames per second will be setpublic final int getScreenWidth()
public final void setScreenWidth(int screenWidth)
screenWidth
- The value to which the screen width will be setpublic final int getScreenHeight()
public final void setScreenHeight(int screenHeight)
screenHeight
- The value to which the screen height will be setpublic final double getScaleFactor()
public final void setScaleFactor(double scaleFactor)
scaleFactor
- The value to which the scale factor will be setpublic final boolean isFullscreen()
public final void setFullscreen(boolean fullscreen)
fullscreen
- Whether this CellGame should be in fullscreen modepublic final Music getCurrentMusic()
public final Music getMusic(int priority)
priority
- The priority of the Music track to returnpublic final void playMusic(Music music)
music
- The Music track to playpublic final void playMusic(Music music, double pitch, double volume)
music
- The Music track to playpitch
- The pitch at which to play the specified Music track, with 1
representing no pitch changevolume
- The volume at which to play the specified Music track, with
1 representing no volume changepublic final void playMusic(int priority, Music music)
priority
- The priority at which to play the specified Music trackmusic
- The Music track to playpublic final void playMusic(int priority, Music music, double pitch, double volume)
priority
- The priority at which to play the specified Music trackmusic
- The Music track to playpitch
- The pitch at which to play the specified Music track, with 1
representing no pitch changevolume
- The volume at which to play the specified Music track, with
1 representing no volume changepublic final void loopMusic(Music music)
music
- The Music track to looppublic final void loopMusic(Music music, double pitch, double volume)
music
- The Music track to looppitch
- The pitch at which to play the specified Music track, with 1
representing no pitch changevolume
- The volume at which to play the specified Music track, with
1 representing no volume changepublic final void loopMusic(int priority, Music music)
priority
- The priority at which to play the specified Music trackmusic
- The Music track to looppublic final void loopMusic(int priority, Music music, double pitch, double volume)
priority
- The priority at which to play the specified Music trackmusic
- The Music track to looppitch
- The pitch at which to play the specified Music track, with 1
representing no pitch changevolume
- The volume at which to play the specified Music track, with
1 representing no volume changepublic final void stopMusic()
public final void stopMusic(Music music)
music
- The Music track to be stoppedpublic final void stopMusic(int priority)
priority
- The priority of the Music track to be stoppedpublic final void stopMusic(int priority, Music music)
priority
- The priority of the Music track to be stoppedmusic
- The Music track to be stoppedpublic final boolean musicIsPaused()
public final void pauseMusic()
public final void resumeMusic()
public final double getMusicPosition()
public final void setMusicPosition(double position)
position
- The music player's new position in secondspublic final double getMusicVolume()
public final void setMusicVolume(double volume)
volume
- The volume of the currently playing Music trackpublic final void fadeMusicVolume(double volume, double duration)
volume
- The eventual volume of the Music trackduration
- The duration in seconds of the fadepublic final void fadeMusicOut(double duration)
duration
- The duration in seconds of the fade-out