Package bytemusketeers.heslingtonhustle
Class PlayScreen
- java.lang.Object
-
- bytemusketeers.heslingtonhustle.PlayScreen
-
- All Implemented Interfaces:
com.badlogic.gdx.Screen
public class PlayScreen extends java.lang.Object implements com.badlogic.gdx.ScreenThePlayScreenclass represents a screen which is shown after the game starts, implementingScreeninterface. It manages the various game cameras, theCharacter, and theAreavector which the player can explore. All assets for the game are preloaded whenPlayScreenis constructed.- Author:
- ENG1 Team 23 (Cohort 3)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPlayScreen.GameStateDistinguish between internal game states; used to inform, among others, therender(float)} andhandleInput()cycles
-
Field Summary
Fields Modifier and Type Field Description private AreaactiveAreaTheAreasubject to world collision, interaction, and renderingprivate java.util.Map<Area.Name,Area>areasprivate com.badlogic.gdx.graphics.g2d.SpriteBatchbatchTheSpriteBatchassociated with the parentalGameinstanceprivate CharactercharacterThe player-controlledSpritethat is tracked by the game cameraprivate static Area.NameDEFAULT_AREAprivate com.badlogic.gdx.graphics.OrthographicCameragameCamTheOrthographicCameraassociated with the parentalGameinstanceprivate OverlaygameOverMenuTheOverlayrendered upon game completionprivate OverlayhudThe persistent heads-up displayOverlaypresenting real-time metric information to the playerprivate MetricControllermetricControllerTheMetricControllerstores and provides means of manipulating and updatingMetricController.Metricvaluesprivate OverlaypauseMenuThe transient-rendered pause menuOverlay, intended to be displayed to the user upon request, or a system event such as loss ofPlayScreenfocusprivate PlayScreen.GameStatestateStores the transientPlayScreen.GameStatebeing experienced by the player in thePlayScreenprivate com.badlogic.gdx.utils.viewport.ViewportviewportThe renderViewportassociated with the parentalGame
-
Constructor Summary
Constructors Constructor Description PlayScreen(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)Instantiates a newPlayScreento be used for the playing area of the game.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadvanceDay()Advances the day, or finishes the game as appropriate.voiddispose()Releases all resources used by thePlayScreenprivate voidhandleInput()Handles user system events, such as key-presses.voidhide()Handles thePlayScreenbeing hiddenprivate voidinitialiseAreas()Initialise the playAreasvoidpause()Handles thePlayScreen, and hence general gameplay execution, being pausedvoidrender(float delta)Handles the graphical rendering obligations of theScreen.voidresize(int width, int height)Handles thePlayScreenbeing resizedvoidresume()Handles thePlayScreen, and hence general gameplay execution, being resumedvoidshow()Handles thePlayScreenbecoming the activeScreen; currently a placeholdervoidswitchArea(Area.Name areaName)private voidtogglePaused()Toggle thestatesuch that the game is paused or resumed, unless the game is overprivate voidupdate()Handles the game logic and updates the state of the game world
-
-
-
Field Detail
-
DEFAULT_AREA
private static final Area.Name DEFAULT_AREA
-
state
private PlayScreen.GameState state
Stores the transientPlayScreen.GameStatebeing experienced by the player in thePlayScreen
-
gameCam
private final com.badlogic.gdx.graphics.OrthographicCamera gameCam
TheOrthographicCameraassociated with the parentalGameinstance
-
batch
private final com.badlogic.gdx.graphics.g2d.SpriteBatch batch
TheSpriteBatchassociated with the parentalGameinstance
-
viewport
private final com.badlogic.gdx.utils.viewport.Viewport viewport
The renderViewportassociated with the parentalGame
-
character
private final Character character
The player-controlledSpritethat is tracked by the game camera- See Also:
Character,OrthographicCamera
-
hud
private final Overlay hud
The persistent heads-up displayOverlaypresenting real-time metric information to the player- See Also:
MetricController,MetricController.Metric
-
pauseMenu
private final Overlay pauseMenu
The transient-rendered pause menuOverlay, intended to be displayed to the user upon request, or a system event such as loss ofPlayScreenfocus- See Also:
PlayScreen.GameState.GAME_PAUSED
-
gameOverMenu
private final Overlay gameOverMenu
TheOverlayrendered upon game completion- See Also:
PlayScreen.GameState.GAME_OVER
-
activeArea
private Area activeArea
TheAreasubject to world collision, interaction, and rendering- See Also:
Area.step(),update(),render(float)
-
metricController
private final MetricController metricController
TheMetricControllerstores and provides means of manipulating and updatingMetricController.Metricvalues- See Also:
MetricListener,MetricUpdater
-
-
Constructor Detail
-
PlayScreen
PlayScreen(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) throws InvalidAreaExceptionInstantiates a newPlayScreento be used for the playing area of the game. This constructor loads all assets for all stages of the playing area, to be manipulated and rendered when required.- Parameters:
batch- The LibGDXSpriteBatchto use for batch object rendering- Throws:
InvalidAreaException- At least oneArearequired by thePlayScreencould not be properly instantiated by theAreaFactory
-
-
Method Detail
-
initialiseAreas
private void initialiseAreas() throws InvalidAreaExceptionInitialise the playAreas- Throws:
InvalidAreaException- See Also:
Area,AreaFactory
-
handleInput
private void handleInput()
Handles user system events, such as key-presses.
-
update
private void update()
Handles the game logic and updates the state of the game world
-
resize
public void resize(int width, int height)Handles thePlayScreenbeing resized- Specified by:
resizein interfacecom.badlogic.gdx.Screen- Parameters:
width- The new width, in pixelsheight- The new height, in pixels
-
show
public void show()
Handles thePlayScreenbecoming the activeScreen; currently a placeholder- Specified by:
showin interfacecom.badlogic.gdx.Screen- See Also:
hide()
-
hide
public void hide()
Handles thePlayScreenbeing hidden- Specified by:
hidein interfacecom.badlogic.gdx.Screen- See Also:
show()
-
pause
public void pause()
Handles thePlayScreen, and hence general gameplay execution, being paused
-
resume
public void resume()
Handles thePlayScreen, and hence general gameplay execution, being resumed- Specified by:
resumein interfacecom.badlogic.gdx.Screen- See Also:
pause()
-
togglePaused
private void togglePaused()
Toggle thestatesuch that the game is paused or resumed, unless the game is over- See Also:
PlayScreen.GameState
-
switchArea
public void switchArea(Area.Name areaName)
-
advanceDay
public void advanceDay()
Advances the day, or finishes the game as appropriate. TheMetricController.Metric.Sleepis always incremented, since the game is over after the final sleep, on the morning of the exam!
-
dispose
public void dispose()
Releases all resources used by thePlayScreen- Specified by:
disposein interfacecom.badlogic.gdx.Screen
-
render
public void render(float delta)
-
-