Managing the World
WorldDisplay
manages:
The moving tile floor, represented by a single GIF
No-go areas on the floor
Blocks occupying certain tiles
Pickups occupying certain tiles
Communication between the player and aliens sprites
The communication between the player and sprites in the game is rudimentary, mainly involving the transmission of position information and the number of pickups left. However, the coding technique of passing this information through the WorldDisplay
is a useful one since it allows WorldDisplay
to monitor and control the interactions between the sprites. WorldDisplay
utilizes three main data structures:
An
obstacles[][]
Boolean array specifying which tiles are no-go's or contain blocksA
WorldItems
object that stores details on blocks, pickups, and sprites in tile row order to make them easier to draw with the correct z-orderingA
numPickups
counter to record how many pickups are still left to be picked up
These are simply declared as variables in the class:
private boolean obstacles[][]; private WorldItems wItems; private int numPickups;
WorldDisplay
's methods fall into five main groups, which I'll consider in detail in the following subsections:
The loading of floor information, which describes where the tiles, rows, and columns are located on the floor
The loading of world entity information, which gives the tile coordinates of the no-go areas, blocks, and pickups
Pickup-related methods
Player-related methods
Drawing the world
Loading Floor Information
The floor image ...
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.