Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

The Tile Occupier

A tile occupier has a unique name, a type value (BLOCK, PICKUP, or SPRITE), a tile coordinate (xTile, yTile), and a coordinate relative to the top-left corner of the floor image (xDraw, yDraw), where the occupier's image should be drawn. The relationship between these coordinates is shown in Figure 13-11.

Positioning a tile occupier in a tile

Figure 13-11. Positioning a tile occupier in a tile

xDraw and yDraw are relative to the floor image, so floor offsets must be added to them before the image is drawn into the JPanel. The constructor initializes the coordinate details and calls calcPosition() to calculate xDraw and yDraw:

    // globals
    private String name;
    private int type;      // BLOCK, PICKUP, or SPRITE
    private BufferedImage image;
    private int xTile, yTile;    // tile coordinate
    private int xDraw, yDraw;
             // coordinate relative to the floor image where the tile
             // occupier should be drawn

    private TiledSprite sprite = null;
      // used when the TileOccupier is a sprite



    public TileOccupier(String nm, int ty, int x, int y,
              BufferedImage im, int xRowStart, int yRowStart,
                                int xTileWidth, int yTileHeight)
    { name = nm;
      type = ty;
      xTile = x; yTile = y;
      image = im;
      calcPosition(xRowStart, yRowStart, xTileWidth, yTileHeight);
    }

If this object is in an even row, then xRowStart and yRowStart will hold the pixel location of the first even row; otherwise, the location of the first odd row is used. The (x, y) arguments give the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page