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.Screen
ThePlayScreen
class represents a screen which is shown after the game starts, implementingScreen
interface. It manages the various game cameras, theCharacter
, and theArea
vector which the player can explore. All assets for the game are preloaded whenPlayScreen
is constructed.- Author:
- ENG1 Team 23 (Cohort 3)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PlayScreen.GameState
Distinguish between internal game states; used to inform, among others, therender(float)
} andhandleInput()
cycles
-
Field Summary
Fields Modifier and Type Field Description private Area
activeArea
TheArea
subject to world collision, interaction, and renderingprivate java.util.Map<Area.Name,Area>
areas
private com.badlogic.gdx.graphics.g2d.SpriteBatch
batch
TheSpriteBatch
associated with the parentalGame
instanceprivate Character
character
The player-controlledSprite
that is tracked by the game cameraprivate static Area.Name
DEFAULT_AREA
private com.badlogic.gdx.graphics.OrthographicCamera
gameCam
TheOrthographicCamera
associated with the parentalGame
instanceprivate Overlay
gameOverMenu
TheOverlay
rendered upon game completionprivate Overlay
hud
The persistent heads-up displayOverlay
presenting real-time metric information to the playerprivate MetricController
metricController
TheMetricController
stores and provides means of manipulating and updatingMetricController.Metric
valuesprivate Overlay
pauseMenu
The transient-rendered pause menuOverlay
, intended to be displayed to the user upon request, or a system event such as loss ofPlayScreen
focusprivate PlayScreen.GameState
state
Stores the transientPlayScreen.GameState
being experienced by the player in thePlayScreen
private com.badlogic.gdx.utils.viewport.Viewport
viewport
The renderViewport
associated with the parentalGame
-
Constructor Summary
Constructors Constructor Description PlayScreen(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
Instantiates a newPlayScreen
to be used for the playing area of the game.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceDay()
Advances the day, or finishes the game as appropriate.void
dispose()
Releases all resources used by thePlayScreen
private void
handleInput()
Handles user system events, such as key-presses.void
hide()
Handles thePlayScreen
being hiddenprivate void
initialiseAreas()
Initialise the playArea
svoid
pause()
Handles thePlayScreen
, and hence general gameplay execution, being pausedvoid
render(float delta)
Handles the graphical rendering obligations of theScreen
.void
resize(int width, int height)
Handles thePlayScreen
being resizedvoid
resume()
Handles thePlayScreen
, and hence general gameplay execution, being resumedvoid
show()
Handles thePlayScreen
becoming the activeScreen
; currently a placeholdervoid
switchArea(Area.Name areaName)
private void
togglePaused()
Toggle thestate
such that the game is paused or resumed, unless the game is overprivate void
update()
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.GameState
being experienced by the player in thePlayScreen
-
gameCam
private final com.badlogic.gdx.graphics.OrthographicCamera gameCam
TheOrthographicCamera
associated with the parentalGame
instance
-
batch
private final com.badlogic.gdx.graphics.g2d.SpriteBatch batch
TheSpriteBatch
associated with the parentalGame
instance
-
viewport
private final com.badlogic.gdx.utils.viewport.Viewport viewport
The renderViewport
associated with the parentalGame
-
character
private final Character character
The player-controlledSprite
that is tracked by the game camera- See Also:
Character
,OrthographicCamera
-
hud
private final Overlay hud
The persistent heads-up displayOverlay
presenting 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 ofPlayScreen
focus- See Also:
PlayScreen.GameState.GAME_PAUSED
-
gameOverMenu
private final Overlay gameOverMenu
TheOverlay
rendered upon game completion- See Also:
PlayScreen.GameState.GAME_OVER
-
activeArea
private Area activeArea
TheArea
subject to world collision, interaction, and rendering- See Also:
Area.step()
,update()
,render(float)
-
metricController
private final MetricController metricController
TheMetricController
stores and provides means of manipulating and updatingMetricController.Metric
values- See Also:
MetricListener
,MetricUpdater
-
-
Constructor Detail
-
PlayScreen
PlayScreen(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) throws InvalidAreaException
Instantiates a newPlayScreen
to 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 LibGDXSpriteBatch
to use for batch object rendering- Throws:
InvalidAreaException
- At least oneArea
required by thePlayScreen
could not be properly instantiated by theAreaFactory
-
-
Method Detail
-
initialiseAreas
private void initialiseAreas() throws InvalidAreaException
Initialise the playArea
s- 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 thePlayScreen
being resized- Specified by:
resize
in interfacecom.badlogic.gdx.Screen
- Parameters:
width
- The new width, in pixelsheight
- The new height, in pixels
-
show
public void show()
Handles thePlayScreen
becoming the activeScreen
; currently a placeholder- Specified by:
show
in interfacecom.badlogic.gdx.Screen
- See Also:
hide()
-
hide
public void hide()
Handles thePlayScreen
being hidden- Specified by:
hide
in 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:
resume
in interfacecom.badlogic.gdx.Screen
- See Also:
pause()
-
togglePaused
private void togglePaused()
Toggle thestate
such 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.Sleep
is 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:
dispose
in interfacecom.badlogic.gdx.Screen
-
render
public void render(float delta)
-
-