![]() |
Tiled Top-down Shooter Prototype
Tiled Top-Down Shooter
|
The tile manager. More...
#include <TileManager.h>
Public Member Functions | |
CTileManager (size_t) | |
Constructor. More... | |
~CTileManager () | |
Destructor. More... | |
void | LoadMap (char *) |
Load a map. More... | |
void | Draw (eSprite) |
Draw the map with a given tile. More... | |
void | DrawBoundingBoxes (eSprite) |
Draw the bounding boxes. More... | |
void | GetObjects (std::vector< Vector2 > &, Vector2 &) |
Get objects. More... | |
const bool | Visible (const Vector2 &, const Vector2 &, float) const |
Check visibility. More... | |
const bool | CollideWithWall (BoundingSphere, Vector2 &, float &) const |
Object-wall collision test. More... | |
Private Member Functions | |
void | MakeBoundingBoxes () |
Make bounding boxes for walls. More... | |
Private Attributes | |
size_t | m_nWidth = 0 |
Number of tiles wide. | |
size_t | m_nHeight = 0 |
Number of tiles high. | |
float | m_fTileSize = 0.0f |
Tile width and height. | |
char ** | m_chMap = nullptr |
The level map. | |
std::vector< BoundingBox > | m_vecWalls |
AABBs for the walls. | |
std::vector< Vector2 > | m_vecTurrets |
Turret positions. | |
Vector2 | m_vPlayer |
Player location. | |
Additional Inherited Members | |
![]() | |
static LSpriteRenderer * | m_pRenderer = nullptr |
Pointer to renderer. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to object manager. | |
static LParticleEngine2D * | m_pParticleEngine = nullptr |
Pointer to particle engine. | |
static CTileManager * | m_pTileManager = nullptr |
Pointer to tile manager. | |
static bool | m_bDrawAABBs = false |
Draw AABB flag. | |
static bool | m_bGodMode = false |
God mode flag. | |
static Vector2 | m_vWorldSize = Vector2::Zero |
World height and width. | |
static CPlayer * | m_pPlayer = nullptr |
Pointer to player character. | |
The tile manager is responsible for the tile-based background.
CTileManager::CTileManager | ( | size_t | n | ) |
Construct a tile manager using square tiles, given the width and height of each tile.
n | Width and height of square tile in pixels. |
CTileManager::~CTileManager | ( | ) |
Delete the memory used for storing the map.
const bool CTileManager::CollideWithWall | ( | BoundingSphere | s, |
Vector2 & | norm, | ||
float & | d | ||
) | const |
Check whether a bounding sphere collides with one of the wall bounding boxes. If so, compute the collision normal and the overlap distance.
s | Bounding sphere of object. |
norm | [out] Collision normal. |
d | [out] Overlap distance. |
void CTileManager::Draw | ( | eSprite | t | ) |
Draw order is top-down, left-to-right so that the image agrees with the map text file viewed in NotePad.
t | Sprite type for a 3-frame sprite: 0 is floor, 1 is wall, 2 is an error tile. |
void CTileManager::DrawBoundingBoxes | ( | eSprite | t | ) |
This is for debug purposes so that you can verify that the collision shapes are in the right places.
t | Line sprite to be stretched to draw the line. |
void CTileManager::GetObjects | ( | std::vector< Vector2 > & | turrets, |
Vector2 & | player | ||
) |
Get positions of objects listed on map.
turrets | [out] Vector of turret positions |
player | [out] Player position. |
void CTileManager::LoadMap | ( | char * | filename | ) |
Delete the old map (if any), allocate the right sized chunk of memory for the new map, and read it from a text file.
filename | Name of the map file. |
|
private |
Make the AABBs for the walls. Care is taken to use the longest horizontal and vertical AABBs possible so that there aren't so many of them.
const bool CTileManager::Visible | ( | const Vector2 & | p0, |
const Vector2 & | p1, | ||
float | r | ||
) | const |
Check whether a circle is visible from a point, that is, either the left or the right side of the object (from the perspective of the point) has no walls between it and the point. This gives some weird behavior when the circle is partially hidden by a block, but it doesn't seem particularly unnatural in practice. It'll do.
p0 | A point. |
p1 | Center of circle. |
r | Radius of circle. |