forked from stefanhendriks/Dune-II---The-Maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.hpp
91 lines (66 loc) · 2.46 KB
/
Map.hpp
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
82
83
84
85
86
87
88
89
90
91
#ifndef MAP_H
#define MAP_H
#include <iostream>
#include <cmath>
#include "Cell.hpp"
#include <array>
#include <SFML/Graphics.hpp>
#include <Thor/Vectors.hpp>
#include "Messages.hpp"
#define DEV_DRAWGRID true
class Map : public sf::Drawable{
public:
static const int MAX_SIZE = 65536; // 256X256 map
static const int MAX_WIDTH = 256;
static const int MAX_HEIGHT = 256;
static const int MIN_WIDTH = 32;
static const int MIN_HEIGHT = 32;
static const int LAYER_GROUND = 0;
static const int LAYER_AIR = 1;
static const int MAX_LAYERS = 2;
Map(sf::Texture& terrain, sf::Texture& shroudEdges, MessageSystem& messages);
void setBoundaries(int maxWidth, int maxHeight);
void load(std::string file);
void updateShroud();
void prepare(const sf::Vector2f &topLeft) const; //prepares the arrays for drawing
Cell& getCell(sf::Vector2i map_point) {
return getCell(map_point.x, map_point.y);
}
Cell& getCell(int x, int y) {
x = std::min(std::max(x, 0), (MAX_WIDTH-1));
y = std::min(std::max(y, 0), (MAX_HEIGHT-1));
int cell = (y * MAX_WIDTH) + x;
return cells[cell];
}
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void drawShrouded(sf::RenderTarget& target, sf::RenderStates states) const;
void removeShroud(sf::Vector2f world_point, int range) {
sf::Vector2i mapPoint = toMapPoint(world_point);
int x = mapPoint.x;
int y = mapPoint.y;
for (int cell_x = std::max(x - range, 0); cell_x <= std::min(x + range, maxWidth -1); cell_x++) {
for (int cell_y = std::max(y - range, 0); cell_y <= std::min(y + range, maxHeight -1); cell_y++) {
if (std::pow(cell_x - x, 2) + std::pow(cell_y - y, 2) <= std::pow(range, 2) + 1) {
getCell(cell_x, cell_y).shrouded = false;
}
}
}
updateShroud();
}
sf::Vector2i toMapPoint(const sf::Vector2f& world_point) const;
int determineShroudEdge(Cell &c);
int getMaxWidth() const;
int getMaxHeight() const;
private:
std::array<Cell, MAX_SIZE> cells; //why not vector? -Koji
int maxWidth;
int maxHeight;
sf::Texture& terrain;
sf::Texture& shroudEdges;
mutable std::vector<sf::Vertex> vertexArray;
mutable std::vector<sf::Vertex> shroudArray;
MessageSystem& messages;
int determineCellTile(Cell &cell);
int determineTerrainTile(bool cellUp, bool cellDown, bool cellLeft, bool cellRight) const;
};
#endif