5 karma · joined Aug 25, 2022 (4y ago) · 2 submissions
comment 4y ago · link · parent
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...
comment 4y ago · link · parent
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.