-
Notifications
You must be signed in to change notification settings - Fork 0
/
land.cpp
42 lines (36 loc) · 1003 Bytes
/
land.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
#include <iostream>
#include "land.hpp"
#include "definitions.hpp"
Land::Land(gameDataPtr data):
data_(std::move(data))
{
sf::Sprite sprite(data_->assets_.getTexture("Land"));
sf::Sprite nextSprite(data_->assets_.getTexture("Land"));
sprite.setPosition(0, data_->window_.getSize().y - sprite.getGlobalBounds().height);
nextSprite.setPosition(sprite.getGlobalBounds().width, data_->window_.getSize().y - nextSprite.getGlobalBounds().height);
sprites_.push_back(sprite);
sprites_.push_back(nextSprite);
}
void Land::move(float dt)
{
for(auto & sprite : sprites_)
{
float movement = PIPE_MOVEMENT_SPEED * dt;
sprite.move(-movement, 0);
if(sprite.getPosition().x < 0 - sprite.getGlobalBounds().width)
{
sprite.setPosition(data_->window_.getSize().x, sprite.getPosition().y);
}
}
}
void Land::draw()
{
for(auto & sprite : sprites_)
{
data_->window_.draw(sprite);
}
}
const std::vector<sf::Sprite>& Land::getSprites() const
{
return sprites_;
}