Package rekit.logic.scene
Class LevelScene
java.lang.Object
rekit.logic.scene.LevelScene
- All Implemented Interfaces:
CameraTarget
,ILevelScene
,IScene
Scene that holds a playable Level created by a LevelCreator. Different Levels
are possible by changing the LevelCreator in the constructor.
- Author:
- Matthias Schmitt
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Indicates whether pause is possible in the current state.protected long
The latest deltaTime inIScene.logicLoop()
.protected SubMenu
Menu that will be displayed when the game has ended.protected ParallaxContainer
The ParallaxContainer for the background.protected SubMenu
Menu than will be displayed when the game is paused. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addGameElement
(GameElement element) Adds a GameElement to the Model.void
Adds a GuiElement to the GameModel.void
applyToGameElements
(Consumer<GameElement> function) Apply function on all game elements.void
applyToGuiElements
(Consumer<GuiElement> function) Apply function on game elements.void
applyToNonNeutralGameElements
(Consumer<GameElement> function) Apply function on game elements (non-neutral).final void
attack
(boolean active) Will invoked if user wants to attack something.final void
end
(boolean won) End a level.float
Get the current camera offset.int
Get the amount of elements in the scene.Get a map of duration-time of elements.final Level
getLevel()
Get the associated level.final MenuItem
getMenu()
Get the associated Root-MenuItem.final GameModel
getModel()
Get the model of the MVC.Get the current player ofnull
if none set.boolean
hasEnded()
Indicates whether the level has ended.void
init()
Initialize the scene.protected void
This method will be invoked inIScene.logicLoop()
.final boolean
This method indicates whether the scene encapsulates a level.final boolean
This method indicates whether the offset is set to wildcard (any position is allowed / no elements will be deleted (because of their position))boolean
isPaused()
Indicates whether the scene is paused.final void
Invoke logic.protected void
Will be invoked after allGameElement.logicLoop()
.protected void
InvokeGameElement.logicLoop()
for all game elements.protected void
Will be invoked before allGameElement.logicLoop()
.void
markForRemove
(GameElement element) Removes a GameElement from the Model The elements will not directly be removed from the internal data structure to prevent concurrency errors.protected int
performEndTasks
(boolean won) Perform tasks on the end of the game (level).void
Removes a GuiElement to the GameModel.void
restart()
Restart the scene.final void
setAttackHandler
(Consumer<Boolean> handler) The handler ofIScene.attack(boolean)
.void
setCameraTarget
(CameraTarget cameraTarget) Set the camera target.void
setCanPause
(boolean canPause) Set whether the game can pausedfinal void
setOffsetWildCard
(boolean wildcard) Set return value ofILevelScene.isOffsetWildCard()
.void
setPause
(boolean pause) Set the pause state.void
start()
Start the scene.boolean
Toggle pause for the scene.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface rekit.logic.IScene
addGameElement, addGuiElement, applyToGameElements, applyToGuiElements, applyToNonNeutralGameElements, getGameElementCount, getGameElementDurations, getModel, isPaused, logicLoop, markForRemove, removeGuiElement, setCanPause, setPause
-
Field Details
-
pauseMenu
Menu than will be displayed when the game is paused. -
endMenu
Menu that will be displayed when the game has ended. Shows options dependent on whether the player won or lost and whether its an arcade level or not. -
parallax
The ParallaxContainer for the background. -
canPause
protected boolean canPauseIndicates whether pause is possible in the current state. -
deltaTime
protected long deltaTimeThe latest deltaTime inIScene.logicLoop()
.
-
-
Constructor Details
-
LevelScene
Create a new LevelScene.- Parameters:
model
- the modellevel
- the level
-
-
Method Details
-
init
public void init()Description copied from interface:IScene
Initialize the scene. e.g. build Level/GUI so Scene is ready to be drawn Must be called on restart. -
start
public void start()Description copied from interface:IScene
Start the scene. Begin drawing and Player/Enemies will begin to move. -
end
public final void end(boolean won) Description copied from interface:ILevelScene
End a level.- Specified by:
end
in interfaceILevelScene
- Parameters:
won
- indicates whether successful or died
-
hasEnded
public boolean hasEnded()Description copied from interface:ILevelScene
Indicates whether the level has ended.- Specified by:
hasEnded
in interfaceILevelScene
- Returns:
true
if ended,false
otherwise
-
performEndTasks
protected int performEndTasks(boolean won) Perform tasks on the end of the game (level).- Parameters:
won
- indicates whether successful or died- Returns:
- delay delay (in ms) when to show the end menu. on -1 the endMenu will not be shown.
-
togglePause
public boolean togglePause()Description copied from interface:IScene
Toggle pause for the scene. SeeIScene.setPause(boolean)
.- Specified by:
togglePause
in interfaceIScene
- Returns:
true
iff operation is possible,false
otherwise
-
restart
public void restart()Description copied from interface:IScene
Restart the scene. -
logicLoopPre
protected void logicLoopPre()Will be invoked before allGameElement.logicLoop()
. -
logicLoopAfter
protected void logicLoopAfter()Will be invoked after allGameElement.logicLoop()
. -
getPlayer
Description copied from interface:ILevelScene
Get the current player ofnull
if none set.- Specified by:
getPlayer
in interfaceILevelScene
- Returns:
- the current player of
null
-
getCameraOffset
public float getCameraOffset()Description copied from interface:IScene
Get the current camera offset.- Specified by:
getCameraOffset
in interfaceCameraTarget
- Specified by:
getCameraOffset
in interfaceIScene
- Returns:
- the current camera offset
-
setCameraTarget
Description copied from interface:IScene
Set the camera target.- Specified by:
setCameraTarget
in interfaceIScene
- Parameters:
cameraTarget
- the camera target
-
getMenu
Description copied from interface:IScene
Get the associated Root-MenuItem.- Specified by:
getMenu
in interfaceIScene
- Returns:
- the root-menuItem or
null
if noScenes.MAIN_MENU
-
isLevelScene
public final boolean isLevelScene()Description copied from interface:IScene
This method indicates whether the scene encapsulates a level.- Specified by:
isLevelScene
in interfaceIScene
- Returns:
true
if this scene encapsulates a level,false
otherwise
-
getLevel
Description copied from interface:ILevelScene
Get the associated level.- Specified by:
getLevel
in interfaceILevelScene
- Returns:
- the level
-
isOffsetWildCard
public final boolean isOffsetWildCard()Description copied from interface:ILevelScene
This method indicates whether the offset is set to wildcard (any position is allowed / no elements will be deleted (because of their position))- Specified by:
isOffsetWildCard
in interfaceILevelScene
- Returns:
true
if activated,false
otherwise
-
setOffsetWildCard
public final void setOffsetWildCard(boolean wildcard) Description copied from interface:ILevelScene
Set return value ofILevelScene.isOffsetWildCard()
.- Specified by:
setOffsetWildCard
in interfaceILevelScene
- Parameters:
wildcard
- the value
-
attack
public final void attack(boolean active) Description copied from interface:IScene
Will invoked if user wants to attack something. -
setAttackHandler
Description copied from interface:IScene
The handler ofIScene.attack(boolean)
.- Specified by:
setAttackHandler
in interfaceIScene
- Parameters:
handler
- the handler ornull
to reset- See Also:
-
isPaused
public boolean isPaused()Description copied from interface:IScene
Indicates whether the scene is paused. -
setPause
public void setPause(boolean pause) Description copied from interface:IScene
Set the pause state. When pause usually the logic loop Useful when resetting. -
logicLoop
public final void logicLoop()Description copied from interface:IScene
Invoke logic. -
innerLogicLoop
protected void innerLogicLoop()This method will be invoked inIScene.logicLoop()
. -
logicLoopGameElement
InvokeGameElement.logicLoop()
for all game elements.- Parameters:
e
- the elements
-
addGameElement
Adds a GameElement to the Model. The elements will not directly be added to the internal data structure to prevent concurrency errors. Instead there is an internal list to hold all waiting GameElements that will be added in the next call of logicLoop- Specified by:
addGameElement
in interfaceIScene
- Parameters:
element
- the GameElement to add
-
markForRemove
Removes a GameElement from the Model The elements will not directly be removed from the internal data structure to prevent concurrency errors. Instead there is an internal list to hold all waiting GameElements that will be removed in the next call of logicLoop- Specified by:
markForRemove
in interfaceIScene
- Parameters:
element
- the GameElement to remove
-
addGuiElement
Adds a GuiElement to the GameModel.- Specified by:
addGuiElement
in interfaceIScene
- Parameters:
e
- the GuiElement to add
-
removeGuiElement
Description copied from interface:IScene
Removes a GuiElement to the GameModel.- Specified by:
removeGuiElement
in interfaceIScene
- Parameters:
e
- the GuiElement to remove
-
applyToGameElements
Description copied from interface:IScene
Apply function on all game elements.- Specified by:
applyToGameElements
in interfaceIScene
- Parameters:
function
- the function
-
applyToNonNeutralGameElements
Description copied from interface:IScene
Apply function on game elements (non-neutral).- Specified by:
applyToNonNeutralGameElements
in interfaceIScene
- Parameters:
function
- the function- See Also:
-
applyToGuiElements
Description copied from interface:IScene
Apply function on game elements.- Specified by:
applyToGuiElements
in interfaceIScene
- Parameters:
function
- the function
-
getGameElementCount
public int getGameElementCount()Description copied from interface:IScene
Get the amount of elements in the scene.- Specified by:
getGameElementCount
in interfaceIScene
- Returns:
- the amount of elements
-
getGameElementDurations
Description copied from interface:IScene
Get a map of duration-time of elements.- Specified by:
getGameElementDurations
in interfaceIScene
- Returns:
- the duration-time of elements by class
-
getModel
Description copied from interface:IScene
Get the model of the MVC. -
setCanPause
public void setCanPause(boolean canPause) Description copied from interface:IScene
Set whether the game can paused- Specified by:
setCanPause
in interfaceIScene
- Parameters:
canPause
-true
iff pausable
-