Tiled Top-down Shooter Prototype
Tiled Top-Down Shooter
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...
 
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 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

◆ 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.

◆ GetObjects()

void CTileManager::GetObjects ( std::vector< Vector2 > &  turrets,
Vector2 &  player 
)

Get positions of objects listed on map.

Parameters
turrets[out] Vector of turret positions
player[out] Player position.

◆ 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.

◆ 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.