moving to magnum
This commit is contained in:
29
Bird.cpp
Normal file
29
Bird.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user