Define the tilemap functions and variables. More...
#include <TileMap.hpp>
Public Member Functions | |
TileMap (std::string tileSheetFileName, int rows, int cols, int _TileWidth, int _TileHeight, int _TileWindowWidth, int _TileWindowHeight, int _mapX, int _mapY, SDL_Renderer *ren) | |
Constructor. More... | |
~TileMap () | |
Destructor. More... | |
void | GenerateSimpleMap (const char *const filePath) |
Read the data in local tile sheet and call SetTile(). More... | |
void | PrintMap () |
Output the value in m_Tiles into console. More... | |
void | SetTile (int x, int y, int type) |
Set type of each tile. More... | |
void | UpdateTile (int x, int y, int type) |
Update the type of a specified tile. More... | |
int | GetTileType (int x, int y) |
Get the type of a specified tile. More... | |
int | CheckCollidable (int x, int y) |
Determines whether the given tile is a collidable tile. More... | |
int * | GetTileArr () |
Get the array which stores the whole tilemap. More... | |
void | Render (SDL_Renderer *ren, Camera *camera) |
Render something to the active viewport. More... | |
void | SetupTileMap () |
Set the value of all the tiles to -1. More... | |
void | SaveTileMap (const char *const filePath) |
Save current tilemap to local file. More... | |
void | addTile (int srcRow, int srcCol, int destRow, int destCol) |
Change the type of a specifed tile. More... | |
int | GetBeneathGround (int x, int y) |
Given enemy pos, return the landable tile pos. More... | |
int | RayCast (int x1, int y1, int x2, int y2) |
Create a raycast to detect player's position. More... | |
int | fastDist (int dx, int dy) |
fastly approximate how many tiles there are between 2 tiles. ref: https://stackoverflow.com/questions/7913511/distance-approximation More... | |
bool | CheckWalkable (int x, int y, int movingRight) |
check if the given tile is walkable More... | |
Position | generateRandomDungeon () |
generate a random dungeon with the BSP Map Generator More... | |
void | autoTiling () |
automatically redraw the tile map to make the whole map look nicer More... | |
void | autoTileGrid (int x, int y) |
look at the 3*3 area around the current grid to determine the proper tile to draw More... | |
Public Member Functions inherited from Component | |
Component () | |
~Component () | |
Define the tilemap functions and variables.
This class offers functions to initialize, update as well as download the whole map.
TileMap::TileMap | ( | std::string | tileSheetFileName, |
int | rows, | ||
int | cols, | ||
int | _TileWidth, | ||
int | _TileHeight, | ||
int | _TileWindowWidth, | ||
int | _TileWindowHeight, | ||
int | _mapX, | ||
int | _mapY, | ||
SDL_Renderer * | ren | ||
) |
Constructor.
tileSheetFileName | The name of the source file which stores the tile sheet. |
rows | How many rows are in the tile sheet. |
cols | How many columns are in the tile sheet. |
_TileWidth | Each tile's width in pixel in source file. |
_TileHeight | Each tile's height in pixel in source file. |
_TileWindowWidth | Each tile's width in pixel in game. |
_TileWindowHeight | Each tile's height in pixel in game. |
_mapX | Total cols of tiles in the current map. |
_mapY | Total rows of tiles in the current map. |
ren | Reference to SDL renderer. |
TileMap::~TileMap | ( | ) |
Destructor.
void TileMap::addTile | ( | int | srcRow, |
int | srcCol, | ||
int | destRow, | ||
int | destCol | ||
) |
Change the type of a specifed tile.
Change the type of a specified tile based on the selected tile. This function only works in Tilemap editor page.
srcRow | The number of rows of the selected tile. |
srcCol | The number of columns of the selected tile. |
destRow | The number of rows of the tile you want to modify. |
destCol | The number of columns of the tile you want to modify. |
void TileMap::autoTileGrid | ( | int | x, |
int | y | ||
) |
look at the 3*3 area around the current grid to determine the proper tile to draw
void TileMap::autoTiling | ( | ) |
automatically redraw the tile map to make the whole map look nicer
int TileMap::CheckCollidable | ( | int | x, |
int | y | ||
) |
Determines whether the given tile is a collidable tile.
bool TileMap::CheckWalkable | ( | int | x, |
int | y, | ||
int | movingRight | ||
) |
check if the given tile is walkable
int TileMap::fastDist | ( | int | dx, |
int | dy | ||
) |
fastly approximate how many tiles there are between 2 tiles. ref: https://stackoverflow.com/questions/7913511/distance-approximation
dx | X-coordinate difference. |
dy | Y-coordinate difference. |
Position TileMap::generateRandomDungeon | ( | ) |
generate a random dungeon with the BSP Map Generator
void TileMap::GenerateSimpleMap | ( | const char *const | filePath | ) |
Read the data in local tile sheet and call SetTile().
filePath | The file name of the local tile sheet. |
int TileMap::GetBeneathGround | ( | int | x, |
int | y | ||
) |
Given enemy pos, return the landable tile pos.
Check the tile under the character.
x | The number of rows of the tile based on player's position. |
y | The number of columns of the tile based on player's position.. |
int * TileMap::GetTileArr | ( | ) |
Get the array which stores the whole tilemap.
int TileMap::GetTileType | ( | int | x, |
int | y | ||
) |
Get the type of a specified tile.
x | The number of columns of this tile. |
y | The number of rows of this tile. |
void TileMap::PrintMap | ( | ) |
Output the value in m_Tiles into console.
int TileMap::RayCast | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2 | ||
) |
Create a raycast to detect player's position.
Check is p(x1, y1) could see p(x2, y2)
x1 | X-coordinate of this enemy. |
y1 | Y-coordinate of this enemy. |
x2 | X-coordinate of the player. |
y2 | Y-coordinate of the player. |
void TileMap::Render | ( | SDL_Renderer * | ren, |
Camera * | camera | ||
) |
Render something to the active viewport.
ren | Reference to SDL renderer |
camera | Reference to Camera |
void TileMap::SaveTileMap | ( | const char *const | filePath | ) |
Save current tilemap to local file.
filePath | Reference to the target file name of this tilemap. |
void TileMap::SetTile | ( | int | x, |
int | y, | ||
int | type | ||
) |
Set type of each tile.
x | The number of columns of the current tile. |
y | The number of rows of the current tile. |
type | The type of the current tile. |
void TileMap::SetupTileMap | ( | ) |
Set the value of all the tiles to -1.
void TileMap::UpdateTile | ( | int | x, |
int | y, | ||
int | type | ||
) |
Update the type of a specified tile.
x | The number of columns of this tile. |
y | The number of rows of this tile. |
type | The new type of this tile. |