-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileMap.h
More file actions
82 lines (60 loc) · 2.53 KB
/
TileMap.h
File metadata and controls
82 lines (60 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once
#include "RegularTile.h"
#include "Pawn.h"
class TileMap
{
private:
//Variables:
float gridSizeF;
int gridSizeI;
sf::Vector2i maxSizeWorldGrid;
sf::Vector2f maxSizeWorldF;
int layers;
std::vector< std::vector< std::vector< std::vector<Tile*> > > > map;
std::stack<Tile*> defferedRenderStack;
std::string textureFilePath;
sf::Texture tileSheet;
sf::RectangleShape collisionBox;
//Culling
int fromX;
int toX;
int fromY;
int toY;
int layer;
//private: Functions:
//Clears the map.
void clearMap();
public:
//Constructors and Destructor:
TileMap(float grid_size, int width, int height, int layers, std::string texture_file_path);
//Should use '\\' instead of '/' in the file path and put this file to the .exe location,
//to be able to play the game without Visual Studio.
TileMap(const std::string file_path);
virtual ~TileMap();
//Accessors:
const bool tileEmpty (const int x, const int y, const int z) const;
const sf::Texture* getTileSheet() const;
const int getLayerSize(const int x, const int y, const int layer) const;
const int& getLayer();
const sf::Vector2i& getMaxSizeGrid() const;
const sf::Vector2f& getMaxSizeF() const;
const bool checkType(const int x, const int y, const int z, const int type) const;
Tile* getTile(const int x, const int y, const int z) const;
Tile* getTile(const int x, const int y) const;
//Functions:
// Tekes three indices frpm the mouse position in the grid and adds a tile to that position,
// if the internal tilemap array allows it.
void addTile(const int x, const int y, const int z, const sf::IntRect& texture_rect, const bool collision, const int type);
// Tekes three indices frpm the mouse position in the grid and removes a tile on that position,
// if the internal tilemap array allows it.
void removeTile(const int x, const int y, const int z, const int type = -1);
void saveToFile(const std::string file_path);
void loadFromFile(const std::string file_path);
void updateWorldBoundsCollision(Entity* entity, const float& dt);
void updateTileCollision(Entity* entity, const float& dt);
void updateTiles(Entity* entity, const float& dt);
void updateCapturing(Entity* entity, const float& dt);
void update(Entity* entity, const float& dt);
void render(sf::RenderTarget* target, const sf::Vector2i& grid_position, sf::Shader* shader = nullptr, const sf::Vector2f player_position = sf::Vector2f(), const bool show_collision = false);
void renderDeffered(sf::RenderTarget* target, sf::Shader* shader = nullptr, const sf::Vector2f player_position = sf::Vector2f());
};