Dev C++ Flappy Bird

Dev C++ Flappy Bird

  1. Program Flappy Bird
  2. Dev C++ Flappy Bird Download

Nov 06, 2017  This video shows an implementation of, sigh, Flappy Bird in C at the command prompt. Source: https://github.com/OneLoneCoder/videos/blob/master/OneLoneCode. I'm programming a game in C that's supposed to be something like the smartphone game 'Flappy Bird'. You who have played it knows its about avoiding approaching obstacles with gaps in them, with a bird thats constantly moving downwards, and you have to click a button to keep it in the air. How to create a flappy bird tutorial was one of the first tutorial we did on this website, we are back now with a new one where we will show you how to make a new and improved version of flappy bird using Microsoft Visual Studio, WPF and C#. In this game you will have your standard pipes and a gap between them where the bird will fly through.

  1. #include <string>
  2. #include <fstream>
  3. #include <ctime>
  4. public:
  5. bird_x =100;
  6. bird[0].setFillColor(sf::Color::Red);
  7. bird[1].setFillColor(sf::Color::Yellow);
  8. bird[1].setPosition(bird_x +71, bird_y +20);
  9. bird.push_back(sf::CircleShape(3.f));
  10. bird[2].setPosition(bird_x +20, bird_y +10);
  11. void getPosition(float*x, float*y){
  12. *y = bird_y +15;
  13. void moveVertically(float mov){
  14. for(unsignedint i =0; i < bird.size(); i++){
  15. }
  16. std::vector<sf::CircleShape> getBirdVector(){
  17. }
  18. std::vector<sf::CircleShape> bird;
  19. float bird_y;
  20. public:
  21. Pipe(unsignedint space, unsignedint window_width, unsignedint window_height){
  22. printf('Spawning new pipe with gap from %u to %un', space -100, space +100);
  23. upper_pipe =new sf::RectangleShape(sf::Vector2f(100, space -100));
  24. lower_pipe =new sf::RectangleShape(sf::Vector2f(100, window_height - space -100));
  25. upper_pipe->setFillColor(sf::Color::Green);
  26. controlled_space = space;
  27. upper_pipe->setPosition(current_x, 0);
  28. }
  29. bool checkIfCollision(float colliding_x, float colliding_y){
  30. if(colliding_x > current_x +50|| colliding_x < current_x -50)returnfalse;
  31. if(colliding_y < controlled_space +100&& colliding_y > controlled_space -100)returnfalse;
  32. }
  33. if(current_x <-100)returntrue;
  34. upper_pipe->move(-1, 0);
  35. returnfalse;
  36. void drawSelf(sf::RenderWindow*to_draw_to){
  37. to_draw_to->draw(*lower_pipe);
  38. }
  39. delete upper_pipe;
  40. }
  41. private:
  42. sf::RectangleShape*lower_pipe;
  43. unsignedint controlled_space;
  44. char*name =(char*)calloc(1, 1);
  45. printf('Enter your name: ');
  46. scanf('%c', &buf);
  47. name =(char*)realloc(name, strlen(name)+2);
  48. }
  49. savefile.open('.flappy_bird_save', std::ios::out| std::ios::app);
  50. savefile <<':';
  51. savefile.write((char*)(void*)(&score), sizeof(unsignedint));
  52. savefile.close();
  53. printf('LEADERBOARDn');
  54. unsignedint score;
  55. };
  56. char buf =0;
  57. while(savefile.good()){
  58. players.resize(players.size()+1);
  59. players[players.size()-1].name=(char*)calloc(1, 1);
  60. buf = savefile.get();
  61. players[players.size()-1].name=(char*)realloc(players[players.size()-1].name, strlen(players[players.size()-1].name)+2);
  62. players[players.size()-1].name[strlen(players[players.size()-1].name)]= buf;
  63. savefile.read((char*)(void*)&(players[players.size()-1].score), sizeof(unsignedint));
  64. }
  65. if(players.size()<3)return;//don't bother
  66. for(unsignedint i =0; i < players.size(); i++){
  67. if(players[pivot_pos].score0) pivot_pos -=1;
  68. if(players[i].score< players[pivot_pos].score){
  69. players.erase(players.begin()+ i);
  70. }
  71. for(unsignedint i =0; i < players.size()-2; i++){
  72. is_sorted =false;
  73. }
  74. if(is_sorted)break;
  75. if(players[i].score0)break;
  76. printf('%s:t%8un', players[i].name, players[i].score);
  77. }
  78. if(argc <2)return1;
  79. std::default_random_engine rand_generator;
  80. printf('Insert quarter to playn');
  81. unsignedint window_width =(argc <3)?1000:atoi(argv[2]);//we have to do it this way because SFML team is too lazy to let you
  82. unsignedint window_height =(argc <4)?800:atoi(argv[3]);//actually get the size of the window.
  83. sf::RenderWindow window(sf::VideoMode(window_width, window_height), argv[1]);//damn kids...
  84. std::uniform_int_distribution<int> pipe_pos_spawn(100, window_height -100);
  85. Bird protagonist;
  86. std::vector<Pipe> pipes;
  87. float protagonist_x;
  88. char*score_text =(char*)calloc(1, 11);
  89. sf::Time check_time;
  90. sf::RectangleShape*current_upper_pipe;
  91. if(!font.loadFromFile('Hack-Regular.ttf'))return1;
  92. score_view.setCharacterSize(32);
  93. score_view.setFillColor(sf::Color::White);
  94. score_view.setString('Score: '+ std::string(score_text));
  95. printf('Scoreview is currently %sn', score_view.getString().toAnsiString().c_str());
  96. pipe_pos_spawn(rand_generator);//throwaway first value
  97. protagonist.moveVertically(window_height /2);
  98. while(window.isOpen()){
  99. while(window.pollEvent(event)){
  100. if(event.type sf::Event::Closed) window.close();
  101. protagonist.getPosition(&protagonist_x, &protagonist_y);
  102. current_gravity_pull =(current_gravity_pull *2<16)? current_gravity_pull :16;
  103. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)&& protagonist_y >0){
  104. protagonist.moveVertically(-2);
  105. protagonist.moveVertically(current_gravity_pull);
  106. if(check_time.asMilliseconds()%10000){
  107. pipes.push_back(Pipe(pipe_pos_spawn(rand_generator), window_width, window_height));
  108. for(unsignedint i =0; i < protagonist_parts.size(); i++){//draw the bird
  109. }
  110. pipes[i].drawSelf(&window);
  111. printf('Update returned truen');
  112. pipes[i].~Pipe();
  113. score +=1;
  114. score_view.setString(std::string(score_text));
  115. printf('Scoreview is currently %sn', score_view.getString().toAnsiString().c_str());
  116. }elseif(pipes[i].checkIfCollision(protagonist_x, protagonist_y)|| protagonist_y >= window_height){
  117. window.close();
  118. return0;
  119. }
  120. window.display();
  121. return0;
PermalinkC++
  1. Sep 27, 2015  Flappy Bird in C (VS 2013). GitHub Gist: instantly share code, notes, and snippets. Skip to content. All gists Back to GitHub. Sign in Sign up Instantly share code, notes, and snippets. Soachishti / CPP-Flappy-Bird.cpp.
  2. The most accurate Flappy Bird clone out there. Made with love. Free to play, NOW! Mister Moonboots. Free game for the iPad by Mr Speaker: Like bouncing? The infinity of space?
  3. I wrote the code myself with Code.org.

Join GitHub today

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Sign upDev c++ flappy bird video
Branch:master
Find file Copy path

Program Flappy Bird

Fetching contributors…
#include<SFML/Graphics.hpp>
#include<SFMLAudio.hpp>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include'Pipes.h'
#include'GameOver.h'
Pipes::Pipes(int PositionX, int PositionY, int PipeDistance, int PipeAbove)
{
std::cout << 'hello!' << std::endl;
if (!PipeUp.loadFromFile('images/FlappyBird.png', sf::IntRect(84, 323, 26, 160)))
{
}
if (!PipeDown.loadFromFile('images/FlappyBird.png', sf::IntRect(56, 323, 26, 160)))
{
}
PipeSpriteUp.setTexture(PipeUp);
PipeSpriteUp.setScale(4,4);
PipeSpriteDown.setTexture(PipeDown);
PipeSpriteDown.setScale(4, 4);
PipeSpriteUp.setPosition(PositionX + PipeDistance, PositionY*1.4 );
PipeSpriteDown.setPosition(PositionX + PipeDistance, PositionY - PipeAbove + 160);
PipeGap = PipeAbove;
}
Pipes::~Pipes()
{
}
voidPipes::draw(sf::RenderWindow &window)
{
//srand((unsigned)time(NULL));
PipeSpriteUp.move(Speed, 0);
PipeSpriteDown.move(Speed, 0);
if (PipeSpriteUp.getPosition().x <= -100 && PipeSpriteDown.getPosition().x <= -100)
{
int Up = rand() % (600 + 1 - 300) + 300;
int Down = Up - PipeGap;
PipeSpriteUp.setPosition(800, Up);
PipeSpriteDown.setPosition(800, Down);
}
window.draw(PipeSpriteUp);
window.draw(PipeSpriteDown);
}
intPipes::OverlapTest(float FlappyBirdX, float FlappyBirdY)
{
constint left_box0 = FlappyBirdX;
constint right_box0 = FlappyBirdX + 17 * 3;
constint top_box0 = FlappyBirdY;
constint bottom_box0 = FlappyBirdY + 12 * 3;
constint left_box1 = PipeSpriteUp.getPosition().x;
constint right_box1 = PipeSpriteUp.getPosition().x + 26 * 4;
constint top_box1 = PipeSpriteUp.getPosition().y;
constint bottom_box1 = PipeSpriteUp.getPosition().y + 160 * 4;
constint left_box2 = PipeSpriteDown.getPosition().x;
constint right_box2 = PipeSpriteDown.getPosition().x + 26 * 4;
constint top_box2 = PipeSpriteDown.getPosition().y;
constint bottom_box2 = PipeSpriteDown.getPosition().y + 160 * 4;
return ((right_box0 >= left_box1 && left_box0 <= right_box1 && top_box0 <= bottom_box1 && bottom_box0 >= top_box1) || (right_box0 >= left_box2 && left_box0 <= right_box2 && top_box0 <= bottom_box2 && bottom_box0 >= top_box2));
}
intPipes::Points(float FlappyBirdX)
{
int left_box0 = FlappyBirdX;
int right_box0 = FlappyBirdX + 17 * 2;
int left_box1 = PipeSpriteDown.getPosition().x + 25;
int right_box1 = PipeSpriteDown.getPosition().x + 26;
int left_box2 = PipeSpriteUp.getPosition().x + 29;
int right_box2 = PipeSpriteUp.getPosition().x + 30;
return ((right_box0 >= left_box1 && left_box0 <= right_box1) || (right_box0 >= left_box2 && left_box0 <= right_box2));
}

Dev C++ Flappy Bird Download

  • Copy lines
  • Copy permalink