Package playground

Class SpaceInvadersLevel

java.lang.Object
playground.Playground
playground.SpaceInvadersLevel
Direct Known Subclasses:
Level1, Level2, Level3, Level4, Level5, Level6, Level7, LevelBoss, LevelHitTwice, LevelWithBox

public class SpaceInvadersLevel extends Playground
Class that realizes all the game logic of a very simple game level. The level contains for now only two objects that are GameObject subclasses: FallingStar and EgoObject. Functions performed by this class are:
  • initially set up the level, spawn all object etc., in method prepareLevel(java.lang.String)
  • React to game events in actionIfEgoCollidesWithCollect(GameObject, GameObject) , actionIfEgoCollidesWithEnemy(GameObject, GameObject), etc.
  • define basic object movement rules for all objects in the level in the various ObjectController subclasses: EgoController and FallingStarController.
  • Field Details

  • Constructor Details

    • SpaceInvadersLevel

      public SpaceInvadersLevel()
  • Method Details

    • prepareLevel

      public void prepareLevel(String id)
      initially sets up the level. Not called by user interaction, but called every time a layer is restarted from scratch. So make sure that this is possible. Here, resources are loaded only once even if method is called several times.
      Specified by:
      prepareLevel in class Playground
      Parameters:
      id - String identifies level.
    • redrawLevel

      public void redrawLevel(Graphics2D g2)
      (re)draws the level but NOT the objects, they draw themselves. Called by the main game loop. This method mainly draws the background and the scoreboard.
      Specified by:
      redrawLevel in class Playground
      Parameters:
      g2 - Graphics2D object that can, and should be, draw on.
    • applyGameLogic

      public void applyGameLogic()
      applies the logic of the level: For now, this is just about deleting shots that are leaving the screen and calling methods 'actionIf..' in case objects collide.
      Specified by:
      applyGameLogic in class Playground
    • gameOver

      public boolean gameOver()
      Specified by:
      gameOver in class Playground
    • levelFinished

      public boolean levelFinished()
      Specified by:
      levelFinished in class Playground
    • preferredSizeX

      public int preferredSizeX()
      calculates and returns the preferred size of the level (in pixel) for X-direction
      Specified by:
      preferredSizeX in class Playground
    • preferredSizeY

      public int preferredSizeY()
      calculates and returns the preferred size of the level (in pixel) for Y-direction
      Specified by:
      preferredSizeY in class Playground