-
Notifications
You must be signed in to change notification settings - Fork 0
/
Platform.cpp
87 lines (70 loc) · 1.58 KB
/
Platform.cpp
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
#include "Platform.h"
float const Platform::BASE_FALL_SPEED = 1.7f;
float Platform::FALL_SPEED_MULT = 1.0f;
float Platform::m_fallSpeed = 1.7f;
Platform::Platform(sf::Texture texture):
m_texture(texture)
{
m_offset = rand() % 10 +1;
m_randX = rand() % 500 + 100;
m_position = sf::Vector2f(m_randX, -10.0f);
initSprite(m_position);
}
Platform::Platform(sf::Texture texture, float x, float y, float width, float height)
: m_position(x, y)
, m_texture(texture)
{
m_offset = 0.0f;
m_randX = 0.0f;
m_sprite.setPosition(m_position);
m_sprite.setTexture(m_texture);
}
Platform::~Platform()
{
}
void Platform::draw(sf::RenderWindow & window)
{
window.draw(m_sprite);
}
void Platform::update(const sf::Time& dt)
{
time += dt;
if (time > PLATFORM_PROGRESSION_TIME)
{
m_fallSpeed += 0.2;
//m_previousFallSpeed = m_fallSpeed;
}
m_sprite.setPosition(m_position);
m_position.y+=m_fallSpeed;
}
/// Check if platform is off screen
bool Platform::getOffScreen(sf::RenderWindow& window)
{
if (m_position.y > window.getSize().y + 50)
{
return true;
}
return m_offScreen;
}
///returns a bool representing if you can spawn the next platform.
bool Platform::getNextPlatform()
{
return m_nextPlatform;
}
sf::Vector2f Platform::getPosition() const
{
return m_position;
}
void Platform::initSprite(sf::Vector2f & pos)
{
m_sprite.setTexture(m_texture);
m_sprite.setPosition(pos);
m_sprite.setScale(1.0f + (m_offset / 10), 1);
}
sf::FloatRect Platform::getBounds() const
{
sf::FloatRect rect = m_sprite.getGlobalBounds();
rect.left = m_position.x;
rect.top = m_position.y;
return rect;
}