-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemySpawnerTile.cpp
More file actions
120 lines (94 loc) · 2.34 KB
/
EnemySpawnerTile.cpp
File metadata and controls
120 lines (94 loc) · 2.34 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "stdafx.h"
#include "EnemySpawnerTile.h"
//Constructors and Destructor:
EnemySpawnerTile::EnemySpawnerTile
(
int grid_x, int grid_y, float grid_size_f,
const sf::Texture& texture, const sf::IntRect& texture_rect,
int enemy_type, int enemy_amount, int32_t enemy_time_to_spawn, float enemy_distance_max
)
: Tile(static_cast<int>(TileTypes::EnemySpawner), grid_x, grid_y, grid_size_f, texture, texture_rect, false)
{
this->enemyType = enemy_type;
this->enemyAmount = enemy_amount;
this->enemyCounter = 0;
this->enemySpawnTimer.restart();
this->enemyTimeToSpawn = enemy_time_to_spawn;
this->enemyDistanceMax = enemy_distance_max;
this->spawned = false;
}
EnemySpawnerTile::~EnemySpawnerTile()
{
}
//Accessors:
const std::string EnemySpawnerTile::getAsString() const
{
std::stringstream ss;
ss << this->type << " " << this->shape.getTextureRect().left << " " << this->shape.getTextureRect().top
<< " " << this->enemyType << " " << this->enemyAmount << " " << this->enemyTimeToSpawn << " " << this->enemyDistanceMax;
return ss.str();
}
const bool& EnemySpawnerTile::getSpawned() const
{
return this->spawned;
}
const int& EnemySpawnerTile::getEnemyCounter() const
{
return this->enemyCounter;
}
const int& EnemySpawnerTile::getEnemyAmount() const
{
return this->enemyAmount;
}
const bool EnemySpawnerTile::canSpawn() const
{
if (this->enemySpawnTimer.getElapsedTime().asMilliseconds() >= this->enemyTimeToSpawn
&& this->enemyCounter < this->enemyAmount)
{
return true;
}
return false;
}
//Modifiers:
void EnemySpawnerTile::setSpawned(const bool spawned)
{
this->spawned = spawned;
this->enemySpawnTimer.restart();
}
//Functions:
void EnemySpawnerTile::increaseEnemyCounter()
{
++this->enemyCounter;
if (this->enemyCounter > this->enemyAmount)
{
this->enemyCounter = this->enemyAmount;
}
}
void EnemySpawnerTile::decreaseEnemyCounter()
{
--this->enemyCounter;
if (this->enemyCounter < 0)
{
this->enemyCounter = 0;
}
}
void EnemySpawnerTile::update(const float& dt)
{
if (this->canSpawn())
{
this->spawned = false;
}
}
void EnemySpawnerTile::render(sf::RenderTarget& target, sf::Shader* shader, const sf::Vector2f player_position)
{
if (shader)
{
shader->setUniform("hasTexture", true);
shader->setUniform("lightPos", player_position);
target.draw(this->shape, shader);
}
else
{
target.draw(this->shape);
}
}