#include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __APPLE__ #include #include namespace rv = ranges::views; std::string assets = "/Users/andrew/personal/Projects/CPP/engine/assets/"; #else #include namespace rv = std::views; std::string assets = "/home/andrew/personal/Projects/CPP/engine/assets/"; #endif #include "data.hpp" #include "elements.hpp" #include "globals.hpp" #include "maps.hpp" #include "scheduler.hpp" int main() { Scheduler scheduler; Manager map_manager; map_manager.load(level_data[BASE]); std::atomic running { true }; sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default); window.setFramerateLimit(FPS); Player player { player_data, GRAVITY }; // player.initialize_bounding_box(player.get_velocity().x); sf::Font font(assets + "pixel.ttf"); sf::Text text(font, "0, 0", 16); text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5) }); std::jthread scheduler_thread([&] { scheduler.update(running); }); while (window.isOpen()) { window.clear(sf::Color::Black); text.setString(std::to_string(scheduler.timers.at(0).get_time())); while (const std::optional event = window.pollEvent()) { if (event->is()) { running = false; window.close(); } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) { running = false; window.close(); } if (map_manager.get_active() >= level_data.size()) { map_manager.set_active(DEFAULT); map_manager.load(level_data[DEFAULT]); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && scheduler.timers.at(1).below_or_zero()) { map_manager.set_next(); scheduler.timers.at(1).reset(); } player.handle_movment(scheduler.timers.at(scheduler.pull("Dash")), map_manager.tilemap); std::cout << player.get_horizontal_collision(map_manager.tilemap) << "\n"; player.handle_gravity(); player.get_vertical_collision(map_manager.tilemap); player.vertical_no_out_of_bounds(); // if (player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) // { // player.set_velocity_y((TILESIZE / 2) - GRAVITY); // } // if (!player.get_vertical_bottom_collision(map_manager.tilemap)) // { // player.get_vertical_top_collision(map_manager.tilemap); // } // if (player.bounding_box != nullptr) // { // player.update_bounding_box(); // // player.check_bounding_box(map_manager.tilemap); // } // for (auto [i, j] : // rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) // { // if (map_manager.tilemap[i][j] == nullptr) continue; // if(player.find_intersection(*map_manager.tilemap[i][j]).x > 0) { // std::cout << player.find_intersection(*map_manager.tilemap[i][j]).x << "\n"; // // running = false; // // window.close(); // } // } map_manager.draw(window); window.draw(player.rect); window.draw(text); window.display(); } map_manager.clear(); return 0; }