T
- The type of CellGame that uses this GameStateU
- The type of GameState that this GameState is for SubThinker
interaction purposesV
- The type of SubThinker that can be assigned to this GameStatepublic abstract class GameState<T extends CellGame,U extends GameState<T,U,V>,V extends SubThinker<T,U,V>> extends Thinker<T,U,V>
A GameState represents one state that a CellGame can be in, such as the main menu, the options menu, in the middle of a level, etc. GameStates are permanent parts of a specific CellGame and referenced by a specific non-negative integer ID, both of which are specified upon the GameState's creation. If a CellGame is in a GameState, that GameState is considered active.
A GameState is also a Thinker that is considered assigned to itself. This means that it has timers, frameActions(), frame events, etc. If its time factor is negative, a GameState will use a time factor of one fracunit. A GameState will take its frameActions() immediately after all Thinkers have experienced all of their time units for that frame, first among the Thinkers assigned to it.
AnimationInstances may be assigned to one GameState each. An AnimationInstance may be assigned to a GameState with or without an integer ID in the context of that GameState. Only one AnimationInstance may be assigned to a given GameState with a given ID at once.
The GameState class is intended to be extended by classes U that extend GameState<T,U,V> and interact with SubThinkers of class V. BasicState is an example of such a class. This allows a GameState's SubThinkers to interact with it in ways unique to its subclass of GameState.
CellGame
,
AnimationInstance
Constructor and Description |
---|
GameState(java.lang.Class<T> gameClass,
java.lang.Class<U> stateClass,
java.lang.Class<V> subThinkerClass,
T game,
int id)
Constructs a GameState 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 GameState
without an ID.
|
boolean |
addAnimInstance(AnimationInstance instance)
Adds the specified AnimationInstance to this GameState without an ID, if
it is not already assigned to a GameState.
|
void |
bindFinishedActions(T game,
int commandNum)
Actions for this GameState 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 GameState to take immediately after a character is
deleted from its CellGame's typed String.
|
void |
charTypedActions(T game,
char c)
Actions for this GameState to take immediately after a character is typed
to its CellGame's typed String.
|
void |
clearAnimInstances()
Removes from this GameState all AnimationInstances that are currently
assigned to it, with or without IDs.
|
void |
enteredActions(T game)
Actions for this GameState to take immediately after being entered.
|
Animation |
getAnimation(int id)
Returns the Animation of the AnimationInstance assigned to this GameState
with the specified ID, or Animation.BLANK if there is none.
|
AnimationInstance |
getAnimInstance(int id)
Returns the AnimationInstance that is assigned to this GameState with the
specified ID, or AnimationInstance.BLANK if there is none.
|
long |
getEffectiveTimeFactor()
Returns this Thinker's effective time factor; that is, the average number
of time units it experiences every frame.
|
T |
getGame()
Returns the CellGame of the GameState to which this Thinker is assigned,
or null if it is not assigned to a GameState.
|
U |
getGameState()
Returns the GameState to which this Thinker is assigned, or null if it is
not assigned to one.
|
int |
getID()
Returns this GameState's ID.
|
int |
getNumAnimInstances()
Returns the number of AnimationInstances that are assigned to this
GameState, with or without IDs.
|
U |
getThis()
Returns this GameState as a U, rather than as a GameState<T,U,V>.
|
boolean |
isActive()
Returns whether this GameState is active.
|
void |
leftActions(T game)
Actions for this GameState to take immediately before being exited.
|
boolean |
removeAnimInstance(AnimationInstance instance)
Removes the specified AnimationInstance from this GameState if it is
currently assigned to this GameState without an ID.
|
void |
renderActions(T game,
Graphics g,
int x1,
int y1,
int x2,
int y2)
Actions for this GameState to take each frame to render its visuals.
|
AnimationInstance |
setAnimation(int id,
Animation animation)
Sets the AnimationInstance that is assigned to this GameState 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 GameState with the
specified ID to the specified AnimationInstance, if it is not already
assigned to a GameState.
|
void |
stringBeganActions(T game,
java.lang.String s)
Actions for this GameState to take immediately after its CellGame
begins typing a new String.
|
void |
stringCanceledActions(T game,
java.lang.String s)
Actions for this GameState to take immediately after its CellGame's typed
String is canceled.
|
void |
stringDeletedActions(T game,
java.lang.String s)
Actions for this GameState 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 GameState to take immediately after its CellGame's typed
String is finished.
|
addSubThinker, addSubThinkerActions, clearLineages, clearSubThinkers, frameActions, getFrameEvents, getGameClass, getNumSubThinkers, getStateClass, getSubThinkerClass, getTimeFactor, getTimerValue, iteratingThroughSubThinkers, removeLineage, removeSubThinker, removeSubThinkerActions, setTimeFactor, setTimerValue, subThinkerIterator
public GameState(java.lang.Class<T> gameClass, java.lang.Class<U> stateClass, java.lang.Class<V> subThinkerClass, T game, int id)
gameClass
- The Class object representing the type of CellGame that
uses this GameStatestateClass
- The Class object representing the type of GameState
that this GameState is for SubThinker interaction purposessubThinkerClass
- The Class object representing the type of
SubThinker that can be assigned to this GameStategame
- The CellGame to which this GameState belongsid
- This GameState's IDpublic final U getThis()
public final T getGame()
Thinker
public final U getGameState()
Thinker
public final long getEffectiveTimeFactor()
Thinker
public final int getID()
public final boolean isActive()
public 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 GameState's CellGamepublic void leftActions(T game)
game
- This GameState's CellGamepublic void renderActions(T game, Graphics g, int x1, int y1, int x2, int y2)
game
- This GameState's CellGameg
- The Graphics context to which this GameState 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 GameState's CellGamecommandNum
- The number of the command that was bound topublic void stringBeganActions(T game, java.lang.String s)
game
- This GameState's CellGames
- The initial value of the typed Stringpublic void charTypedActions(T game, char c)
game
- This GameState's CellGamec
- The character that was just typedpublic void charDeletedActions(T game, char c)
game
- This GameState's CellGamec
- The character that was just deletedpublic void stringDeletedActions(T game, java.lang.String s)
game
- This GameState's CellGames
- The String that was just deletedpublic void stringFinishedActions(T game, java.lang.String s)
game
- This GameState's CellGames
- The String that was just finishedpublic void stringCanceledActions(T game, java.lang.String s)
game
- This GameState's CellGames
- The String that was just canceled