Platformer Prototype
A Bare-Bones Platformer
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CTileManager Class Reference

The tile manager. More...

#include <TileManager.h>

Inheritance diagram for CTileManager:
CCommon

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 Protected Attributes inherited from CCommon
static LSpriteRenderer * m_pRenderer = nullptr
 Pointer to renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to object manager.
 
static LParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static CTileManagerm_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 CPlayerm_pPlayer = nullptr
 Pointer to player character.
 

Detailed Description

The tile manager is responsible for the tile-based background.

Constructor & Destructor Documentation

◆ CTileManager()

CTileManager::CTileManager ( size_t  n)

Construct a tile manager using square tiles, given the width and height of each tile.

Parameters
nWidth and height of square tile in pixels.

◆ ~CTileManager()

CTileManager::~CTileManager ( )

Delete the memory used for storing the map.

Member Function Documentation

◆ Clear()

void CTileManager::Clear ( )
private

Clear the tile manager by deleting the array of character maps.

◆ CollideWithWall()

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.

Parameters
sBounding sphere of object.
norm[out] Collision normal.
d[out] Overlap distance.
Returns
true if the bounding sphere overlaps a wall.

◆ Draw()

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.

Parameters
tSprite type for a 3-frame sprite: 0 is floor, 1 is wall, 2 is an error tile.

◆ DrawBoundingBoxes()

void CTileManager::DrawBoundingBoxes ( eSprite  t)

This is for debug purposes so that you can verify that the collision shapes are in the right places.

Parameters
tLine sprite to be stretched to draw the line.

◆ LoadMap()

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.

Parameters
filenameName of the map file.

◆ MakeBoundingBoxes()

void CTileManager::MakeBoundingBoxes ( )
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.

◆ PreProcess()

void CTileManager::PreProcess ( const char *  buffer,
const size_t  n 
)
private

Pre-process a tile map.

Parameters
bufferCharacter buffer holding map.
nNumber of characters in buffer.

◆ ProcessChar()

char CTileManager::ProcessChar ( const char  c,
const size_t  i,
const size_t  j 
)
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.

Parameters
cCharacter to be processed.
iVertical index of character in map.
jHorizontal index of character in map.
Returns
The processed character.

◆ ReadMap()

void CTileManager::ReadMap ( char *&  buffer,
const char *  filename 
)
private

Read a map from a file.

Parameters
buffer[out] Character buffer to hold map.
filenameName of text file.

◆ Visible()

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.

Parameters
p0A point.
p1Center of circle.
rRadius of circle.
Returns
true If the circle is visible from the point.