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
|
||||||
|
@ -1,179 +1,206 @@
|
|||||||
#include <SFML/Window.hpp>
|
|
||||||
#include <SFML/Graphics.hpp>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "Bird.h"
|
#include "Bird.h"
|
||||||
#include "Pipe.h"
|
#include "Pipe.h"
|
||||||
|
#include "Magnum/GL/Renderer.h"
|
||||||
|
#include "Magnum/Math/Color.h"
|
||||||
|
|
||||||
#ifdef linux
|
#ifdef linux
|
||||||
#elif defined _WIN32
|
#elif defined _WIN32
|
||||||
#elif defined TARGET_OS_MAC
|
#elif defined TARGET_OS_MAC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const float g = 7.8;
|
#include <Magnum/GL/DefaultFramebuffer.h>
|
||||||
const int WINDOW_X = 600;
|
#include <Magnum/Platform/Sdl2Application.h>
|
||||||
const int WINDOW_Y = 800;
|
|
||||||
|
|
||||||
float elap_time() {
|
|
||||||
static std::chrono::time_point<std::chrono::system_clock> start;
|
|
||||||
static bool started = false;
|
|
||||||
|
|
||||||
if (!started) {
|
|
||||||
start = std::chrono::system_clock::now();
|
|
||||||
started = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
|
using namespace Magnum;
|
||||||
std::chrono::duration<double> elapsed_time = now - start;
|
|
||||||
return static_cast<float>(elapsed_time.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
std::mt19937 rng(time(NULL));
|
|
||||||
std::uniform_int_distribution<int> rgen(100, 400);
|
|
||||||
|
|
||||||
int pipe_dist = 200;
|
|
||||||
|
|
||||||
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "flappy");
|
class MyApplication: public Platform::Application {
|
||||||
|
public:
|
||||||
|
explicit MyApplication(const Arguments& arguments);
|
||||||
|
|
||||||
std::shared_ptr<std::vector<sf::Texture>> texture_list = std::make_shared<std::vector<sf::Texture>>();
|
private:
|
||||||
for (int i = 0; i < 4; i++) {
|
void drawEvent() override;
|
||||||
sf::Texture t;
|
};
|
||||||
t.loadFromFile("../Assets/bird.png", sf::IntRect(0, i*12, 34, 24));
|
|
||||||
texture_list->push_back(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init flappy
|
MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} {
|
||||||
Bird bird(WINDOW_X/2, WINDOW_Y/2, texture_list);
|
/* TODO: Add your initialization code here */
|
||||||
|
|
||||||
std::list<Pipe> pipes;
|
|
||||||
|
|
||||||
// Init world
|
|
||||||
sf::Texture background = sf::Texture(); background.loadFromFile("../Assets/sky.png");
|
|
||||||
sf::Sprite background_sprite = sf::Sprite(background); background_sprite.setPosition(0, 0); background_sprite.setScale(8, 8);
|
|
||||||
sf::Texture land = sf::Texture(); land.loadFromFile("../Assets/land.png");
|
|
||||||
sf::Sprite land_sprite = sf::Sprite(land); land_sprite.setPosition(0, WINDOW_Y - WINDOW_Y / 10); land_sprite.setScale(3, 2);
|
|
||||||
sf::Texture pipe_up, pipe_down = sf::Texture(); pipe_down.loadFromFile("../Assets/pipe-down.png"); pipe_up.loadFromFile("../Assets/pipe-up.png");
|
|
||||||
sf::Sprite pipe_up_sprite = sf::Sprite(pipe_up); sf::Sprite pipe_down_sprite = sf::Sprite(pipe_down);
|
|
||||||
sf::Texture pipe_shaft = sf::Texture(); pipe_shaft.loadFromFile("../Assets/pipe.png");
|
|
||||||
sf::Sprite pipe_shaft_sprite = sf::Sprite(pipe_shaft);
|
|
||||||
|
|
||||||
double momentum = 0;
|
|
||||||
float step_size = 0.005f;
|
|
||||||
double frame_time = 0.0, elapsed_time = 0.0, delta_time = 0.0, accumulator_time = 0.0, current_time = 0.0;
|
|
||||||
float speed = 250;
|
|
||||||
|
|
||||||
std::shared_ptr<sf::Shader> shader = std::make_shared<sf::Shader>();
|
|
||||||
if (!shader->loadFromFile("/home/mrh/source/floppy-bird/Assets/shaders/pipe_shader.vert", "/home/mrh/source/floppy-bird/Assets/shaders/pipe_shader.frag"))
|
|
||||||
{
|
|
||||||
std::cout << "asodijfoqijwef" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (window.isOpen())
|
void MyApplication::drawEvent() {
|
||||||
{
|
|
||||||
sf::Event event; // Handle input
|
|
||||||
while (window.pollEvent(event)) {
|
|
||||||
if (event.type == sf::Event::Closed)
|
|
||||||
window.close();
|
|
||||||
if (event.type == sf::Event::MouseWheelScrolled)
|
|
||||||
if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel)
|
|
||||||
speed += event.mouseWheelScroll.delta * 20;
|
|
||||||
if(event.type == sf::Event::KeyPressed)
|
|
||||||
if (event.key.code == sf::Keyboard::Space)
|
|
||||||
bird.impulse(3.0);
|
|
||||||
if (event.type == sf::Event::MouseButtonPressed) {
|
|
||||||
if (event.mouseButton.button == sf::Mouse::Right)
|
|
||||||
pipe_dist -= 10;
|
|
||||||
if (event.mouseButton.button == sf::Mouse::Middle)
|
|
||||||
pipe_dist += 10;
|
|
||||||
if (event.mouseButton.button == sf::Mouse::Left)
|
|
||||||
bird.impulse(3.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
elapsed_time = elap_time(); // Handle time
|
Color4 r;
|
||||||
delta_time = elapsed_time - current_time;
|
GL::Renderer::setClearColor(Color4::red());
|
||||||
current_time = elapsed_time;
|
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color);
|
||||||
if (delta_time > 0.02f) {
|
|
||||||
delta_time = 0.02f;
|
|
||||||
}
|
|
||||||
accumulator_time += delta_time;
|
|
||||||
|
|
||||||
while ((accumulator_time - step_size) >= step_size) { // While the frame has sim time, update
|
|
||||||
accumulator_time -= step_size;
|
|
||||||
|
|
||||||
if (pipe_down_sprite.getPosition().x < -pipe_down_sprite.getGlobalBounds().width) {
|
|
||||||
pipe_down_sprite.setPosition(WINDOW_X, rgen(rng));
|
|
||||||
pipe_up_sprite.setPosition(WINDOW_X, pipe_down_sprite.getPosition().y + pipe_dist);
|
|
||||||
|
|
||||||
pipes.emplace_back(100, 100, std::make_shared<sf::Texture>(pipe_up), std::make_shared<sf::Texture>(pipe_shaft), shader);
|
swapBuffers();
|
||||||
std::cout << "added one" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pipe_up_sprite.setPosition(pipe_up_sprite.getPosition().x - step_size * speed, pipe_up_sprite.getPosition().y);
|
|
||||||
pipe_down_sprite.setPosition(pipe_down_sprite.getPosition().x - step_size * speed, pipe_down_sprite.getPosition().y);
|
|
||||||
}
|
|
||||||
if (background_sprite.getPosition().x + background_sprite.getGlobalBounds().width < WINDOW_X) {
|
|
||||||
background_sprite.setPosition(0, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
background_sprite.setPosition(background_sprite.getPosition().x - step_size * (speed - 100), background_sprite.getPosition().y);
|
|
||||||
if (land_sprite.getPosition().x + 10 + land_sprite.getGlobalBounds().width < WINDOW_X)
|
|
||||||
land_sprite.setPosition(14, land_sprite.getPosition().y);
|
|
||||||
else
|
|
||||||
land_sprite.setPosition(land_sprite.getPosition().x - step_size * speed, land_sprite.getPosition().y);
|
|
||||||
|
|
||||||
// Check collisions
|
|
||||||
if (bird.collides(pipe_up_sprite.getGlobalBounds()) ||
|
|
||||||
bird.collides(pipe_down_sprite.getGlobalBounds()) ||
|
|
||||||
bird.collides(land_sprite.getGlobalBounds())
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//std::cout << "dead!!!!!!!!" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
bird.tick(step_size);
|
|
||||||
for (auto pipe = pipes.begin(); pipe != pipes.end(); ++pipe)
|
|
||||||
{
|
|
||||||
pipe->tick(step_size, speed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window.draw(background_sprite, &*shader); // Render
|
|
||||||
window.draw(land_sprite);
|
|
||||||
window.draw(bird);
|
|
||||||
window.draw(pipe_up_sprite);
|
|
||||||
window.draw(pipe_down_sprite);
|
|
||||||
|
|
||||||
for (auto ptr = pipes.begin(); ptr != pipes.end(); ++ptr)
|
|
||||||
{
|
|
||||||
window.draw(*ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
pipe_shaft_sprite.setPosition(pipe_up_sprite.getPosition()); // Render the bottom pipe
|
|
||||||
int y_pos = pipe_up_sprite.getPosition().y + pipe_up_sprite.getGlobalBounds().height;
|
|
||||||
while (y_pos < WINDOW_Y) {
|
|
||||||
pipe_shaft_sprite.setPosition(pipe_shaft_sprite.getPosition().x, y_pos);
|
|
||||||
y_pos++;
|
|
||||||
window.draw(pipe_shaft_sprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
y_pos = pipe_down_sprite.getPosition().y; // Render the top pipe
|
MAGNUM_APPLICATION_MAIN(MyApplication)
|
||||||
while (y_pos > 0) {
|
|
||||||
pipe_shaft_sprite.setPosition(pipe_shaft_sprite.getPosition().x, y_pos);
|
|
||||||
y_pos--;
|
|
||||||
window.draw(pipe_shaft_sprite);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.display();
|
|
||||||
|
|
||||||
|
const float g = 7.8;
|
||||||
|
const int WINDOW_X = 600;
|
||||||
|
const int WINDOW_Y = 800;
|
||||||
|
|
||||||
|
float elap_time() {
|
||||||
|
static std::chrono::time_point<std::chrono::system_clock> start;
|
||||||
|
static bool started = false;
|
||||||
|
|
||||||
|
if (!started) {
|
||||||
|
start = std::chrono::system_clock::now();
|
||||||
|
started = true;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
|
||||||
|
std::chrono::duration<double> elapsed_time = now - start;
|
||||||
|
return static_cast<float>(elapsed_time.count());
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
//int main()
|
||||||
|
//{
|
||||||
|
// std::mt19937 rng(time(NULL));
|
||||||
|
// std::uniform_int_distribution<int> rgen(100, 400);
|
||||||
|
//
|
||||||
|
// int pipe_dist = 200;
|
||||||
|
|
||||||
|
//sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "flappy");
|
||||||
|
|
||||||
|
// std::shared_ptr<std::vector<sf::Texture>> texture_list = std::make_shared<std::vector<sf::Texture>>();
|
||||||
|
// for (int i = 0; i < 4; i++) {
|
||||||
|
// sf::Texture t;
|
||||||
|
// t.loadFromFile("../Assets/bird.png", sf::IntRect(0, i*12, 34, 24));
|
||||||
|
// texture_list->push_back(t);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Init flappy
|
||||||
|
// Bird bird(WINDOW_X/2, WINDOW_Y/2, texture_list);
|
||||||
|
//
|
||||||
|
// std::list<Pipe> pipes;
|
||||||
|
//
|
||||||
|
// // Init world
|
||||||
|
// sf::Texture background = sf::Texture(); background.loadFromFile("../Assets/sky.png");
|
||||||
|
// sf::Sprite background_sprite = sf::Sprite(background); background_sprite.setPosition(0, 0); background_sprite.setScale(8, 8);
|
||||||
|
// sf::Texture land = sf::Texture(); land.loadFromFile("../Assets/land.png");
|
||||||
|
// sf::Sprite land_sprite = sf::Sprite(land); land_sprite.setPosition(0, WINDOW_Y - WINDOW_Y / 10); land_sprite.setScale(3, 2);
|
||||||
|
// sf::Texture pipe_up, pipe_down = sf::Texture(); pipe_down.loadFromFile("../Assets/pipe-down.png"); pipe_up.loadFromFile("../Assets/pipe-up.png");
|
||||||
|
// sf::Sprite pipe_up_sprite = sf::Sprite(pipe_up); sf::Sprite pipe_down_sprite = sf::Sprite(pipe_down);
|
||||||
|
// sf::Texture pipe_shaft = sf::Texture(); pipe_shaft.loadFromFile("../Assets/pipe.png");
|
||||||
|
// sf::Sprite pipe_shaft_sprite = sf::Sprite(pipe_shaft);
|
||||||
|
//
|
||||||
|
// double momentum = 0;
|
||||||
|
// float step_size = 0.005f;
|
||||||
|
// double frame_time = 0.0, elapsed_time = 0.0, delta_time = 0.0, accumulator_time = 0.0, current_time = 0.0;
|
||||||
|
// float speed = 250;
|
||||||
|
//
|
||||||
|
// std::shared_ptr<sf::Shader> shader = std::make_shared<sf::Shader>();
|
||||||
|
// if (!shader->loadFromFile("/home/mrh/source/floppy-bird/Assets/shaders/pipe_shader.vert", "/home/mrh/source/floppy-bird/Assets/shaders/pipe_shader.frag"))
|
||||||
|
// {
|
||||||
|
// std::cout << "asodijfoqijwef" << std::endl;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// while (window.isOpen())
|
||||||
|
// {
|
||||||
|
// sf::Event event; // Handle input
|
||||||
|
// while (window.pollEvent(event)) {
|
||||||
|
// if (event.type == sf::Event::Closed)
|
||||||
|
// window.close();
|
||||||
|
// if (event.type == sf::Event::MouseWheelScrolled)
|
||||||
|
// if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel)
|
||||||
|
// speed += event.mouseWheelScroll.delta * 20;
|
||||||
|
// if(event.type == sf::Event::KeyPressed)
|
||||||
|
// if (event.key.code == sf::Keyboard::Space)
|
||||||
|
// bird.impulse(3.0);
|
||||||
|
// if (event.type == sf::Event::MouseButtonPressed) {
|
||||||
|
// if (event.mouseButton.button == sf::Mouse::Right)
|
||||||
|
// pipe_dist -= 10;
|
||||||
|
// if (event.mouseButton.button == sf::Mouse::Middle)
|
||||||
|
// pipe_dist += 10;
|
||||||
|
// if (event.mouseButton.button == sf::Mouse::Left)
|
||||||
|
// bird.impulse(3.0);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// elapsed_time = elap_time(); // Handle time
|
||||||
|
// delta_time = elapsed_time - current_time;
|
||||||
|
// current_time = elapsed_time;
|
||||||
|
// if (delta_time > 0.02f) {
|
||||||
|
// delta_time = 0.02f;
|
||||||
|
// }
|
||||||
|
// accumulator_time += delta_time;
|
||||||
|
//
|
||||||
|
// while ((accumulator_time - step_size) >= step_size) { // While the frame has sim time, update
|
||||||
|
// accumulator_time -= step_size;
|
||||||
|
//
|
||||||
|
// if (pipe_down_sprite.getPosition().x < -pipe_down_sprite.getGlobalBounds().width) {
|
||||||
|
// pipe_down_sprite.setPosition(WINDOW_X, rgen(rng));
|
||||||
|
// pipe_up_sprite.setPosition(WINDOW_X, pipe_down_sprite.getPosition().y + pipe_dist);
|
||||||
|
//
|
||||||
|
// pipes.emplace_back(100, 100, std::make_shared<sf::Texture>(pipe_up), std::make_shared<sf::Texture>(pipe_shaft), shader);
|
||||||
|
// std::cout << "added one" << std::endl;
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// pipe_up_sprite.setPosition(pipe_up_sprite.getPosition().x - step_size * speed, pipe_up_sprite.getPosition().y);
|
||||||
|
// pipe_down_sprite.setPosition(pipe_down_sprite.getPosition().x - step_size * speed, pipe_down_sprite.getPosition().y);
|
||||||
|
// }
|
||||||
|
// if (background_sprite.getPosition().x + background_sprite.getGlobalBounds().width < WINDOW_X) {
|
||||||
|
// background_sprite.setPosition(0, 0);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// background_sprite.setPosition(background_sprite.getPosition().x - step_size * (speed - 100), background_sprite.getPosition().y);
|
||||||
|
// if (land_sprite.getPosition().x + 10 + land_sprite.getGlobalBounds().width < WINDOW_X)
|
||||||
|
// land_sprite.setPosition(14, land_sprite.getPosition().y);
|
||||||
|
// else
|
||||||
|
// land_sprite.setPosition(land_sprite.getPosition().x - step_size * speed, land_sprite.getPosition().y);
|
||||||
|
//
|
||||||
|
// // Check collisions
|
||||||
|
// if (bird.collides(pipe_up_sprite.getGlobalBounds()) ||
|
||||||
|
// bird.collides(pipe_down_sprite.getGlobalBounds()) ||
|
||||||
|
// bird.collides(land_sprite.getGlobalBounds())
|
||||||
|
// )
|
||||||
|
// {
|
||||||
|
// //std::cout << "dead!!!!!!!!" << std::endl;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// bird.tick(step_size);
|
||||||
|
// for (auto pipe = pipes.begin(); pipe != pipes.end(); ++pipe)
|
||||||
|
// {
|
||||||
|
// pipe->tick(step_size, speed);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// window.draw(background_sprite, &*shader); // Render
|
||||||
|
// window.draw(land_sprite);
|
||||||
|
// window.draw(bird);
|
||||||
|
// window.draw(pipe_up_sprite);
|
||||||
|
// window.draw(pipe_down_sprite);
|
||||||
|
//
|
||||||
|
// for (auto ptr = pipes.begin(); ptr != pipes.end(); ++ptr)
|
||||||
|
// {
|
||||||
|
// window.draw(*ptr);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// pipe_shaft_sprite.setPosition(pipe_up_sprite.getPosition()); // Render the bottom pipe
|
||||||
|
// int y_pos = pipe_up_sprite.getPosition().y + pipe_up_sprite.getGlobalBounds().height;
|
||||||
|
// while (y_pos < WINDOW_Y) {
|
||||||
|
// pipe_shaft_sprite.setPosition(pipe_shaft_sprite.getPosition().x, y_pos);
|
||||||
|
// y_pos++;
|
||||||
|
// window.draw(pipe_shaft_sprite);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// y_pos = pipe_down_sprite.getPosition().y; // Render the top pipe
|
||||||
|
// while (y_pos > 0) {
|
||||||
|
// pipe_shaft_sprite.setPosition(pipe_shaft_sprite.getPosition().x, y_pos);
|
||||||
|
// y_pos--;
|
||||||
|
// window.draw(pipe_shaft_sprite);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// window.display();
|
||||||
|
// }
|
||||||
|
// return 0;
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
Loading…
Reference in new issue