com.alienfactory.javamappy
Class Layer

java.lang.Object
  extended by com.alienfactory.javamappy.Layer

public class Layer
extends java.lang.Object

Represents one of the layers in a Map. See LayerViewer for details on rendering a Layer to the screen.

Author:
Steve Eynon

Constructor Summary
Layer(MapHeader mapHeader, short[][] layerData, Block[] blocks, AnimBlock[] animBlocks)
           
Layer(Map map, short[][] layerData)
          Deprecated. use @link Layer#Layer(MapHeader, short[][], Block[], AnimBlock[]) instead
 
Method Summary
 AnimBlock getAnimBlock(int blockX, int blockY)
          Returns the AnimBlock at the given block coordinates.
 AnimBlock[] getAnimBlocks()
          Returns the AnimBlocks used by this Layer, as passed into the constructor.
 Block getBlock(int blockX, int blockY)
          Returns the Block at the given block coordinates.
 int getBlockIndex(int blockX, int blockY)
          Returns the Block index at the given coordinates.
 Block[] getBlocks()
          Returns the Blocks used by this Layer, as passed into the constructor.
 int getBottomCollisionCoor(int pixelX, int pixelY, int width, int height)
          Starts at the top of the given rectangle and works its way down, checking the status of the collision flags on the way.
 int getCollisionAt(int x, int y)
          Performs a collision detection test at the given pixel coordinates using the Block's collision flags.
 int getHeightInBlocks()
          Returns the height of the layer, measured in blocks.
 int getHeightInPixels()
          Returns the height of the layer, measured in pixels.
 short[][] getLayerData()
          Returns the raw layer data as passed into the constructor.
 int getLeftCollisionCoor(int pixelX, int pixelY, int width, int height)
          Starts at the right of the given rectangle and works its way to the left, checking the status of the collision flags on the way.
 MapHeader getMapHeader()
          Returns the MapHeader associated with this Layer.
 int getRightCollisionCoor(int pixelX, int pixelY, int width, int height)
          Starts at the left of the given rectangle and works its way to the right, checking the status of the collision flags on the way.
 int getTopCollisionCoor(int pixelX, int pixelY, int width, int height)
          Starts at the bottom of the given rectangle and works its way up, checking the status of the collision flags on the way.
 int getWidthInBlocks()
          Returns the width of the layer, measured in blocks.
 int getWidthInPixels()
          Returns the width of the layer, measured in pixels.
 boolean isAnimBlock(int blockX, int blockY)
          A helper method that checks if the block at the given coordinates is an AnimBlock.
 boolean isCollisionAt(int x, int y)
          Performs a collision detection test at the given pixel coordinates using the Block's collision flags.
 void setBlockIndex(int blockX, int blockY, int blockIndex)
          Replaces the block at the given coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Layer

public Layer(Map map,
             short[][] layerData)
Deprecated. use @link Layer#Layer(MapHeader, short[][], Block[], AnimBlock[]) instead


Layer

public Layer(MapHeader mapHeader,
             short[][] layerData,
             Block[] blocks,
             AnimBlock[] animBlocks)
Method Detail

getMapHeader

public MapHeader getMapHeader()
Returns the MapHeader associated with this Layer. This method should not return null.

Returns:
the MapHeader associated with this Viewer

getWidthInBlocks

public int getWidthInBlocks()
Returns the width of the layer, measured in blocks.


getHeightInBlocks

public int getHeightInBlocks()
Returns the height of the layer, measured in blocks.


getWidthInPixels

public int getWidthInPixels()
Returns the width of the layer, measured in pixels.


getHeightInPixels

public int getHeightInPixels()
Returns the height of the layer, measured in pixels.


getLayerData

public short[][] getLayerData()
Returns the raw layer data as passed into the constructor.


getBlocks

public Block[] getBlocks()
Returns the Blocks used by this Layer, as passed into the constructor.


getAnimBlocks

public AnimBlock[] getAnimBlocks()
Returns the AnimBlocks used by this Layer, as passed into the constructor.


