android.gameengine.icadroids.tiles
Class GameTiles

java.lang.Object
  extended by android.gameengine.icadroids.tiles.GameTiles

public class GameTiles
extends java.lang.Object

Gametiles are especially useful if you want to quickly build a level/map (walls, floor, etc) for a platform- or boardgame. This class makes for every tile a seperated object and place it on the right position. The tile objects can be manipulated separately.

Author:
Edward van Raak & Bas van der Zandt

Field Summary
 int tileSize
          The width and height of every tile.
 java.util.Vector<Sprite> tileTypes
          Array that holds different TileTypes with each it's own sprites and behavior.
 
Constructor Summary
GameTiles(int tileSize)
          This overloaded constructor will make an GameTile object with an empty tilemap.
GameTiles(java.lang.String[] tileResources, int[][] map, int tileSize)
          Make a new tilemap object with the given tile resources, the tilemap and the tile size
 
Method Summary
 void addTileMap(int[][] map, int tileSize)
          Add / replace the current tile map.
 void addTileResources(java.lang.String[] resourceNames)
          Add resources to the list
 void changeTile(int xTile, int yTile, int tileType)
          Change a tile in the game world, add or remove a tile.
 void drawTiles(Canvas c)
          Loop through the TileArray to draw the Tiles.
 int getMapHeigth()
          Get the height of the map
 int getMapWidth()
          Get the width of the map
 Tile[][] getTileArray()
          Get the list with all the Tile objects in it.
 Tile getTileOnIndex(int xIndex, int yIndex)
          get a Tile on a specified index number of the tile list
 Tile getTileOnPosition(int xPosition, int yPosition)
          Get a tile on a specific x and y position in the game world
 java.util.Vector<Sprite> getTileTypes()
           
 void setTileTypes(java.util.Vector<Sprite> tileTypes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tileTypes

public java.util.Vector<Sprite> tileTypes
Array that holds different TileTypes with each it's own sprites and behavior.


tileSize

public int tileSize
The width and height of every tile. Default value set to 50.

Constructor Detail

GameTiles

public GameTiles(java.lang.String[] tileResources,
                 int[][] map,
                 int tileSize)
Make a new tilemap object with the given tile resources, the tilemap and the tile size

Parameters:
tileResources - a list of string with the names of the images you want to use in the tilemap. This images have only the name of the images without the extension! For example: new String[] = {"tile1", "tile2", "tile3"};
map - An 2d Array of the overlay map. The numbers are the position of the tileResources, starting at 0. -1 means invisible Tile. Example: new Int[][] = {{0,-1,2,2,-1},{1,1,-1,2,-1}}
tileSize - The size of a tile. This size is the width and height of a tile.

GameTiles

public GameTiles(int tileSize)
This overloaded constructor will make an GameTile object with an empty tilemap.

Parameters:
tileSize -
Method Detail

addTileMap

public void addTileMap(int[][] map,
                       int tileSize)
Add / replace the current tile map. This method will also convert the given int[][] map to a Tile[][] map.

Parameters:
map - An 2d Array of the overlay map. The numbers are the position of the tileResources, starting at 0. -1 means invisible Tile. Example: new Int[][] = {{0,-1,2,2,-1},{1,1,-1,2,-1}}
tileSize - The size of a tile. This size is the width and height of a tile.

drawTiles

public void drawTiles(Canvas c)
Loop through the TileArray to draw the Tiles. The TileType is checked on every loop so that the correct sprite is drawn.


changeTile

public void changeTile(int xTile,
                       int yTile,
                       int tileType)
Change a tile in the game world, add or remove a tile.

Notes:

The x and y positions are the indices in the tile array.
The value -1 for the tileType removes the tile at the given position.
If you specify a position that was previously empty, a new Tile will be created.

Parameters:
yTile - the y-pos of the tile in the tile array
xTile - the y-pos of the tile in the tile array
tileType - the new sprite type that should replace this tile

getTileTypes

public java.util.Vector<Sprite> getTileTypes()
Returns:
the tileTypes

setTileTypes

public void setTileTypes(java.util.Vector<Sprite> tileTypes)
Parameters:
tileTypes - the tileTypes to set

getTileArray

public Tile[][] getTileArray()
Get the list with all the Tile objects in it.

Returns:
the tileArray

addTileResources

public void addTileResources(java.lang.String[] resourceNames)
Add resources to the list

Parameters:
resourceNames - all resources you want to add to the list

getMapHeigth

public int getMapHeigth()
Get the height of the map

Returns:
Map height

getMapWidth

public int getMapWidth()
Get the width of the map

Returns:
Map width

getTileOnPosition

public Tile getTileOnPosition(int xPosition,
                              int yPosition)
Get a tile on a specific x and y position in the game world

Parameters:
xPosition - x position of the tile
yPosition - y position of the tile
Returns:
The Tile object at the given x and y position

getTileOnIndex

public Tile getTileOnIndex(int xIndex,
                           int yIndex)
get a Tile on a specified index number of the tile list

Parameters:
xIndex - The x index of the list
yIndex - The y index of the List
Returns:
The tile Object at the given index position