-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatform.cpp
More file actions
68 lines (55 loc) · 1.85 KB
/
Platform.cpp
File metadata and controls
68 lines (55 loc) · 1.85 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
#include "Platform.hpp"
#include "DEFINITIONS.h"
namespace ArktisProductions
{
Platform::Platform(GameDataRef data) : _data(data)
{
}
void Platform::spawnPlatform()
{
sf::Sprite sprite(this->_data->assets.GetTexture("brick_floor"));
float y_coordinate;
while(true)
{
y_coordinate = RANDOM_PLATFORM_Y_COORDINATE;
if (y_coordinate < MAX_PLATFORM_HEIGHT)
break;
}
sprite.setPosition(FIXED_PLATFORM_X_COORDINATE, y_coordinate);
platformSprites.push_back(sprite);
}
void Platform::spawnInvisiblePlatform()
{
sf::Sprite sprite(this->_data->assets.GetTexture("brick_floor"));
sprite.setPosition(this->_data->window.getSize().x, 0);
sprite.setColor(sf::Color(0, 0, 0, 0));
platformSprites.push_back(sprite);
}
void Platform::movePlatforms(float dt)
{
for (unsigned short int i = 0; i < platformSprites.size(); i++)
{
if (platformSprites.at(i).getPosition().x < 0 - platformSprites.at(i).getGlobalBounds().width)
platformSprites.erase(platformSprites.begin()+i);
else
{
// sf::Vector2f position = platformSprites.at(i).getPosition();
float mvmt = PLATFORM_MVMT_SPEED * dt;
platformSprites.at(i).move(-mvmt, 0);
}
}
}
void Platform::DrawPlatforms()
{
for (unsigned short int i = 0; i < platformSprites.size(); i++)
this->_data->window.draw(platformSprites.at(i));
}
void Platform::PurgePlatforms()
{
this->platformSprites.clear();
}
const std::vector<sf::Sprite> &Platform::GetSprites() const
{
return this->platformSprites;
}
}