![]() |
Tiled Platformer Prototype
A Basic Tiled Platformer
|
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 | 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 &) |
| 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_bShowBounds = false |
| Draw bounding boxes and circles flag. | |
| static eGameState | m_eGameState = eGameState::Loading |
| Game state. | |
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 the center a tile from its row and column indices.
| i | Row number. |
| j | Column number. |

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

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