Class LevelScene

java.lang.Object
rekit.logic.scene.LevelScene
All Implemented Interfaces:
CameraTarget, ILevelScene, IScene

public abstract class LevelScene extends Object implements ILevelScene
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 Details

    • pauseMenu

      protected SubMenu pauseMenu
      Menu than will be displayed when the game is paused.
    • endMenu

      protected SubMenu 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

      protected ParallaxContainer parallax
      The ParallaxContainer for the background.
    • canPause

      protected boolean canPause
      Indicates whether pause is possible in the current state.
    • deltaTime

      protected long deltaTime
      The latest deltaTime in IScene.logicLoop().
  • Constructor Details

    • LevelScene

      public LevelScene(GameModel model, Level level)
      Create a new LevelScene.
      Parameters:
      model - the model
      level - 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.
      Specified by:
      init in interface IScene
    • start

      public void start()
      Description copied from interface: IScene
      Start the scene. Begin drawing and Player/Enemies will begin to move.
      Specified by:
      start in interface IScene
    • end

      public final void end(boolean won)
      Description copied from interface: ILevelScene
      End a level.
      Specified by:
      end in interface ILevelScene
      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 interface ILevelScene
      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. See IScene.setPause(boolean).
      Specified by:
      togglePause in interface IScene
      Returns:
      true iff operation is possible, false otherwise
    • restart

      public void restart()
      Description copied from interface: IScene
      Restart the scene.
      Specified by:
      restart in interface IScene
    • logicLoopPre

      protected void logicLoopPre()
      Will be invoked before all GameElement.logicLoop().
    • logicLoopAfter

      protected void logicLoopAfter()
      Will be invoked after all GameElement.logicLoop().
    • getPlayer

      public Player getPlayer()
      Description copied from interface: ILevelScene
      Get the current player of null if none set.
      Specified by:
      getPlayer in interface ILevelScene
      Returns:
      the current player of null
    • getCameraOffset

      public float getCameraOffset()
      Description copied from interface: IScene
      Get the current camera offset.
      Specified by:
      getCameraOffset in interface CameraTarget
      Specified by:
      getCameraOffset in interface IScene
      Returns:
      the current camera offset
    • setCameraTarget

      public void setCameraTarget(CameraTarget cameraTarget)
      Description copied from interface: IScene
      Set the camera target.
      Specified by:
      setCameraTarget in interface IScene
      Parameters:
      cameraTarget - the camera target
    • getMenu

      public final MenuItem getMenu()
      Description copied from interface: IScene
      Get the associated Root-MenuItem.
      Specified by:
      getMenu in interface IScene
      Returns:
      the root-menuItem or null if no Scenes.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 interface IScene
      Returns:
      true if this scene encapsulates a level, false otherwise
    • getLevel

      public final Level getLevel()
      Description copied from interface: ILevelScene
      Get the associated level.
      Specified by:
      getLevel in interface ILevelScene
      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 interface ILevelScene
      Returns:
      true if activated, false otherwise
    • setOffsetWildCard

      public final void setOffsetWildCard(boolean wildcard)
      Description copied from interface: ILevelScene
      Set return value of ILevelScene.isOffsetWildCard().
      Specified by:
      setOffsetWildCard in interface ILevelScene
      Parameters:
      wildcard - the value
    • attack

      public final void attack(boolean active)
      Description copied from interface: IScene
      Will invoked if user wants to attack something.
      Specified by:
      attack in interface IScene
      Parameters:
      active - indicates whether attack is active or not (this means that the Attack-Key is pressed or not)
      See Also:
    • setAttackHandler

      public final void setAttackHandler(Consumer<Boolean> handler)
      Description copied from interface: IScene
      The handler of IScene.attack(boolean).
      Specified by:
      setAttackHandler in interface IScene
      Parameters:
      handler - the handler or null to reset
      See Also:
    • isPaused

      public boolean isPaused()
      Description copied from interface: IScene
      Indicates whether the scene is paused.
      Specified by:
      isPaused in interface IScene
      Returns:
      true if paused, false otherwise
    • setPause

      public void setPause(boolean pause)
      Description copied from interface: IScene
      Set the pause state. When pause usually the logic loop Useful when resetting.
      Specified by:
      setPause in interface IScene
      Parameters:
      pause - the new pause state
    • logicLoop

      public final void logicLoop()
      Description copied from interface: IScene
      Invoke logic.
      Specified by:
      logicLoop in interface IScene
    • innerLogicLoop

      protected void innerLogicLoop()
      This method will be invoked in IScene.logicLoop().
    • logicLoopGameElement

      protected void logicLoopGameElement(GameElement e)
      Invoke GameElement.logicLoop() for all game elements.
      Parameters:
      e - the elements
    • addGameElement

      public void addGameElement(GameElement element)
      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 interface IScene
      Parameters:
      element - the GameElement to add
    • markForRemove

      public 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. 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 interface IScene
      Parameters:
      element - the GameElement to remove
    • addGuiElement

      public void addGuiElement(GuiElement e)
      Adds a GuiElement to the GameModel.
      Specified by:
      addGuiElement in interface IScene
      Parameters:
      e - the GuiElement to add
    • removeGuiElement

      public void removeGuiElement(GuiElement e)
      Description copied from interface: IScene
      Removes a GuiElement to the GameModel.
      Specified by:
      removeGuiElement in interface IScene
      Parameters:
      e - the GuiElement to remove
    • applyToGameElements

      public void applyToGameElements(Consumer<GameElement> function)
      Description copied from interface: IScene
      Apply function on all game elements.
      Specified by:
      applyToGameElements in interface IScene
      Parameters:
      function - the function
    • applyToNonNeutralGameElements

      public void applyToNonNeutralGameElements(Consumer<GameElement> function)
      Description copied from interface: IScene
      Apply function on game elements (non-neutral).
      Specified by:
      applyToNonNeutralGameElements in interface IScene
      Parameters:
      function - the function
      See Also:
    • applyToGuiElements

      public void applyToGuiElements(Consumer<GuiElement> function)
      Description copied from interface: IScene
      Apply function on game elements.
      Specified by:
      applyToGuiElements in interface IScene
      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 interface IScene
      Returns:
      the amount of elements
    • getGameElementDurations

      public Map<String,Long> getGameElementDurations()
      Description copied from interface: IScene
      Get a map of duration-time of elements.
      Specified by:
      getGameElementDurations in interface IScene
      Returns:
      the duration-time of elements by class
    • getModel

      public final GameModel getModel()
      Description copied from interface: IScene
      Get the model of the MVC.
      Specified by:
      getModel in interface IScene
      Returns:
      the model
    • setCanPause

      public void setCanPause(boolean canPause)
      Description copied from interface: IScene
      Set whether the game can paused
      Specified by:
      setCanPause in interface IScene
      Parameters:
      canPause - true iff pausable