Package playground

Class BreakoutLevelBase

java.lang.Object
playground.Playground
playground.BreakoutLevelBase
Direct Known Subclasses:
BreakoutLevel0, BreakoutLevel1, BreakoutLevelBaseAdvanced

public abstract class BreakoutLevelBase extends Playground
  • Field Details

  • Constructor Details

    • BreakoutLevelBase

      public BreakoutLevelBase()
  • Method Details

    • gameOver

      public boolean gameOver()
      signals to game engine that the game has finished by game over. called every game loop. default implementation is always false.
      Specified by:
      gameOver in class Playground
      Returns:
      false
    • levelFinished

      public boolean levelFinished()
      signals to game engine that the game has finished by success. called every game loop. default implementation is always false.
      Specified by:
      levelFinished in class Playground
      Returns:
      false
    • resetRequested

      public boolean resetRequested()
      signals to game engine that the game has been requested to be reseted (restart). called every game loop. default implementation is always false.
      Returns:
      false
    • redrawLevel

      public void redrawLevel(Graphics2D g)
      unimplemented empty method called by game engine every loop.
      Specified by:
      redrawLevel in class Playground
      Parameters:
      g - Graphics2D abstract drawing object of java Swing, used to carry out all drawing operations.
    • preferredSizeX

      public int preferredSizeX()
      Signal that the level has a size of 700x700 pixels.
      Specified by:
      preferredSizeX in class Playground
      Returns:
      x size of level 700
    • preferredSizeY

      public int preferredSizeY()
      Signal that the level has a size of 700x700 pixels.
      Specified by:
      preferredSizeY in class Playground
      Returns:
      y size of level 700
    • actionIfBallHitsBrick

      protected abstract void actionIfBallHitsBrick(GameObject ball, GameObject brick)
      Method that gets called by applyGameLogic() whenever the ball collides with a brick.
      Parameters:
      ball - A reference to the current ball object
      brick - A reference to the ego object
    • actionIfBallHitsEgo

      protected abstract void actionIfBallHitsEgo(GameObject ball, GameObject ego)
      Method that gets called by applyGameLogic() whenever the ball collides with the ego object.
      Parameters:
      ball - A reference to the current ball object
      ego - A reference to the ego object
    • applyGameLogic

      public void applyGameLogic()
      checks for interactions between GameObjects; notably ball with ego and ball with brick. In case of detected collisions, it calls either actionIfBallHitsBrick(GameObject, GameObject) or actionIfBallHitsEgo(GameObject, GameObject). Called every game loop.
      Specified by:
      applyGameLogic in class Playground
    • createEgoObject

      protected abstract GameObject createEgoObject()
      Creates the ego object and returns it, called by prepareLevel(java.lang.String). Does NOT add the ego object to the playground, but returns it.
      Returns:
      The created ego object instance (of class RectObject with EgoController.
    • createBall

      protected abstract GameObject createBall()
      Creates the ball object and returns it, called by #prepareLevel. Does NOT add the ball object to the playground, but returns it.
      Returns:
      The created ball object instance (of class FallingStar)
    • createBrick

      protected abstract GameObject createBrick(int row, int column)
      Creates the GameObject (RectObject) instance representing a single brick at a certain grid position. The brick is NOT added here, but returned.
      Parameters:
      row - row position in the grid, ranges from 0 to calcNrBricksY()-1
      column - column position in the grid of bricks, ranges from 0 to calcNrBricksX()-1
      Returns:
      The GameObject instance (really a RectObject) representing the created brick.
    • prepareLevel

      public abstract void prepareLevel(String level)
      Prepares a generic Breakout-Type level. This method relies on the methods createEgoObject(), createBall() and createBrick(int, int), among others, which are meant to be overwritten in subclasses.
      Attention: the attributes ball and ego need to be set properly to GameObject instances when implementing this method prepareLevel(String).
      Specified by:
      prepareLevel in class Playground
      Parameters:
      level - String passes by the game engine (not used currently and can be ignored).