T
- The subclass of CellGame that uses this CellGameStateU
- The subclass of CellGameState that this CellGameState isV
- The subclass of Thinker that this CellGameState usespublic abstract class CellGameState<T extends CellGame,U extends CellGameState<T,U,V>,V extends Thinker<T,U,V>> extends ThinkerGroup<T,U,V>
A CellGameState represents one state that a CellGame can be in, such as the main menu, the options menu, in the middle of a level, etc. CellGameStates are permanent parts of a specific CellGame and referenced by a specific non-negative integer ID, both of which are specified upon the CellGameState's creation.
A CellGameState has its own actions to take every time its CellGame executes a 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.
AnimationInstances may be assigned to one CellGameState each. An AnimationInstance may be assigned to a CellGameState with or without an integer ID in the context of that CellGameState. Only one AnimationInstance may be assigned to a given CellGameState with a given ID at once.
A CellGameState is also a ThinkerGroup, which means that Thinkers may be directly assigned to one CellGameState each.
The CellGameState class is intended to be directly extended by classes U that extend CellGameState<T,U,V> and interact with Thinkers of class V. BasicGameState is an example of such a class. This allows a CellGameState's Thinkers to interact with it in ways unique to its subclass of CellGameState.
Constructor and Description |
---|
CellGameState(T game,
int id)
Creates a new CellGameState of the specified CellGame with the specified
ID.
|
Modifier and Type | Method and Description |
---|---|
AnimationInstance |
addAnimInstance(Animation animation)
Adds a new AnimationInstance of the specified Animation to this
CellGameState.
|
boolean |
addAnimInstance(AnimationInstance instance)
Adds the specified AnimationInstance to this CellGameState if it is not
already assigned to a CellGameState.
|
void |
addThinkerActions(T game,
V thinker)
Actions for this CellGameState to take immediately after adding a Thinker
to itself.
|
void |
addThinkerActions(V thinker)
Actions for this ThinkerGroup to take immediately after adding a Thinker
to itself, before the Thinker takes its addedActions().
|
void |
bindFinishedActions(T game,
int commandNum)
Actions for this CellGameState to take immediately after its CellGame has
bound the last valid control pressed to a specified command.
|
void |
charDeletedActions(T game,
char c)
Actions for this CellGameState to take immediately after a character is
deleted from its CellGame's typed String.
|
void |
charTypedActions(T game,
char c)
Actions for this CellGameState to take immediately after a character is
typed to its CellGame's typed String.
|
void |
clearAnimInstances()
Removes from this CellGameState all AnimationInstances that are currently
assigned to it, with or without IDs.
|
void |
enteredActions(T game)
Actions for this CellGameState to take immediately after being entered.
|
void |
frameActions(T game)
Actions for this CellGameState to take once every frame, after all of its
Thinkers have taken their timeUnitActions() but before they take their
frameActions().
|
Animation |
getAnimation(int id)
Returns the Animation of the AnimationInstance assigned to this
CellGameState with the specified ID, if there is one.
|
AnimationInstance |
getAnimInstance(int id)
Returns the AnimationInstance that is assigned to this CellGameState with
the specified ID.
|
T |
getGame()
Returns the CellGame to which this CellGameState belongs.
|
int |
getID()
Returns this CellGameState's ID.
|
int |
getNumAnimInstances()
Returns the number of AnimationInstances that are assigned to this
CellGameState.
|
abstract U |
getThis()
A method which returns this CellGameState as a U, rather than as a
CellGameState<T,U,V>.
|
long |
getTimeFactor()
Returns this CellGameState's time factor; that is, the average number of
discrete time units it experiences every frame.
|
boolean |
isActive()
Returns whether this CellGameState is active - that is, whether its
CellGame is currently in this state.
|
void |
leftActions(T game)
Actions for this CellGameState to take immediately before being exited.
|
boolean |
removeAnimInstance(AnimationInstance instance)
Removes the specified AnimationInstance from this CellGameState if it
is currently assigned to this CellGameState.
|
void |
removeThinkerActions(T game,
V thinker)
Actions for this CellGameState to take immediately before removing a
Thinker from itself.
|
void |
removeThinkerActions(V thinker)
Actions for this ThinkerGroup to take immediately before removing a
Thinker from itself, after the Thinker takes its removedActions().
|
void |
renderActions(T game,
org.newdawn.slick.Graphics g,
int x1,
int y1,
int x2,
int y2)
Actions for this CellGameState to take each frame to render its visuals.
|
AnimationInstance |
setAnimation(int id,
Animation animation)
Sets the AnimationInstance that is assigned to this CellGameState with
the specified ID to a new AnimationInstance of the specified Animation,
if there is not already an AnimationInstance of that Animation assigned
with that ID.
|
boolean |
setAnimInstance(int id,
AnimationInstance instance)
Sets the AnimationInstance that is assigned to this CellGameState with
the specified ID to the specified AnimationInstance, if it is not already
assigned to a CellGameState.
|
void |
setTimeFactor(long timeFactor)
Sets this CellGameState's time factor to the specified value.
|
void |
stringBeganActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame
begins typing a new String.
|
void |
stringCanceledActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame's
typed String is canceled.
|
void |
stringDeletedActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame's
typed String is deleted and reset to the empty String.
|
void |
stringFinishedActions(T game,
java.lang.String s)
Actions for this CellGameState to take immediately after its CellGame's
typed String is finished.
|
addThinker, getNumThinkers, iteratingThroughThinkers, removeAllSubThinkers, removeAllThinkers, removeLineage, removeThinker, thinkerIterator, updateThinkerListActions
public CellGameState(T game, int id)
game
- The CellGame to which this CellGameState belongsid
- This CellGameState's IDpublic abstract U getThis()
public final T getGame()
public final int getID()
public final boolean isActive()
public final long getTimeFactor()
public final void setTimeFactor(long timeFactor)
timeFactor
- The new time factorpublic final int getNumAnimInstances()
public final boolean addAnimInstance(AnimationInstance instance)
instance
- The AnimationInstance to addpublic final AnimationInstance addAnimInstance(Animation animation)
animation
- The Animation to add a new AnimationInstance ofpublic final boolean removeAnimInstance(AnimationInstance instance)
instance
- The AnimationInstance to removepublic final AnimationInstance getAnimInstance(int id)
id
- The ID of the AnimationInstance to be returnedpublic final boolean setAnimInstance(int id, AnimationInstance instance)
id
- The ID with which to assign the specified AnimationInstanceinstance
- The AnimationInstance to add with the specified IDpublic final Animation getAnimation(int id)
id
- The ID of the AnimationInstance whose Animation is to be
returnedpublic final AnimationInstance setAnimation(int id, Animation animation)
id
- The ID with which to assign the new AnimationInstanceanimation
- The Animation to add a new AnimationInstance ofpublic final void clearAnimInstances()
public void enteredActions(T game)
game
- This CellGameState's CellGamepublic void leftActions(T game)
game
- This CellGameState's CellGamepublic final void addThinkerActions(V thinker)
ThinkerGroup
addThinkerActions
in class ThinkerGroup<T extends CellGame,U extends CellGameState<T,U,V>,V extends Thinker<T,U,V>>
thinker
- The Thinker that was addedpublic final void addThinkerActions(T game, V thinker)
game
- This CellGameState's CellGamethinker
- The Thinker that was addedpublic final void removeThinkerActions(V thinker)
ThinkerGroup
removeThinkerActions
in class ThinkerGroup<T extends CellGame,U extends CellGameState<T,U,V>,V extends Thinker<T,U,V>>
thinker
- The Thinker that is about to be removedpublic final void removeThinkerActions(T game, V thinker)
game
- This CellGameState's CellGamethinker
- The Thinker that is about to be removedpublic void frameActions(T game)
game
- This CellGameState's CellGamepublic void renderActions(T game, org.newdawn.slick.Graphics g, int x1, int y1, int x2, int y2)
game
- This CellGameState's CellGameg
- The Graphics context to which this CellGameState 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 void bindFinishedActions(T game, int commandNum)
game
- This CellGameState's CellGamecommandNum
- The number of the command that was bound topublic void stringBeganActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The initial value of the typed Stringpublic void charTypedActions(T game, char c)
game
- This CellGameState's CellGamec
- The character that was just typedpublic void charDeletedActions(T game, char c)
game
- This CellGameState's CellGamec
- The character that was just deletedpublic void stringDeletedActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The String that was just deletedpublic void stringFinishedActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The String that was just finishedpublic void stringCanceledActions(T game, java.lang.String s)
game
- This CellGameState's CellGames
- The String that was just canceled