7 ms·
How to make Flappy Bird with C++
- jbaczuk 4y agoGetting compiler errors with clang, any experience with building on Mac?
- marcoscpp 4y agoStep by step code and also video tutorial
- gus_massa 4y agoWhere did you get the graphics from? Are they scrapped from the original game, some free resources or you draw them yourself?
- gustavorg 4y agogoogle flappy bird sprites There are tons of sites with all type of sprites, opengameart.org, for example.
- t6jvcereio 4y agoWell... The video is 35 minutes in length, but you can tell it's been heavily edited. Even if you knew what you're doing you probably wouldn't be able to do it in 35 mins
- dvfjsdhgfv 4y agoI mean it's not bad but you start with a couple of files already packed with code and you don't explain all that. It is probably fine for someone who knows what these things are for but this kind of person can probably do away with the rest of the tutorial.
- SuperV1234 4y agoPoor. Encouraging unnecessary use of 'shared_ptr' really is detrimental to a beginner's growth.
- t6jvcereio 4y agoBeginner here. Could you please explain?
- kiriin 4y ago>std::shared_ptr<sf::RenderWindow> window; >std::shared_ptr<sf::Sprite> background, bird, pipeBottom, pipeTop; None of that should be shared_ptr, in fact they shouldn't be pointers at all. >auto flappy = std::make_shared<FlappyBird>(); >flappy->run(); That would work just fine as a global in main.cpp FlappyBird flappy;
- a_t48 4y agoDisagree - it's very reasonable for resources to be shared.
- fusciaoptics 4y agoCan you share your vim setup? What plugins do you use and what does your config look like?
- tejohnso 4y agoInteresting choice with SFML. Always curious to see what people choose for graphics when it comes to C++. I tried a simple game with that which worked alright, but then I wanted to port to Android and things didn't go very well. I switch to SDL2, where there's more official support for Android, but it's still not ... let's say ... enjoyable. Probably because I'm going against the Android grain in trying to avoid android-studio and gradle. I didn't need those for Windows64, Linux64, ARM, and I'd rather keep the same CMAKE, gui-free dev env for Android as well.
- thn-gap 4y agoSFML can export to Android, but to me the biggest drawback is lack of Web export. In the current gamedev scene, web export is super popular for tiny games (specially for game jams, where it's just more convenience and also secure to share and try other games). In today's world where so many tools offer web export (from libs to frameworks to engines), I can't justify learning a tool that doesn't support it.
- camel-cdr 4y agoCheck out raylib
- tejohnso 4y agoWhat a great library! Thanks! This should be a lot more popular.
- TylerGlaiel 4y agoThis feels like it was written by someone who started learning C++ the day before he wrote this tutorial
- jakearmitage 4y agoThe sad thing is that there are tons of people doing this in a professional environment. auto and shared_ptr all the things. exceptions everywhere. RTTI. <cstdio> <cmath>.
- melony 4y agoThe code looks fine to me. If you see the newer C++23 guides like Lospinoso's C++ book, auto, shared_ptr, braces default value initializations are all considered best practices now. The only major issue I see is that OP should have used references instead of shared_ptrs for some of the variables.
- TylerGlaiel 4y agoNot a single one of the things he has as a shared pointer needed to be a pointer at all.
- throwaway968321 4y agojust want to point out, this unjustly uses std::shared_ptr in main.cpp auto flappy = std::make_shared<FlappyBird>(); flappy->run(); you can do this. FlappyBird flappy; flappy.run(); in flappy.hpp std::shared_ptr<sf::RenderWindow> window; std::shared_ptr<sf::Sprite> background, bird, pipeBottom, pipeTop; just do this. sf::RenderWindow window; sf::Sprite background, bird, pipeBottom, pipeTop; in flappy.cpp. auto e = std::make_shared<sf::Event>(); while( window->pollEvent( *e ) ){ if( e->type == sf::Event::Closed){ window->close(); } } just do this sf::Event event; while (window.pollEvent(event)) { if (e.type == sf::Event::Closed) { window.close(); } } It's really that simple.
- throwaway968321 4y agoin https://github.com/terroo/flappybird/blob/main/flappy.cpp#L132 https://github.com/terroo/flappybird/blob/main/flappy.cpp#L1... for (std::size_t i {}; i < pipes.size(); ++i) { C++ has had range based loops for years now, can use that instead here. for (auto& pipe : pipes) I don't remember if the '&' is needed after the auto though. anyway you should just use Rust, Zig, or Go...
- eco 4y agoYeah, since C++11 (the 2011 standard). '&' isn't necessary to use auto but you would use it here to avoid making an unnecessary copy of the pipe.
- ncmncm 4y agoIn this case, where it is erasing one of the container elements inside the loop, the range-based loop would not be right. But the code is busted anyway. After it erases the pipe (which is always at index zero) it then skips the pipe that was at index 1, if there was one. Correct would be to do the check and erase before entering the loop. Then the range-based loop would better.
- mrlonglong 4y agoSo I spent the last couple of hours on this. Pulled out all the shared_ptr and make_shared bollocks, played a couple of tricks with ld to embed the PNG images into the binary (since I don't do Windows or macOS, I'm OK with that), add some external references to these embedded images, created a CMakeFile that will figure out if you have SFML installed on the system etc. Looks better already!