org.jtgl.gaming
Class TiledSurface

java.lang.Object
  extended by org.jtgl.gaming.Surface
      extended by org.jtgl.gaming.TiledSurface

public class TiledSurface
extends Surface

Represents a surface compound of image tiles (each tile could be empty of filled with a static or animated image)

Author:
Manuel Polo (manuel_polo at yahoo dot es)

Field Summary
 boolean showGrid
           
 
Constructor Summary
TiledSurface(int cellRows, int cellColumns, ImageMatrix imageMatrix)
          Creates a new instance of TiledSurface
TiledSurface(int cellRows, int cellColumns, JTGLImage image, int frameWidth, int frameHeight)
           
 
Method Summary
 int createAnimatedTile(int staticIndex)
           
 void draw(JTGLGraphics g)
           
 void fillCells(int col, int row, int numCols, int numRows, int cellValue)
           
 int getAnimatedCells()
           
 short getAnimatedTile(int animatedIndex)
          Gets the tile referenced by an animated tile.
 short getCell(int col, int row)
           
 short getCellAt(int x, int y)
           
 int getCellHeight()
           
 short getCellValue(int index)
           
 int getCellWidth()
           
 int getCellX(int col)
           
 int getCellY(int row)
           
 int getCol(int x)
           
 int getColumns()
           
 short[] getMap()
           
 int getNumCells()
           
 int getNumTiles()
           
 int getRow(int y)
           
 int getRows()
           
 int getViewHeight()
           
 int getViewWidth()
           
 int getViewX()
           
 int getViewY()
           
 void modCell(int oldIndex, int newIndex)
          Modify all cells with values oldIndex to value newIndex
 void modCells(int savedIndex, int newValue)
          Modify all cells with values oldIndex to value newIndex.
 int modSaveCells(int value)
          Faster method than modCell(int oldIndex,int newIndex) that scans whole map and save cell locations containing the passed value
 int modSaveCells(int value, int reserveSlots)
          Faster method than modCell(int oldIndex,int newIndex) that scans whole map and save all cell locations (indexes within cell-map) containing the passed value
 void moveView(int dx, int dy)
           
 void resetMap(int cellRows, int cellColumns)
           
 void setAnimatedTile(int animatedIndex, int staticIndex)
          Associates an animated tile with the specified static tile.
 void setCell(int col, int row, int index)
           
 void setCellValue(int index, int value)
           
 void setImageMatrix(ImageMatrix imageMatrix, boolean clearMap)
           
 void setMap(short[] map)
           
 void setStaticTileSet(JTGLImage image, int cellWidth, int cellHeight)
           
 void setViewLocation(int x, int y)
           
 void setViewWindow(int x, int y, int width, int height)
           
 void setViewWindowFromViewPort(int vx, int vy, int vWidth, int vHeight)
           
protected  int updateViewCols(int viewWidth, int cellWidth)
           
protected  int updateViewRows(int viewHeight, int cellHeight)
           
 
Methods inherited from class org.jtgl.gaming.Surface
getAbsRefLocation, getBounds, getCenterLocation, getHeight, getLocation, getRefLocation, getWidth, getX, getY, isVisible, move, setAbsRefLocation, setLocation, setRefLocation, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

showGrid

public boolean showGrid
Constructor Detail

TiledSurface

public TiledSurface(int cellRows,
                    int cellColumns,
                    ImageMatrix imageMatrix)
Creates a new instance of TiledSurface


TiledSurface

public TiledSurface(int cellRows,
                    int cellColumns,
                    JTGLImage image,
                    int frameWidth,
                    int frameHeight)
Method Detail

resetMap

public void resetMap(int cellRows,
                     int cellColumns)

setStaticTileSet

public void setStaticTileSet(JTGLImage image,
                             int cellWidth,
                             int cellHeight)

setImageMatrix

public void setImageMatrix(ImageMatrix imageMatrix,
                           boolean clearMap)

getNumCells

public final int getNumCells()

getNumTiles

public final int getNumTiles()

getAnimatedCells

public final int getAnimatedCells()

getRows

public final int getRows()

getColumns

public final int getColumns()

getCellWidth

public final int getCellWidth()

getCellHeight

public final int getCellHeight()

setMap

public void setMap(short[] map)

getMap

public short[] getMap()

setCell

public void setCell(int col,
                    int row,
                    int index)

setCellValue

public void setCellValue(int index,
                         int value)

getCell

public short getCell(int col,
                     int row)

getCellValue

public short getCellValue(int index)

getCellX

public int getCellX(int col)

getCellY

public int getCellY(int row)

getCol

public int getCol(int x)

getRow

public int getRow(int y)

getCellAt

public short getCellAt(int x,
                       int y)

modCell

public final void modCell(int oldIndex,
                          int newIndex)
Modify all cells with values oldIndex to value newIndex


modSaveCells

public int modSaveCells(int value,
                        int reserveSlots)
Faster method than modCell(int oldIndex,int newIndex) that scans whole map and save all cell locations (indexes within cell-map) containing the passed value


modSaveCells

public int modSaveCells(int value)
Faster method than modCell(int oldIndex,int newIndex) that scans whole map and save cell locations containing the passed value


modCells

public void modCells(int savedIndex,
                     int newValue)
Modify all cells with values oldIndex to value newIndex. This method is faster than modCell but requires a previous call to modSaveCells to allocate an index to a saved value.

See Also:
modSaveCells

createAnimatedTile

public int createAnimatedTile(int staticIndex)

setAnimatedTile

public void setAnimatedTile(int animatedIndex,
                            int staticIndex)
Associates an animated tile with the specified static tile.

Parameters:
animatedIndex - the index of the animated tile
staticIndex - the index of the associated tile (must be 0 or a valid static tile index)
Throws:
java.lang.IndexOutOfBoundsException - if the staticIndex is invalid
java.lang.IndexOutOfBoundsException - if the animated tile index is invalid
See Also:
getAnimatedTile(int)

getAnimatedTile

public short getAnimatedTile(int animatedIndex)
Gets the tile referenced by an animated tile.

Returns the tile index currently associated with the animated tile.

Parameters:
animatedIndex - the index of the animated tile
Returns:
the index of the tile reference by the animated tile
Throws:
java.lang.IndexOutOfBoundsException - if the animated tile index is invalid
See Also:
setAnimatedTile(int, int)

fillCells

public void fillCells(int col,
                      int row,
                      int numCols,
                      int numRows,
                      int cellValue)

setViewWindowFromViewPort

public void setViewWindowFromViewPort(int vx,
                                      int vy,
                                      int vWidth,
                                      int vHeight)

setViewWindow

public void setViewWindow(int x,
                          int y,
                          int width,
                          int height)

setViewLocation

public void setViewLocation(int x,
                            int y)

getViewX

public int getViewX()

getViewY

public int getViewY()

getViewWidth

public int getViewWidth()

getViewHeight

public int getViewHeight()

moveView

public void moveView(int dx,
                     int dy)

draw

public void draw(JTGLGraphics g)
Specified by:
draw in class Surface

updateViewCols

protected int updateViewCols(int viewWidth,
                             int cellWidth)

updateViewRows

protected int updateViewRows(int viewHeight,
                             int cellHeight)