Game Development Reference
In-Depth Information
break;
case MOVE_DOWN:
row++;
if (row == mapRowCount) {
row = 0;
}
break;
case MOVE_LEFT:
col--;
if (col <0) {
col = mapColumnCount - 1;
}
break;
case MOVE_RIGHT:
col++;
if (col == mapColumnCount) {
col = 0;
}
break;
}
if (tileSheetData[levelTileMap[row][col]] == TILE_MOVE) {
//trace("can move");
return true;
}else {
//trace("can't move");
return false;
}
}
These are the major points you need to know about the checkTile function:
The checkTile function runs a switch:case on the direction passed in.
The first thing it does is set its local row and col variables to equal the currRow and
currCol values from the object (the player in this case).
Based on the direction the player is trying to go, the col or row value will either be
incremented or decremented by one as follows:
Left : col--
Right : col++
Up : row --
Down : row++
If the new value for the row or column happens to be off screen (a tunnel perhaps), the
tile col or row value is set to the value on the opposite side of the game screen.
After the switch:case statement, the tileSheetData array is evaluated. It plugs the row
and col values into the 2D array of level tiles, levelTileMap , to get a single number
representing the tile from the tile sheet ( tileSheetData ) on the level map. If that tile is a
TILE_MOVE tile, true is returned by the function. If not, false is returned.
Search WWH ::




Custom Search