vooga.engine.state
Class GameState

java.lang.Object
  extended by vooga.engine.state.GameState
Direct Known Subclasses:
BasicTextGameState, ConfigState, EndGameState, EndGameState, ExampleState1, ExampleState2, GameEndState, GameEndState, GameOverState, GameOverState, GamePlayState, GamePlayState, HelpState, LoadState, MainGameState, MainMenu, MainMenuState, Menu, MenuGameState, MenuState, MenuState, MenuState, MenuState, NetworkMenuState, PauseGameState, PauseState, PauseState, PauseState, PlayGameState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayState, PlayStateControlExample, PreferencesState, SetLevelState, SetNumMatchesState, TheirTurnState, TronGamePauseState, TronGamePlayState, WaitingState

public abstract class GameState
extends java.lang.Object

GameState is, at its most basic conception, a container class for collections of sprites. Beyond that, it should be used to control state-specific behavior that defines those sprites. For example, the mainGameState should include all of the sprites necessary to play the game in both the render and update groups. The mainGameState, when set to active, will then iterate through those sprites and render and update them appropriately. Additional behavior can be called in the gameState' render or update methods to provide high-level functionality (i.e. functionality to be preserved across the entire gameState, not a specific level). GameStates show their power most of all when changing states. As an example, take the change from a mainGameState into a pausedGameState. The pausedGameState could be constructed using the mainGameState's sprites as render-only sprites, effectively "freezing" the action by no longer updating those sprites. A menu could then be added as rendered+updated sprites, displayed over the "frozen" action. Returning to the main game flow is as simple as toggling back to the mainGameState.


Field Summary
protected  java.util.Collection<PlayField> myRenderField
           
protected  java.util.Collection<PlayField> myUpdateField
           
 
Constructor Summary
GameState()
          Constructs a new GameState play
GameState(GameState gamestate)
          Constructs a new GameState using another GameState as the base.
GameState(PlayField playfield)
          Creates a new GameState from a Playfield by placing all SpriteGroups in render and update groups.
 
Method Summary
 void activate()
          Sets the GameState to active.
 void addGroup(SpriteGroup group)
           
 void addPlayField(PlayField playfield)
          Adds a playfield to an rendered and updated in an existing GameState
 void addRenderPlayField(PlayField playfield)
          Adds a playfield to an rendered in an existing GameState
 void addRenderState(GameState gamestate)
          Adds the contents of an existing GameState to the current state's renderGroups.
 void addState(GameState gamestate)
          Adds the contents of an existing GameState to the current state's render and updateGroups.
 void addUpdatePlayField(PlayField playfield)
          Adds a playfield to an updated in an existing GameState
 void addUpdateState(GameState gamestate)
          Adds the contents of an existing GameState to the current state's updateGroups.
 void deactivate()
          Sets the GameState to inactive.
 boolean equals(java.lang.Object obj)
          Equals function for GameStates
 SpriteGroup getGroup(java.lang.String name)
          Get a SpriteGroup out of the GameState if it exists.
 java.util.Collection<PlayField> getRenderField()
          Returns the GameState's renderGroups.
 java.util.Collection<PlayField> getUpdateField()
          Returns the GameState's updateGroups.
abstract  void initialize()
          The initialize method sets up specific variables and parameters necessary to the specific functioning of the GameState.
 boolean isActive()
          Returns the boolean value of the GameState's active variable.
 void removeEverything()
          Clears the GameState of all contents.
 void render(java.awt.Graphics2D g)
          Renders all sprites stored in the GameState's renderGroups.
 void update(long t)
          Updates all sprites stored in the GameState' updateGroups.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myRenderField

protected java.util.Collection<PlayField> myRenderField

myUpdateField

protected java.util.Collection<PlayField> myUpdateField
Constructor Detail

GameState

public GameState()
Constructs a new GameState play


GameState

public GameState(GameState gamestate)
Constructs a new GameState using another GameState as the base.

Parameters:
gamestate -

GameState

public GameState(PlayField playfield)
Creates a new GameState from a Playfield by placing all SpriteGroups in render and update groups.

Parameters:
playfield -
Method Detail

activate

public void activate()
Sets the GameState to active. Active GameStates are rendered and updated in the main game loop.


deactivate

public void deactivate()
Sets the GameState to inactive. Inactive GameStates are not rendered and updated in the main game loop.


initialize

public abstract void initialize()
The initialize method sets up specific variables and parameters necessary to the specific functioning of the GameState. This should include all of the necessary initialization for the GameState's specific use, rather than anything broadly required for all GameStates.


isActive

public boolean isActive()
Returns the boolean value of the GameState's active variable.

Returns:
boolean

render

public void render(java.awt.Graphics2D g)
Renders all sprites stored in the GameState's renderGroups.

Parameters:
g -

update

public void update(long t)
Updates all sprites stored in the GameState' updateGroups.

Parameters:
t -

getRenderField

public java.util.Collection<PlayField> getRenderField()
Returns the GameState's renderGroups.

Returns:
List

getUpdateField

public java.util.Collection<PlayField> getUpdateField()
Returns the GameState's updateGroups.

Returns:
List

addRenderState

public void addRenderState(GameState gamestate)
Adds the contents of an existing GameState to the current state's renderGroups.

Parameters:
gamestate -

addUpdateState

public void addUpdateState(GameState gamestate)
Adds the contents of an existing GameState to the current state's updateGroups.

Parameters:
gamestate -

addState

public void addState(GameState gamestate)
Adds the contents of an existing GameState to the current state's render and updateGroups.

Parameters:
gamestate -

addPlayField

public void addPlayField(PlayField playfield)
Adds a playfield to an rendered and updated in an existing GameState

Parameters:
playfield - to be rendered and updated

addRenderPlayField

public void addRenderPlayField(PlayField playfield)
Adds a playfield to an rendered in an existing GameState

Parameters:
playfield - to be rendered

addUpdatePlayField

public void addUpdatePlayField(PlayField playfield)
Adds a playfield to an updated in an existing GameState

Parameters:
playfield - to be updated

removeEverything

public void removeEverything()
Clears the GameState of all contents.


getGroup

public SpriteGroup getGroup(java.lang.String name)
Get a SpriteGroup out of the GameState if it exists. If it does not exist than this method will return null

Parameters:
name - the name of the SpriteGroup
Returns:
SpriteGroup with that name

addGroup

public void addGroup(SpriteGroup group)

equals

public boolean equals(java.lang.Object obj)
Equals function for GameStates

Overrides:
equals in class java.lang.Object
Parameters:
Object -
Returns:
boolean