Package playground
Class SpaceInvadersLevel
java.lang.Object
playground.Playground
playground.SpaceInvadersLevel
- Direct Known Subclasses:
Level1
,Level2
,Level3
,Level4
,LevelBoss
,LevelHitTwice
,LevelMovingHitObjects
,LevelMovingObjects
,LevelWithBox
,SpaceInvadersLevelAua
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
andFallingStarController
.
-
Field Summary
Fields inherited from class playground.Playground
FLAGS_ALL, FLAGS_GLOBAL, FLAGS_LEVEL
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.boolean
gameOver()
boolean
int
calculates and returns the preferred size of the level (in pixel) for X-directionint
calculates and returns the preferred size of the level (in pixel) for Y-directionvoid
prepareLevel
(String id) initially sets up the level.void
(re)draws the level but NOT the objects, they draw themselves.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
-
SHOTSPEED
public static final double SHOTSPEED- See Also:
-
EGOSPEED
public static final double EGOSPEED- See Also:
-
-
Constructor Details
-
SpaceInvadersLevel
public SpaceInvadersLevel()
-
-
Method Details
-
prepareLevel
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 classPlayground
- Parameters:
id
- String identifies level.
-
redrawLevel
(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 classPlayground
- 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 classPlayground
-
gameOver
public boolean gameOver()- Specified by:
gameOver
in classPlayground
-
levelFinished
public boolean levelFinished()- Specified by:
levelFinished
in classPlayground
-
preferredSizeX
public int preferredSizeX()calculates and returns the preferred size of the level (in pixel) for X-direction- Specified by:
preferredSizeX
in classPlayground
-
preferredSizeY
public int preferredSizeY()calculates and returns the preferred size of the level (in pixel) for Y-direction- Specified by:
preferredSizeY
in classPlayground
-