-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.hpp
executable file
·83 lines (65 loc) · 2.21 KB
/
tile.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
#ifndef TILE_HPP
#define TILE_HPP
#include <SFML/Graphics.hpp>
#include <vector>
#include "animation_handler.hpp"
enum class TileType { VOID, GRASS, FOREST, WATER, RESIDENTIAL, COMMERCIAL, INDUSTRIAL, ROAD };
std::string tileTypeToStr(TileType type);
class Tile
{
public:
AnimationHandler animHandler;
sf::Sprite sprite;
TileType tileType;
/* Tile variant, allowing for different looking versions of the
* same tile */
int tileVariant;
/* Region IDs of the tile, tiles in the same region are connected.
* First is for transport */
unsigned int regions[1];
/* Placement cost of the tile */
unsigned int cost;
/* Current residents / employees */
double population;
/* Maximum population per growth stage / tile variant */
unsigned int maxPopPerLevel;
/* Maximum number of building levels */
unsigned int maxLevels;
/* Production output per customer/worker per day, either monetary or goods */
float production;
/* Goods stored */
float storedGoods;
/* Constructor */
Tile() { }
Tile(const unsigned int tileSize, const unsigned int height, sf::Texture& texture,
const std::vector<Animation>& animations,
const TileType tileType, const unsigned int cost, const unsigned int maxPopPerLevel,
const unsigned int maxLevels)
{
this->tileType = tileType;
this->tileVariant = 0;
this->regions[0] = 0;
this->cost = cost;
this->population = 0;
this->maxPopPerLevel = maxPopPerLevel;
this->maxLevels = maxLevels;
this->production = 0;
this->storedGoods = 0;
this->sprite.setOrigin(sf::Vector2f(0.0f, tileSize*(height-1)));
this->sprite.setTexture(texture);
this->animHandler.frameSize = sf::IntRect(0, 0, tileSize*2, tileSize*height);
for(auto animation : animations)
{
this->animHandler.addAnim(animation);
}
this->animHandler.update(0.0f);
}
void draw(sf::RenderWindow& window, float dt);
void update();
/* Return a string containing the display cost of the tile */
std::string getCost()
{
return std::to_string(this->cost);
}
};
#endif /* TILE_HPP */