com.alienfactory.javamappy
Class Block

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

public class Block
extends java.lang.Object

A simple bean class which represents a Block as used by Mappy.

A Block may contain up to 4 layers of images (1 background layer and 3 foreground layers), 7 fields of User data, quadratic collision information and 4 other flags.

Author:
Steve Eynon

Field Summary
static int ATTACH_NEXT
          Used in Pillar Riser Mode to flag that the next Block should continue the pillar.
static int BACKGROUND
          A Block image layer used to get / set its image index.
static int BOTTOM
          In conjunction with LEFT or RIGHT this specifies a corner of the Block.
static int FOREGROUND1
          A Block image layer used to get / set its image index.
static int FOREGROUND2
          A Block image layer used to get / set its image index.
static int FOREGROUND3
          A Block image layer used to get / set its image index.
static int LEFT
          In conjunction with TOP or BOTTOM this specifies a corner of the Block.
static int LEFT_SIDE_PILLAR
          Used in Pillar Riser Mode to flag that only the left hand side of the Block should be rendered.
static int MAX_USER_DATA
          A minimum index for User Data.
static int MIN_USER_DATA
          A minimum index for User Data.
static int RIGHT
          In conjunction with TOP or BOTTOM this specifies a corner of the Block.
static int RIGHT_SIDE_PILLAR
          Used in Pillar Riser Mode to flag that only the right hand side of the Block should be rendered.
static int TOP
          In conjunction with LEFT or RIGHT this specifies a corner of the Block.
static int TRIGGER
          A User defined flag.
static int UNUSED1
          A User defined flag.
static int UNUSED2
          A User defined flag.
static int UNUSED3
          A User defined flag.
 
Constructor Summary
Block()
           
 
Method Summary
 boolean getCollisionFlag(int flag)
          Returns the specified collision flag.
 boolean getFlag(int flag)
          Returns the specified flag.
 int getImageIndex(int imageLayer)
          Returns the image index of the given Block layer.
 java.lang.String getTextString()
          Returns the text string associated with this block.
 int getUserData(int index)
          Returns the specified User Data.
 void setCollisionFlag(int flag, boolean newFlag)
          Sets the specified collision flag.
 void setFlag(int flag, boolean newFlag)
          Sets the specified flag to the given boolean value.
 void setImageIndex(int imageLayer, int newImageIndex)
          Sets the image index of the given Block layer.
 void setTextString(java.lang.String textString)
          Sets the text string associated with this block.
 void setUserData(int index, int newUserData)
          Sets the specified User Data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
In conjunction with TOP or BOTTOM this specifies a corner of the Block. Used when getting / setting a collision flag.

Has a constant value of 4.

See Also:
setCollisionFlag(int, boolean), getCollisionFlag(int), Constant Field Values

RIGHT

public static final int RIGHT
In conjunction with TOP or BOTTOM this specifies a corner of the Block. Used when getting / setting a collision flag.

Has a constant value of 8.

See Also:
setCollisionFlag(int, boolean), getCollisionFlag(int), Constant Field Values

TOP

public static final int TOP
In conjunction with LEFT or RIGHT this specifies a corner of the Block. Used when getting / setting a collision flag.

Has a constant value of 16.

See Also:
setCollisionFlag(int, boolean), getCollisionFlag(int), Constant Field Values

BOTTOM

public static final int BOTTOM
In conjunction with LEFT or RIGHT this specifies a corner of the Block. Used when getting / setting a collision flag.

Has a constant value of 32.

See Also:
setCollisionFlag(int, boolean), getCollisionFlag(int), Constant Field Values

BACKGROUND

public static final int BACKGROUND
A Block image layer used to get / set its image index.

Has a constant value of 0.

See Also:
setImageIndex(int, int), getImageIndex(int), Constant Field Values

FOREGROUND1

public static final int FOREGROUND1
A Block image layer used to get / set its image index.

Has a constant value of 1.

See Also:
setImageIndex(int, int), getImageIndex(int), Constant Field Values

FOREGROUND2

public static final int FOREGROUND2
A Block image layer used to get / set its image index.

Has a constant value of 2.

See Also:
setImageIndex(int, int), getImageIndex(int), Constant Field Values

FOREGROUND3

public static final int FOREGROUND3
A Block image layer used to get / set its image index.

Has a constant value of 3.

See Also:
setImageIndex(int, int), getImageIndex(int), Constant Field Values

MIN_USER_DATA

public static final int MIN_USER_DATA
A minimum index for User Data.

Has a constant value of 1.

See Also:
setUserData(int, int), getUserData(int), Constant Field Values

MAX_USER_DATA

public static final int MAX_USER_DATA
A minimum index for User Data.

Has a constant value of 7.

See Also:
setUserData(int, int), getUserData(int), Constant Field Values

TRIGGER

public static final int TRIGGER
A User defined flag.

Has a constant value of 0.

See Also:
setFlag(int, boolean), getFlag(int), Constant Field Values

UNUSED1

