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 booleanIndicates whether pause is possible in the current state.protected longThe latest deltaTime inIScene.logicLoop().protected SubMenuMenu that will be displayed when the game has ended.protected ParallaxContainerThe ParallaxContainer for the background.protected SubMenuMenu than will be displayed when the game is paused. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGameElement(GameElement element) Adds a GameElement to the Model.voidAdds a GuiElement to the GameModel.voidapplyToGameElements(Consumer<GameElement> function) Apply function on all game elements.voidapplyToGuiElements(Consumer<GuiElement> function) Apply function on game elements.voidapplyToNonNeutralGameElements(Consumer<GameElement> function) Apply function on game elements (non-neutral).final voidattack(boolean active) Will invoked if user wants to attack something.final voidend(boolean won) End a level.floatGet the current camera offset.intGet the amount of elements in the scene.Get a map of duration-time of elements.final LevelgetLevel()Get the associated level.final MenuItemgetMenu()Get the associated Root-MenuItem.final GameModelgetModel()Get the model of the MVC.Get the current player ofnullif none set.booleanhasEnded()Indicates whether the level has ended.voidinit()Initialize the scene.protected voidThis method will be invoked inIScene.logicLoop().final booleanThis method indicates whether the scene encapsulates a level.final booleanThis method indicates whether the offset is set to wildcard (any position is allowed / no elements will be deleted (because of their position))booleanisPaused()Indicates whether the scene is paused.final voidInvoke logic.protected voidWill be invoked after allGameElement.logicLoop().protected voidInvokeGameElement.logicLoop()for all game elements.protected voidWill be invoked before allGameElement.logicLoop().voidmarkForRemove(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 intperformEndTasks(boolean won) Perform tasks on the end of the game (level).voidRemoves a GuiElement to the GameModel.voidrestart()Restart the scene.final voidsetAttackHandler(Consumer<Boolean> handler) The handler ofIScene.attack(boolean).voidsetCameraTarget(CameraTarget cameraTarget) Set the camera target.voidsetCanPause(boolean canPause) Set whether the game can pausedfinal voidsetOffsetWildCard(boolean wildcard) Set return value ofILevelScene.isOffsetWildCard().voidsetPause(boolean pause) Set the pause state.voidstart()Start the scene.booleanToggle pause for the scene.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:ISceneInitialize 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:ISceneStart the scene. Begin drawing and Player/Enemies will begin to move. -
end
public final void end(boolean won) Description copied from interface:ILevelSceneEnd a level.- Specified by:
endin interfaceILevelScene- Parameters:
won- indicates whether successful or died
-
hasEnded
public boolean hasEnded()Description copied from interface:ILevelSceneIndicates whether the level has ended.- Specified by:
hasEndedin interfaceILevelScene- Returns:
trueif ended,falseotherwise
-
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:ISceneToggle pause for the scene. SeeIScene.setPause(boolean).- Specified by:
togglePausein interfaceIScene- Returns:
trueiff operation is possible,falseotherwise
-
restart
public void restart()Description copied from interface:ISceneRestart 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:ILevelSceneGet the current player ofnullif none set.- Specified by:
getPlayerin interfaceILevelScene- Returns:
- the current player of
null
-
getCameraOffset
public float getCameraOffset()Description copied from interface:ISceneGet the current camera offset.- Specified by:
getCameraOffsetin interfaceCameraTarget- Specified by:
getCameraOffsetin interfaceIScene- Returns:
- the current camera offset
-
setCameraTarget
Description copied from interface:ISceneSet the camera target.- Specified by:
setCameraTargetin interfaceIScene- Parameters:
cameraTarget- the camera target
-
getMenu
Description copied from interface:ISceneGet the associated Root-MenuItem.- Specified by:
getMenuin interfaceIScene- Returns:
- the root-menuItem or
nullif noScenes.MAIN_MENU
-
isLevelScene
public final boolean isLevelScene()Description copied from interface:ISceneThis method indicates whether the scene encapsulates a level.- Specified by:
isLevelScenein interfaceIScene- Returns:
trueif this scene encapsulates a level,falseotherwise
-
getLevel
Description copied from interface:ILevelSceneGet the associated level.- Specified by:
getLevelin interfaceILevelScene- Returns:
- the level
-
isOffsetWildCard
public final boolean isOffsetWildCard()Description copied from interface:ILevelSceneThis method indicates whether the offset is set to wildcard (any position is allowed / no elements will be deleted (because of their position))- Specified by:
isOffsetWildCardin interfaceILevelScene- Returns:
trueif activated,falseotherwise
-
setOffsetWildCard
public final void setOffsetWildCard(boolean wildcard) Description copied from interface:ILevelSceneSet return value ofILevelScene.isOffsetWildCard().- Specified by:
setOffsetWildCardin interfaceILevelScene- Parameters:
wildcard- the value
-
attack
public final void attack(boolean active) Description copied from interface:ISceneWill invoked if user wants to attack something. -
setAttackHandler
Description copied from interface:ISceneThe handler ofIScene.attack(boolean).- Specified by:
setAttackHandlerin interfaceIScene- Parameters:
handler- the handler ornullto reset- See Also:
-
isPaused
public boolean isPaused()Description copied from interface:ISceneIndicates whether the scene is paused. -
setPause
public void setPause(boolean pause) Description copied from interface:ISceneSet the pause state. When pause usually the logic loop Useful when resetting. -
logicLoop
public final void logicLoop()Description copied from interface:ISceneInvoke 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:
addGameElementin 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:
markForRemovein interfaceIScene- Parameters:
element- the GameElement to remove
-
addGuiElement
Adds a GuiElement to the GameModel.- Specified by:
addGuiElementin interfaceIScene- Parameters:
e- the GuiElement to add
-
removeGuiElement
Description copied from interface:ISceneRemoves a GuiElement to the GameModel.- Specified by:
removeGuiElementin interfaceIScene- Parameters:
e- the GuiElement to remove
-
applyToGameElements
Description copied from interface:ISceneApply function on all game elements.- Specified by:
applyToGameElementsin interfaceIScene- Parameters:
function- the function
-
applyToNonNeutralGameElements
Description copied from interface:ISceneApply function on game elements (non-neutral).- Specified by:
applyToNonNeutralGameElementsin interfaceIScene- Parameters:
function- the function- See Also:
-
applyToGuiElements
Description copied from interface:ISceneApply function on game elements.- Specified by:
applyToGuiElementsin interfaceIScene- Parameters:
function- the function
-
getGameElementCount
public int getGameElementCount()Description copied from interface:ISceneGet the amount of elements in the scene.- Specified by:
getGameElementCountin interfaceIScene- Returns:
- the amount of elements
-
getGameElementDurations
Description copied from interface:ISceneGet a map of duration-time of elements.- Specified by:
getGameElementDurationsin interfaceIScene- Returns:
- the duration-time of elements by class
-
getModel
Description copied from interface:ISceneGet the model of the MVC. -
setCanPause
public void setCanPause(boolean canPause) Description copied from interface:ISceneSet whether the game can paused- Specified by:
setCanPausein interfaceIScene- Parameters:
canPause-trueiff pausable
-