![]() |
The Top-Down Tiled Game Prototype
A Basic Tiled Top-Down Shooter
|
Tile manager. More...
#include <TileManager.h>


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< CObjectDesc > | m_vecObjects |
| Object descriptors. | |
Additional Inherited Members | |
Static Protected Attributes inherited from CCommon | |
| static Sage::CSpriteRenderer * | m_pRenderer = nullptr |
| Pointer to renderer. | |
| static CObjectManager * | m_pObjectManager = nullptr |
| Pointer to object manager. | |
| static Sage::CParticleEngine2D * | m_pParticleEngine = nullptr |
| Pointer to particle engine. | |
| static CTileManager * | m_pTileManager = nullptr |
| Pointer to tile manager. | |
| static CPlayer * | m_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. | |
The tile manager is responsible for the tile-based background and matters arising therefrom. See Section 5 of the documentation for more details.
| 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. 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.
| 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. |

| const std::vector< CObjectDesc > & CTileManager::GetObjects | ( | ) | const |
Get object descriptors for objects listed on map.
m_vecObjects. 
|
private |
Get the position of a tile from its indices (row and column numbers).
| i | Row number. |
| j | Column number. |

|
private |
Insert an object into our vector of map objects m_vecObjects.
| t | Type. |
| v | Position. |
| r | Orientation. |

| 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.
| 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 |
Make bounding boxes that consist of a single tile.

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

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

| 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.
| pGuard | Pointer to a guard. |

