![]() |
Platformer Prototype
A Bare-Bones Platformer
|
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... | |
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... | |
void | Clear () |
Clear the map. More... | |
void | ReadMap (char *&, const char *) |
Read the map text file. More... | |
void | PreProcess (const char *, const size_t) |
Preprocess the text map. More... | |
char | ProcessChar (const char, const size_t, const size_t) |
Process character. 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. | |
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.
|
private |
Clear the tile manager by deleting the array of character maps.
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::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.
|
private |
Pre-process a tile map.
buffer | Character buffer holding map. |
n | Number of characters in buffer. |
|
private |
Process a character. Non-tile characters get replaced by a floor tile after the corresponding object gets created by the object manager. T
is a turret, P
the player, and D
a door.
c | Character to be processed. |
i | Vertical index of character in map. |
j | Horizontal index of character in map. |
|
private |
Read a map from a file.
buffer | [out] Character buffer to hold map. |
filename | Name of text file. |
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. |