Package playground
Class BreakoutLevelBase
java.lang.Object
playground.Playground
playground.BreakoutLevelBase
- Direct Known Subclasses:
BreakoutLevel0
,BreakoutLevel1
,BreakoutLevelBaseAdvanced
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GameObject
instance of the ball, needs to be set byprepareLevel(String)
protected GameObject
instance of the ball, needs to be set byprepareLevel(String)
Fields inherited from class playground.Playground
addables, canvasX, canvasY, flags, FLAGS_ALL, FLAGS_GLOBAL, FLAGS_LEVEL, gameObjects, gameTime, keyEvents, level, mouseEvents, pausedFlag, removables, timeStep
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
actionIfBallHitsBrick
(GameObject ball, GameObject brick) Method that gets called by applyGameLogic() whenever the ball collides with a brick.protected abstract void
actionIfBallHitsEgo
(GameObject ball, GameObject ego) Method that gets called by applyGameLogic() whenever the ball collides with the ego object.void
checks for interactions between GameObjects; notably ball with ego and ball with brick.protected abstract GameObject
Creates the ball object and returns it, called by #prepareLevel.protected abstract GameObject
createBrick
(int row, int column) Creates the GameObject (RectObject) instance representing a single brick at a certain grid position.protected abstract GameObject
Creates the ego object and returns it, called byprepareLevel(java.lang.String)
.boolean
gameOver()
signals to game engine that the game has finished by game over. called every game loop. default implementation is always false.boolean
signals to game engine that the game has finished by success. called every game loop. default implementation is always false.int
Signal that the level has a size of 700x700 pixels.int
Signal that the level has a size of 700x700 pixels.abstract void
prepareLevel
(String level) Prepares a generic Breakout-Type level.void
unimplemented empty method called by game engine every loop.boolean
signals to game engine that the game has been requested to be reseted (restart). called every game loop. default implementation is always false.Methods inherited from class playground.Playground
addObject, addObjectNow, collectObjects, deleteObject, deleteObjectNow, getGameTime, getGlobalFlag, getKeyEvents, getLevelFlag, getMouseEvents, getObject, getOrCreateGlobalFlag, getOrCreateLevelFlag, getSizeX, getSizeY, getTimestep, isPaused, processKeyEvents, processMouseEvents, redraw, reset, resetFlags, setGameTime, setGlobalFlag, setLevelFlag, setPaused, setTimestep, togglePause, updateObjects
-
Field Details
-
ball
instance of the ball, needs to be set byprepareLevel(String)
-
ego
instance of the ball, needs to be set byprepareLevel(String)
-
-
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 classPlayground
- 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 classPlayground
- 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
unimplemented empty method called by game engine every loop.- Specified by:
redrawLevel
in classPlayground
- 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 classPlayground
- Returns:
- x size of level 700
-
preferredSizeY
public int preferredSizeY()Signal that the level has a size of 700x700 pixels.- Specified by:
preferredSizeY
in classPlayground
- Returns:
- y size of level 700
-
actionIfBallHitsBrick
Method that gets called by applyGameLogic() whenever the ball collides with a brick.- Parameters:
ball
- A reference to the current ball objectbrick
- A reference to the ego object
-
actionIfBallHitsEgo
Method that gets called by applyGameLogic() whenever the ball collides with the ego object.- Parameters:
ball
- A reference to the current ball objectego
- 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 eitheractionIfBallHitsBrick(GameObject, GameObject)
oractionIfBallHitsEgo(GameObject, GameObject)
. Called every game loop.- Specified by:
applyGameLogic
in classPlayground
-
createEgoObject
Creates the ego object and returns it, called byprepareLevel(java.lang.String)
. Does NOT add the ego object to the playground, but returns it.- Returns:
- The created ego object instance (of class
RectObject
withEgoController
.
-
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
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()-1column
- 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
Prepares a generic Breakout-Type level. This method relies on the methodscreateEgoObject()
,createBall()
andcreateBrick(int, int)
, among others, which are meant to be overwritten in subclasses.
Attention: the attributesball
andego
need to be set properly to GameObject instances when implementing this methodprepareLevel(String)
.- Specified by:
prepareLevel
in classPlayground
- Parameters:
level
- String passes by the game engine (not used currently and can be ignored).
-