You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
711 B
30 lines
711 B
2 years ago
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||
|
#include "Bird.h"
|
||
|
|
||
|
|
||
|
Bird::Bird(float x, float y, const std::shared_ptr<std::vector<sf::Texture>> texture_list) : position(x, y), texture_list(texture_list), momentum(1.0)
|
||
|
{
|
||
|
sprite = sf::Sprite(texture_list->at(0));
|
||
|
sprite.setPosition(position);
|
||
|
}
|
||
|
|
||
|
void Bird::impulse(float p) {
|
||
|
momentum = -p;
|
||
|
}
|
||
|
|
||
|
void Bird::tick(float step) {
|
||
|
momentum += gravity * step; // Impart gravity
|
||
|
position.y += momentum;
|
||
|
sprite.setPosition(position);
|
||
|
}
|
||
|
|
||
|
void Bird::draw(sf::RenderTarget &target, sf::RenderStates states) const {
|
||
|
target.draw(sprite, states);
|
||
|
}
|
||
|
|
||
|
bool Bird::collides(sf::FloatRect bounds)
|
||
|
{
|
||
|
return sprite.getGlobalBounds().intersects(bounds);
|
||
|
}
|
||
|
|