Managing the Bricks
BricksManager
is separated into five broad groups of methods:
Loading bricks information.
Initializing the bricks data structures.
Moving the bricks map.
Drawing the bricks.
JumperSprite
-related tasks. These are mostly various forms of collision detection between the sprite and the bricks.
BricksManager
reads a bricks map and creates a Brick
object for each brick. The data structure holding the Brick
objects is optimized so drawing and collision detection can be carried out quickly.
Moving and drawing the bricks map is analogous to the moving and drawing of an image by a Ribbon
object. However, the drawing process is complicated by the ribbon consisting of multiple bricks instead of a single GIF.
Jack, the JumperSprite
object, uses BricksManager
methods to determine if its planned moves will cause it to collide with a brick.
Loading Bricks Information
BricksManager
calls loadBricksFile()
to load a bricks map; the map is assumed to be in bricksInfo.txt from Images/.
The first line of the file (ignoring comment lines) is the name of the image strip:
s tiles.gif 5
This means that tiles.gif holds a strip of five images. The map is a series of lines containing numbers and spaces. Each line corresponds to a row of tiles in the game. A number refers to a particular image in the image strip, which becomes a tile. A space means that no tile is used in that position in the game.
Tip
The map file may contain empty lines and comment lines (those starting with //
), which are ignored. ...
Get Killer Game Programming in Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.