The Top-Down Tiled Game Prototype
A Basic Tiled Top-Down Shooter
Loading...
Searching...
No Matches
CTileManager Class Reference

Tile manager. More...

#include <TileManager.h>

Inheritance diagram for CTileManager:
Collaboration diagram for CTileManager:

Public Member Functions

 CTileManager (size_t)
 Constructor.
 
 ~CTileManager ()
 Destructor.
 
void LoadMap (const std::string &)
 Load a map.
 
void Draw (eSprite)
 Draw the map using multi-framed tile sprite.
 
void DrawBoundingBoxes (eSprite)
 Draw the bounding boxes.
 
const std::vector< CObjectDesc > & GetObjects () const
 Get object descriptorss.
 
const bool Visible (CGuard *) const
 Player visibility test.
 
const bool CollideWithWall (BoundingSphere, Vector2 &, float &) const
 Object-wall collision test.
 

Private Member Functions

void MakeBoundingBoxes ()
 Make bounding boxes for walls.
 
void MakeBoundingBoxesH ()
 Make bounding boxes for horizontal walls.
 
void MakeBoundingBoxesV ()
 Make bounding boxes for vertical walls.
 
void MakeBoundingBoxes1 ()
 Make bounding boxes for 1-block walls.
 
Vector2 IndexToPosition (size_t, size_t)
 Tile index to position.
 
void InsertObject (eObject, const Vector2 &, float=0.0f)
 Insert object.
 

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< CObjectDescm_vecObjects
 Object descriptors.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_pRenderer = nullptr
 Pointer to renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to object manager.
 
static Sage::CParticleEngine2D * m_pParticleEngine = nullptr
 Pointer to particle engine.
 
static CTileManagerm_pTileManager = nullptr
 Pointer to tile manager.

 
static CPlayerm_pPlayer = nullptr
 Pointer to player character.
 
static Vector2 m_vWorldSize
 World height and width.
 
static bool m_bGodMode = false
 God mode flag.
 
static bool m_bShowState = false
 Show NPC state flag.
 
static bool m_bShowBounds = false
 Draw bounding boxes and circles flag.
 

Detailed Description

The tile manager is responsible for the tile-based background and matters arising therefrom. See Section 5 of the documentation for more details.

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. This function assumes that if there is any overlap at all, then the sphere overlaps either a single corner point of the bounding box, or if not, then a single edge of the bounding box in the XY plane. This is a reasonable assumption for a 2D game in which objects move only a small distance in each frame. If the sphere overlaps more than one bounding box in the bounding box list, then the first one is used. Therefore this function will need to be called more than once per animation frame.

Parameters
sBounding sphere of object.
norm[out] Collision normal.
d[out] Overlap distance.
Returns
true if the bounding sphere overlaps a wall.
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ 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.
Here is the caller graph for this function:

◆ GetObjects()

const std::vector< CObjectDesc > & CTileManager::GetObjects ( ) const

Get object descriptors for objects listed on map.

Returns
A reference to m_vecObjects.
Here is the caller graph for this function:

◆ IndexToPosition()

Vector2 CTileManager::IndexToPosition ( size_t i,
size_t j )
private

Get the position of a tile from its indices (row and column numbers).

Parameters
iRow number.
jColumn number.
Returns
Position of tile.
Here is the caller graph for this function:

◆ InsertObject()

void CTileManager::InsertObject ( eObject t,
const Vector2 & v,
float r = 0.0f )
private

Insert an object into our vector of map objects m_vecObjects.

Parameters
tType.
vPosition.
rOrientation.
Here is the caller graph for this function:

◆ LoadMap()

void CTileManager::LoadMap ( const std::string & 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.
Here is the call graph for this function:
Here is the caller graph for this function:

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeBoundingBoxes1()

void CTileManager::MakeBoundingBoxes1 ( )
private

Make bounding boxes that consist of a single tile.

Here is the caller graph for this function:

◆ MakeBoundingBoxesH()

void CTileManager::MakeBoundingBoxesH ( )
private

Make horizontal bounding boxes that we as long as possible but skip any walls that consist of just a single tile.

Here is the caller graph for this function:

◆ MakeBoundingBoxesV()

void CTileManager::MakeBoundingBoxesV ( )
private

Make vertical bounding boxes that we as long as possible but skip any walls that consist of just a single tile.

Here is the caller graph for this function:

◆ Visible()

const bool CTileManager::Visible ( CGuard * pGuard) const

Check whether the player is visible to a guard. What we want is to check whether a line can be drawn between the guard's position and the player's position without overlapping one of the wall AABBs. Unfortunately, since we are using DirectX::BoundingBox for an AABB which does not have an Intersect function for a line, we'll have to use its Intersect function for a 3D triangle whose top edge is the line.

Parameters
pGuardPointer to a guard.
Returns
true If one side of player is visible to the guard.
Here is the call graph for this function:
Here is the caller graph for this function: