Game Engine 2D Platformer
TileMap.hpp
Go to the documentation of this file.
1 /*
2  * @file TileMap.hpp
3  * @brief TileMap class interface
4  * @date 2021-03-12
5  ***********************************************/
6 #ifndef TILE_H
7 #define TILE_H
8 
9 #include <string>
10 #include <iostream>
11 #include <vector>
12 #include <map>
14 #include "GameEntity.hpp"
15 #include "TileComponent.hpp"
16 
19 class TileMap
20 {
21 public:
30  TileMap(std::string tileSheetFileName, std::string _TileMapPath, int levelWidth, int levelHeight, int _TileSize, SDL_Renderer *ren);
34  ~TileMap();
39  void GenerateSimpleMap(std::vector<int> &collectablesAvailable);
43  void PrintMap();
47  void SetTile(int x, int y, int type);
51  int GetTileType(int x, int y);
55  void Render(SDL_Renderer *ren, int x, std::vector<std::shared_ptr<GameEntity>> &obstacles, std::shared_ptr<GameEntity> mainCharacter);
59  void setTileSheetMap(int width, int height);
60 
61  std::vector<int> getEnemyData();
62 
63 private:
64  // Dimensions of our TileMap and individual tiles.
65  // Used for spiltting up the sprite sheet
66  int m_Rows;
67  int m_Cols;
68  // How big each tile is.
69  int m_TileWidth;
70  int m_TileHeight;
71  // size of our tilemap
72  int m_MapX;
73  int m_MapY;
74  // Where our TileMap is rendered
75  // An SDL Surface contains pixel data to draw our TileMap
76  SDL_Surface *m_TileSpriteSheet;
77  SDL_Texture *m_Texture;
78  // Stores our tile types
79  int *m_Tiles;
80  int tileArray;
81  int imgWidth;
82  int imgHeight;
83  // SDL_Texture* mWinTexture;
84  // SDL_Texture* mCoinTexture;
85  std::map<int, std::vector<int>> tMap;
86  std::string tileMapPath;
87  std::vector<int> enemyCoordinates;
88  SDL_Texture* mCoinTexture;
89  SDL_Texture* mWinTexture;
90  //Create a ResourceManager instance
92 };
93 
94 #endif
std::shared_ptr< GameEntity > mainCharacter
Definition: Engine.cpp:51
The resource manager is responsible for handling and managing resources regarding the game.
Definition: ResourceManager.hpp:23
static ResourceManager & getInstance()
Method used to get instance of ResourceManager class.
Definition: ResourceManager.cpp:8
TileMap class is used to create and generate a map.
Definition: TileMap.hpp:20
void GenerateSimpleMap(std::vector< int > &collectablesAvailable)
Temporary function for generating a simple map to display some tiles.
Definition: TileMap.cpp:94
std::vector< int > getEnemyData()
Definition: TileMap.cpp:166
void PrintMap()
Function for printing text to console.
Definition: TileMap.cpp:135
void setTileSheetMap(int width, int height)
Helper function to set the tMap i.e.
Definition: TileMap.cpp:59
~TileMap()
Destructor for a tilemap.
Definition: TileMap.cpp:84
void Render(SDL_Renderer *ren, int x, std::vector< std::shared_ptr< GameEntity >> &obstacles, std::shared_ptr< GameEntity > mainCharacter)
Draw all of the tiles in the tilemap.
Definition: TileMap.cpp:177
TileMap(std::string tileSheetFileName, std::string _TileMapPath, int levelWidth, int levelHeight, int _TileSize, SDL_Renderer *ren)
Constuctor for a TileMap. Takes in a file path for a tile sheet, file for tile map path,...
Definition: TileMap.cpp:14
void SetTile(int x, int y, int type)
Set the 'type' of tile at an x and y position.
Definition: TileMap.cpp:152
int GetTileType(int x, int y)
Return the tile type at an x and y position.
Definition: TileMap.cpp:161