parent
e7ca641cbb
commit
c1baadc755
@ -1,29 +1,29 @@
|
|||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
//#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
#include "Bird.h"
|
//#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)
|
//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 = sf::Sprite(texture_list->at(0));
|
||||||
sprite.setPosition(position);
|
// sprite.setPosition(position);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void Bird::impulse(float p) {
|
//void Bird::impulse(float p) {
|
||||||
momentum = -p;
|
// momentum = -p;
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void Bird::tick(float step) {
|
//void Bird::tick(float step) {
|
||||||
momentum += gravity * step; // Impart gravity
|
// momentum += gravity * step; // Impart gravity
|
||||||
position.y += momentum;
|
// position.y += momentum;
|
||||||
sprite.setPosition(position);
|
// sprite.setPosition(position);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void Bird::draw(sf::RenderTarget &target, sf::RenderStates states) const {
|
//void Bird::draw(sf::RenderTarget &target, sf::RenderStates states) const {
|
||||||
target.draw(sprite, states);
|
// target.draw(sprite, states);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
bool Bird::collides(sf::FloatRect bounds)
|
//bool Bird::collides(sf::FloatRect bounds)
|
||||||
{
|
//{
|
||||||
return sprite.getGlobalBounds().intersects(bounds);
|
// return sprite.getGlobalBounds().intersects(bounds);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
#ifndef FLOPPY_BIRD_BIRD_H
|
//#ifndef FLOPPY_BIRD_BIRD_H
|
||||||
#define FLOPPY_BIRD_BIRD_H
|
//#define FLOPPY_BIRD_BIRD_H
|
||||||
|
//
|
||||||
#include <SFML/Graphics/Sprite.hpp>
|
//#include <SFML/Graphics/Sprite.hpp>
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
//#include <SFML/Graphics/Texture.hpp>
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
//#include <SFML/Graphics/RenderTarget.hpp>
|
||||||
#include <memory>
|
//#include <memory>
|
||||||
|
//
|
||||||
const float gravity = 9.8;
|
//const float gravity = 9.8;
|
||||||
|
//
|
||||||
class Bird : public sf::Drawable {
|
//class Bird : public sf::Drawable {
|
||||||
|
//
|
||||||
sf::Sprite sprite;
|
// sf::Sprite sprite;
|
||||||
std::shared_ptr<std::vector<sf::Texture>> texture_list;
|
// std::shared_ptr<std::vector<sf::Texture>> texture_list;
|
||||||
|
//
|
||||||
sf::Vector2f position;
|
// sf::Vector2f position;
|
||||||
float momentum;
|
// float momentum;
|
||||||
|
//
|
||||||
public:
|
//public:
|
||||||
Bird(float x, float y, const std::shared_ptr<std::vector<sf::Texture>> texture_list);
|
// Bird(float x, float y, const std::shared_ptr<std::vector<sf::Texture>> texture_list);
|
||||||
|
//
|
||||||
void impulse(float p);
|
// void impulse(float p);
|
||||||
void tick(float step);
|
// void tick(float step);
|
||||||
bool collides(sf::FloatRect bounds);
|
// bool collides(sf::FloatRect bounds);
|
||||||
|
//
|
||||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
|
//
|
||||||
#endif //FLOPPY_BIRD_BIRD_H
|
//#endif //FLOPPY_BIRD_BIRD_H
|
||||||
|
@ -1,38 +1,38 @@
|
|||||||
#include "Pipe.h"
|
//#include "Pipe.h"
|
||||||
|
//
|
||||||
#include <utility>
|
//#include <utility>
|
||||||
|
//
|
||||||
Pipe::Pipe(float x, float y,
|
//Pipe::Pipe(float x, float y,
|
||||||
std::shared_ptr<sf::Texture> pipe_top_texture_s,
|
// std::shared_ptr<sf::Texture> pipe_top_texture_s,
|
||||||
std::shared_ptr<sf::Texture> pipe_shaft_texture_s,
|
// std::shared_ptr<sf::Texture> pipe_shaft_texture_s,
|
||||||
std::shared_ptr<sf::Shader> pipe_shaft_shader_s) :
|
// std::shared_ptr<sf::Shader> pipe_shaft_shader_s) :
|
||||||
position(x, y),
|
// position(x, y),
|
||||||
pipe_top_texture(std::move(pipe_top_texture_s)),
|
// pipe_top_texture(std::move(pipe_top_texture_s)),
|
||||||
pipe_shaft_texture(std::move(pipe_shaft_texture_s)),
|
// pipe_shaft_texture(std::move(pipe_shaft_texture_s)),
|
||||||
pipe_shaft_shader(std::move(pipe_shaft_shader_s)),
|
// pipe_shaft_shader(std::move(pipe_shaft_shader_s)),
|
||||||
momentum(1.0)
|
// momentum(1.0)
|
||||||
{
|
//{
|
||||||
pipe_top = sf::Sprite(*pipe_top_texture);
|
// pipe_top = sf::Sprite(*pipe_top_texture);
|
||||||
pipe_shaft = sf::Sprite(*pipe_shaft_texture);
|
// pipe_shaft = sf::Sprite(*pipe_shaft_texture);
|
||||||
|
//
|
||||||
pipe_top.setPosition(position);
|
// pipe_top.setPosition(position);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void Pipe::tick(float step, float speed) {
|
//void Pipe::tick(float step, float speed) {
|
||||||
position.x += step * speed;
|
// position.x += step * speed;
|
||||||
pipe_top.setPosition(position);
|
// pipe_top.setPosition(position);
|
||||||
|
//
|
||||||
auto pos = pipe_top.getPosition();
|
// auto pos = pipe_top.getPosition();
|
||||||
pos.y += 25;
|
// pos.y += 25;
|
||||||
pipe_shaft.setPosition(pos);
|
// pipe_shaft.setPosition(pos);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void Pipe::draw(sf::RenderTarget &target, sf::RenderStates states) const{
|
//void Pipe::draw(sf::RenderTarget &target, sf::RenderStates states) const{
|
||||||
states.shader = &*pipe_shaft_shader;
|
// states.shader = &*pipe_shaft_shader;
|
||||||
target.draw(pipe_top, states);
|
// target.draw(pipe_top, states);
|
||||||
target.draw(pipe_shaft, states);
|
// target.draw(pipe_shaft, states);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
bool Pipe::collides(sf::FloatRect bounds) {
|
//bool Pipe::collides(sf::FloatRect bounds) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
//}
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
#ifndef FLOPPY_BIRD_PIPE_H
|
//#ifndef FLOPPY_BIRD_PIPE_H
|
||||||
#define FLOPPY_BIRD_PIPE_H
|
//#define FLOPPY_BIRD_PIPE_H
|
||||||
|
//
|
||||||
|
//
|
||||||
#include <SFML/Graphics/Sprite.hpp>
|
//#include <SFML/Graphics/Sprite.hpp>
|
||||||
#include <SFML/Graphics/Texture.hpp>
|
//#include <SFML/Graphics/Texture.hpp>
|
||||||
#include <SFML/Graphics/RenderTarget.hpp>
|
//#include <SFML/Graphics/RenderTarget.hpp>
|
||||||
#include <memory>
|
//#include <memory>
|
||||||
|
//
|
||||||
class Pipe : public sf::Drawable {
|
//class Pipe : public sf::Drawable {
|
||||||
|
//
|
||||||
sf::Sprite pipe_top;
|
// sf::Sprite pipe_top;
|
||||||
sf::Sprite pipe_shaft;
|
// sf::Sprite pipe_shaft;
|
||||||
|
//
|
||||||
std::shared_ptr<sf::Texture> pipe_top_texture;
|
// std::shared_ptr<sf::Texture> pipe_top_texture;
|
||||||
std::shared_ptr<sf::Texture> pipe_shaft_texture;
|
// std::shared_ptr<sf::Texture> pipe_shaft_texture;
|
||||||
|
//
|
||||||
std::shared_ptr<sf::Shader> pipe_shaft_shader;
|
// std::shared_ptr<sf::Shader> pipe_shaft_shader;
|
||||||
|
//
|
||||||
sf::Vector2f position;
|
// sf::Vector2f position;
|
||||||
float momentum;
|
// float momentum;
|
||||||
|
//
|
||||||
public:
|
//public:
|
||||||
Pipe(float x, float y, std::shared_ptr<sf::Texture> pipe_top_texture, std::shared_ptr<sf::Texture> pipe_shaft_texture, std::shared_ptr<sf::Shader> shader);
|
// Pipe(float x, float y, std::shared_ptr<sf::Texture> pipe_top_texture, std::shared_ptr<sf::Texture> pipe_shaft_texture, std::shared_ptr<sf::Shader> shader);
|
||||||
|
//
|
||||||
void tick(float step, float speed);
|
// void tick(float step, float speed);
|
||||||
bool collides(sf::FloatRect bounds);
|
// bool collides(sf::FloatRect bounds);
|
||||||
|
//
|
||||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
|
||||||
};
|
//};
|
||||||
|
//
|
||||||
|
//
|
||||||
#endif //FLOPPY_BIRD_PIPE_H
|
//#endif //FLOPPY_BIRD_PIPE_H
|
||||||
|
Loading…
Reference in new issue