public static final int UNUSED1
A User defined flag.

Has a constant value of 1.

See Also:
setFlag(int, boolean), getFlag(int), Constant Field Values

UNUSED2

public static final int UNUSED2
A User defined flag.

Has a constant value of 2.

See Also:
setFlag(int, boolean), getFlag(int), Constant Field Values

UNUSED3

public static final int UNUSED3
A User defined flag.

Has a constant value of 3.

See Also:
setFlag(int, boolean), getFlag(int), Constant Field Values

ATTACH_NEXT

public static final int ATTACH_NEXT
Used in Pillar Riser Mode to flag that the next Block should continue the pillar.

Has a constant value of 1.

See Also:
setFlag(int, boolean), getFlag(int), Constant Field Values

LEFT_SIDE_PILLAR

public static final int LEFT_SIDE_PILLAR
Used in Pillar Riser Mode to flag that only the left hand side of the Block should be rendered.

Has a constant value of 2.

See Also:
setFlag(int, boolean), getFlag(int), Constant Field Values

RIGHT_SIDE_PILLAR

public static final int RIGHT_SIDE_PILLAR
Used in Pillar Riser Mode to flag that only the right hand side of the Block should be rendered.

Has a constant value of 3.

See Also:
setFlag(int, boolean), getFlag(int), Constant Field Values
Constructor Detail

Block

public Block()
Method Detail

setImageIndex

public void setImageIndex(int imageLayer,
                          int newImageIndex)
                   throws java.lang.IllegalArgumentException
Sets the image index of the given Block layer.

Parameters:
imageLayer - should be one of BACKGROUND, FOREGROUND1, FOREGROUND2 or FOREGROUND3
newImageIndex - the image index to be set
Throws:
java.lang.IllegalArgumentException - if imageLayer is out of bounds - it is assumed that newImageIndex is valid
See Also:
getImageIndex(int)

getImageIndex

public int getImageIndex(int imageLayer)
                  throws java.lang.IllegalArgumentException
Returns the image index of the given Block layer.

Parameters:
imageLayer - should be one of BACKGROUND, FOREGROUND1, FOREGROUND2 or FOREGROUND3
Returns:
the image index of the given Block layer.
Throws:
java.lang.IllegalArgumentException - if imageLayer is out of bounds
See Also:
setImageIndex(int, int)

setUserData

public void setUserData(int index,
                        int newUserData)
                 throws java.lang.IllegalArgumentException
Sets the specified User Data.

Parameters:
index - the User Data to be updated.
newUserData - the new User Data.
Throws:
java.lang.IllegalArgumentException - if (index < MIN_USER_DATA) or (index > MAX_USER_DATA) or
See Also:
getUserData(int)

getUserData

public int getUserData(int index)
                throws java.lang.IllegalArgumentException
Returns the specified User Data.

Parameters:
index - the User Data to be returned.
Returns:
the specified User Data.
Throws:
java.lang.IllegalArgumentException - if (index < MIN_USER_DATA) or (index > MAX_USER_DATA) or
See Also:
setUserData(int, int)

setFlag

public void setFlag(int flag,
                    boolean newFlag)
             throws java.lang.IllegalArgumentException
Sets the specified flag to the given boolean value.

Parameters:
flag - should one of TRIGGER, UNUSED1, UNUSED2 or UNUSED3
newFlag - the new flag to set
Throws:
java.lang.IllegalArgumentException - if flag is out of bounds
See Also:
getFlag(int)

getFlag

public boolean getFlag(int flag)
                throws java.lang.IllegalArgumentException
Returns the specified flag.

Parameters:
flag - should be one of TRIGGER, UNUSED1, UNUSED2 or UNUSED3
Returns:
the specified flag value
Throws:
java.lang.IllegalArgumentException - if flag is out of bounds
See Also:
setFlag(int, boolean)

setCollisionFlag

public void setCollisionFlag(int flag,
                             boolean newFlag)
                      throws java.lang.IllegalArgumentException
Sets the specified collision flag. Example usage:
block.setCollisionFlag(TOP | LEFT, true);

Parameters:
flag - should be a combination of LEFT, RIGHT, TOP and BOTTOM
newFlag - the new Flag.
Throws:
java.lang.IllegalArgumentException - when flag is not valid
See Also:
getCollisionFlag(int)

getCollisionFlag

public boolean getCollisionFlag(int flag)
                         throws java.lang.IllegalArgumentException
Returns the specified collision flag. Example usage:
block.getCollisionFlag(BOTTOM | RIGHT);

Parameters:
flag - should be a combination of LEFT, RIGHT, TOP and BOTTOM
Returns:
the specified collision flag
Throws:
java.lang.IllegalArgumentException - when flag is not valid
See Also:
setCollisionFlag(int, boolean)

getTextString

public java.lang.String getTextString()
Returns the text string associated with this block. The string is set when the map is loaded and is defined within Mappy.


setTextString

public void setTextString(java.lang.String textString)
Sets the text string associated with this block.



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