getBlockIndex

public int getBlockIndex(int blockX,
                         int blockY)
                  throws java.lang.IllegalArgumentException
Returns the Block index at the given coordinates. Animation Blocks have negative values.

Throws:
java.lang.IllegalArgumentException

setBlockIndex

public void setBlockIndex(int blockX,
                          int blockY,
                          int blockIndex)
                   throws java.lang.IllegalArgumentException
Replaces the block at the given coordinates. Use this method for dynamically updating and changing the map.

Throws:
java.lang.IllegalArgumentException

getBlock

public Block getBlock(int blockX,
                      int blockY)
               throws java.lang.IllegalArgumentException
Returns the Block at the given block coordinates.
 
If the block is an animation block then the current block in the anim sequence is returned.

Throws:
java.lang.IllegalArgumentException

getAnimBlock

public AnimBlock getAnimBlock(int blockX,
                              int blockY)
                       throws java.lang.IllegalArgumentException
Returns the AnimBlock at the given block coordinates.
 
If the block is not an AnimBlock then an IllegalArgumentException is thrown.

Throws:
java.lang.IllegalArgumentException

isAnimBlock

public boolean isAnimBlock(int blockX,
                           int blockY)
                    throws java.lang.IllegalArgumentException
A helper method that checks if the block at the given coordinates is an AnimBlock.

Throws:
java.lang.IllegalArgumentException

isCollisionAt

public boolean isCollisionAt(int x,
                             int y)
Performs a collision detection test at the given pixel coordinates using the Block's collision flags.

Parameters:
x - the X coordinate
y - the Y coordinate
Returns:
true if there is a collision flag set at the given coordinates
See Also:
Block.setCollisionFlag(int, boolean), Block.getCollisionFlag(int)

getCollisionAt

public int getCollisionAt(int x,
                          int y)
Performs a collision detection test at the given pixel coordinates using the Block's collision flags. This method returns a number representing which corner of the Block the coordinates collided with, or -1 if no collision occurred.

Parameters:
x - the X coordinate
y - the Y coordinate
Returns:
a combination of Block.LEFT, Block.RIGHT, Block.TOP and Block.BOTTOM or -1 if no collision occurred
See Also:
Block.setCollisionFlag(int, boolean), Block.getCollisionFlag(int)

getTopCollisionCoor

public int getTopCollisionCoor(int pixelX,
                               int pixelY,
                               int width,
                               int height)
Starts at the bottom of the given rectangle and works its way up, checking the status of the collision flags on the way. Use this method in platform games when your hero is jumping and you want to know the coor of the ceiling she's just hit her head on, if any.

Returns:
the Y coordinate of the collision or -1 if no collision occurred

getBottomCollisionCoor

public int getBottomCollisionCoor(int pixelX,
                                  int pixelY,
                                  int width,
                                  int height)
Starts at the top of the given rectangle and works its way down, checking the status of the collision flags on the way. Use this method in a platform game when your hero is falling and you want to know the coor of the floor she's just landed on, if any.

Returns:
the Y coordinate of the collision or -1 if no collision occurred

getLeftCollisionCoor

public int getLeftCollisionCoor(int pixelX,
                                int pixelY,
                                int width,
                                int height)
Starts at the right of the given rectangle and works its way to the left, checking the status of the collision flags on the way. Use this method in a platform game when your hero is moving and you want to know the coor of a wall she's just hit, if any.

Returns:
the X coordinate of the collision or -1 if no collision occurred

getRightCollisionCoor

public int getRightCollisionCoor(int pixelX,
                                 int pixelY,
                                 int width,
                                 int height)
Starts at the left of the given rectangle and works its way to the right, checking the status of the collision flags on the way. Use this method in a platform game when your hero is moving and you want to know the coor of a wall she's just hit, if any.

Returns:
the X coordinate of the collision or -1 if no collision occurred


Copyright © 2001-2009 Alien-Factory Ltd. All Rights Reserved.