diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ff24801 --- /dev/null +++ b/.clang-format @@ -0,0 +1,42 @@ +--- +# Base Style +BasedOnStyle: LLVM +Standard: Latest +ColumnLimit: 120 +ReflowComments: true +SortIncludes: true +IncludeBlocks: Regroup + +# Indentation +UseTab: Always +TabWidth: 8 +IndentWidth: 8 +ContinuationIndentWidth: 8 +AlignAfterOpenBracket: Align +PointerAlignment: Right + +# Braces +BreakBeforeBraces: Custom +BraceWrapping: + AfterFunction: false + AfterClass: false + AfterControlStatement: false + AfterNamespace: false + IndentBraces: false + +# Containers & lists +SpacesInContainerLiterals: true +Cpp11BracedListStyle: false + +SpaceBeforeCpp11BracedList: true + +# Control statements & loops +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterControlStatements: true +SpaceBeforeRangeBasedForLoopColon: true +AllowShortFunctionsOnASingleLine: true + +# Preprocessor +IndentPPDirectives: AfterHash +PPIndentWidth: 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0418c8f..5e54e9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 4.2.1) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -15,32 +15,32 @@ set(SOURCES include(FetchContent) FetchContent_Declare(SFML - GIT_REPOSITORY https://github.com/SFML/SFML.git - GIT_TAG 3.0.2 - GIT_SHALLOW ON - EXCLUDE_FROM_ALL - SYSTEM) + GIT_REPOSITORY https://github.com/SFML/SFML.git + GIT_TAG 3.0.2 + GIT_SHALLOW ON + EXCLUDE_FROM_ALL + SYSTEM) FetchContent_MakeAvailable(SFML) if(APPLE) - message(STATUS "Detected macOS: installing range-v3") + message(STATUS "Detected macOS: installing range-v3") - include(FetchContent) - FetchContent_Declare( - range-v3 - GIT_REPOSITORY https://github.com/ericniebler/range-v3.git - GIT_TAG 0.12.0 - GIT_SHALLOW ON - ) - FetchContent_MakeAvailable(range-v3) + include(FetchContent) + FetchContent_Declare( + range-v3 + GIT_REPOSITORY https://github.com/ericniebler/range-v3.git + GIT_TAG 0.12.0 + GIT_SHALLOW ON + ) + FetchContent_MakeAvailable(range-v3) - include_directories(${range-v3_SOURCE_DIR}/include) + include_directories(${range-v3_SOURCE_DIR}/include) endif() add_executable(engine ${SOURCES}) target_link_libraries(engine - PRIVATE - SFML::Graphics - SFML::Window - SFML::System + PRIVATE + SFML::Graphics + SFML::Window + SFML::System ) diff --git a/include/data.hpp b/include/data.hpp new file mode 100644 index 0000000..cb25cce --- /dev/null +++ b/include/data.hpp @@ -0,0 +1,22 @@ +#ifndef DATA_HPP +#define DATA_HPP + +#include "globals.hpp" +#include +#include + +struct Map { + const char map[MAX_ROWS][MAX_COLS]; +}; + +struct Player { + sf::Vector2 size { TILESIZE / 2.0f, TILESIZE / 2.0f }; + sf::Vector2 pos { TILESIZE, TILESIZE }; + float max_velocity_y { 15.0f }; + float border_size { -1.0f }; + + float dash_distance { 20.0f }; + sf::Vector2f velocity { 3.0f, 0 }; +}; + +#endif diff --git a/include/elements.hpp b/include/elements.hpp index a7d8530..78f8b66 100644 --- a/include/elements.hpp +++ b/include/elements.hpp @@ -47,4 +47,13 @@ private: sf::Vector2f _min_velocity; }; +struct player_data { + sf::Vector2 size { TILESIZE / 2.0f, TILESIZE / 2.0f }; + sf::Vector2 pos { TILESIZE, TILESIZE }; + float max_velocity_y { 15.0f }; + float border_size { -1.0f }; + float dash_distance { 20.0f }; + sf::Vector2f velocity { 3.0f, 0 }; +}; + #endif diff --git a/include/maps.hpp b/include/maps.hpp index aa37350..33be985 100644 --- a/include/maps.hpp +++ b/include/maps.hpp @@ -2,22 +2,25 @@ #define MAPS_HPP #include +#include #include "globals.hpp" #include "elements.hpp" -extern char test_level_0[MAX_ROWS][MAX_COLS]; -extern char test_level_1[MAX_ROWS][MAX_COLS]; -extern char test_level_2[MAX_ROWS][MAX_COLS]; +struct Level { + char data[MAX_ROWS][MAX_COLS]; + std::string name; +}; -void clear_map(Entity* wall_list[MAX_ROWS][MAX_COLS]); -void load_map(Entity* wall_list[MAX_ROWS][MAX_COLS], const char map_data[MAX_ROWS][MAX_COLS]); -// void create_map(sf::RenderWindow &window, sf::Vector2i &local_position, sf::Vector2i &start_mouse_pos, sf::Vector2i &end_mouse_pos, bool &dragging, bool &prev_dragging, Entity *wall_list[MAX_ROWS][MAX_COLS]); +extern Level levels[]; + +void clear_map(std::array, MAX_ROWS> wall_list); +void load_map(std::array, MAX_ROWS> wall_list, const std::array, MAX_ROWS> map_data); std::array, MAX_ROWS> create_map(sf::RenderWindow &window, sf::Vector2i &local_position, sf::Vector2i &start_mouse_pos, sf::Vector2i &end_mouse_pos, bool &dragging, bool &prev_dragging, - Entity *wall_list[MAX_ROWS][MAX_COLS]); + std::array, MAX_ROWS> wall_list); #endif diff --git a/src/data.cpp b/src/data.cpp new file mode 100644 index 0000000..fcd5616 --- /dev/null +++ b/src/data.cpp @@ -0,0 +1 @@ +#include "data.hpp" diff --git a/src/elements.cpp b/src/elements.cpp index f050b43..547b8fa 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -1,17 +1,20 @@ #include "elements.hpp" + #include "globals.hpp" -#include + #include +#include #include #include #ifdef __APPLE__ -#include #include +#include #else #include #endif -Entity::Entity(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, sf::Color inside_color, sf::Color border_color) { +Entity::Entity(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, + sf::Color inside_color, sf::Color border_color) { rect.setSize(size); rect.setPosition(pos); rect.setOutlineThickness(border_thickness); @@ -20,21 +23,13 @@ Entity::Entity(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f vel _velocity = velocity; } -void Entity::set_velocity(sf::Vector2 velocity) { - _velocity = velocity; -} +void Entity::set_velocity(sf::Vector2 velocity) { _velocity = velocity; } -void Entity::set_velocity_x(int velocity) { - _velocity.x = velocity; -} +void Entity::set_velocity_x(int velocity) { _velocity.x = velocity; } -void Entity::set_velocity_y(int velocity) { - _velocity.y = velocity; -} +void Entity::set_velocity_y(int velocity) { _velocity.y = velocity; } -sf::Vector2 Entity::get_velocity() { - return _velocity; -} +sf::Vector2 Entity::get_velocity() { return _velocity; } CollisionDir Entity::find_intersection(Entity &entity) { sf::FloatRect a = rect.getGlobalBounds(); @@ -51,17 +46,17 @@ CollisionDir Entity::find_intersection(Entity &entity) { if (overlapW < overlapH) { // Horizontal collision - return (a.position.x < b.position.x) - ? CollisionDir::Right // a hit b from the left side - : CollisionDir::Left; // a hit b from the right side + return (a.position.x < b.position.x) ? CollisionDir::Right // a hit b from the left side + : CollisionDir::Left; // a hit b from the right side } else { - return (a.position.y < b.position.y) - ? CollisionDir::Bottom - : CollisionDir::Top; + return (a.position.y < b.position.y) ? CollisionDir::Bottom : CollisionDir::Top; } } -Player::Player(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, float gravity, float max_acceleration, float dash_distance, sf::Color inside_color, sf::Color border_color) : Entity(size, pos, velocity, border_thickness, inside_color, border_color) { +Player::Player(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f velocity, float border_thickness, + float gravity, float max_acceleration, float dash_distance, sf::Color inside_color, + sf::Color border_color) + : Entity(size, pos, velocity, border_thickness, inside_color, border_color) { _min_velocity = velocity; m_acceleration = gravity; m_jump_strength = max_acceleration; @@ -70,24 +65,28 @@ Player::Player(sf::Vector2 size, sf::Vector2 pos, sf::Vector2f vel } void Player::handle_movment() { - if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) { + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) { rect.move({_velocity.x, 0}); - } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { rect.move({-_velocity.x, 0}); - } if(timers.dash_cooldown <= 0) { + } + if (timers.dash_cooldown <= 0) { m_dash = false; - } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W) && !m_dash && timers.dash_cooldown <= 0) { + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W) && !m_dash && timers.dash_cooldown <= 0) { m_dash = true; - _velocity.x = m_dash_distance; + _velocity.x = m_dash_distance; timers.dash_cooldown = timers.dash_cooldown_max; - } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !m_jumping) { + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !m_jumping) { m_jumping = true; _velocity.y = -m_jump_strength; // push up } } void Player::handle_gravity() { - if(get_velocity().x > _min_velocity.x) { + if (get_velocity().x > _min_velocity.x) { set_velocity_x(get_velocity().x - m_acceleration); } @@ -97,16 +96,17 @@ void Player::handle_gravity() { void Player::horizontal_no_out_of_bounds(Entity &base) { float right_border = WIDTH - rect.getSize().x; - if(rect.getPosition().x > right_border) { - rect.setPosition({ right_border, rect.getPosition().y}); + if (rect.getPosition().x > right_border) { + rect.setPosition({right_border, rect.getPosition().y}); } - if(rect.getPosition().x < std::abs(rect.getOutlineThickness())) { - rect.setPosition({ 0, rect.getPosition().y}); + if (rect.getPosition().x < std::abs(rect.getOutlineThickness())) { + rect.setPosition({0, rect.getPosition().y}); } } void Player::vertical_no_out_of_bounds(Entity &base) { - float groundY = base.rect.getPosition().y - base.rect.getSize().y - rect.getSize().y - base.rect.getOutlineThickness() - rect.getOutlineThickness(); + float groundY = base.rect.getPosition().y - base.rect.getSize().y - rect.getSize().y - + base.rect.getOutlineThickness() - rect.getOutlineThickness(); if (rect.getPosition().y >= groundY) { rect.setPosition({rect.getPosition().x, groundY}); set_velocity_y(0); @@ -116,19 +116,25 @@ void Player::vertical_no_out_of_bounds(Entity &base) { bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) { #ifdef __APPLE__ -for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { - #else - for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { - #endif - if(wall_list[i][j] == nullptr) continue; + for (auto [i, j] : + ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { +#else + for (auto [i, j] : + std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { +#endif + if (wall_list[i][j] == nullptr) + continue; auto collision = wall_list[i][j]->find_intersection(*this); - if(collision == CollisionDir::None) continue; - if(collision == CollisionDir::Left) { - rect.setPosition({ wall_list[i][j]->rect.getPosition().x - rect.getSize().x, rect.getPosition().y }); + if (collision == CollisionDir::None) + continue; + if (collision == CollisionDir::Left) { + rect.setPosition( + {wall_list[i][j]->rect.getPosition().x - rect.getSize().x, rect.getPosition().y}); return true; } - if(collision == CollisionDir::Right) { - rect.setPosition({ wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x, rect.getPosition().y }); + if (collision == CollisionDir::Right) { + rect.setPosition({wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x, + rect.getPosition().y}); return true; } } @@ -137,15 +143,20 @@ for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_RO bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) { #ifdef __APPLE__ -for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { - #else - for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { - #endif - if(wall_list[i][j] == nullptr) continue; + for (auto [i, j] : + ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { +#else + for (auto [i, j] : + std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { +#endif + if (wall_list[i][j] == nullptr) + continue; auto collision = find_intersection(*wall_list[i][j]); - if(collision == CollisionDir::None) continue; - if(collision == CollisionDir::Top) { - rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y}); + if (collision == CollisionDir::None) + continue; + if (collision == CollisionDir::Top) { + rect.setPosition({rect.getPosition().x, + wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y}); set_velocity_y(0); return true; } @@ -155,15 +166,20 @@ for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_RO bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) { #ifdef __APPLE__ -for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { - #else - for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { - #endif - if(wall_list[i][j] == nullptr) continue; + for (auto [i, j] : + ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { +#else + for (auto [i, j] : + std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { +#endif + if (wall_list[i][j] == nullptr) + continue; auto collision = find_intersection(*wall_list[i][j]); - if(collision == CollisionDir::None) continue; - if(collision == CollisionDir::Bottom && get_velocity().y > 0) { - rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y }); + if (collision == CollisionDir::None) + continue; + if (collision == CollisionDir::Bottom && get_velocity().y > 0) { + rect.setPosition( + {rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y}); m_jumping = false; set_velocity_y(0); return true; diff --git a/src/main.cpp b/src/main.cpp index 5e7389d..2bb7e4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,25 +1,25 @@ #include #include #include +#include #include #include -#include #include #include #include +#include #include #include -#include #ifdef __APPLE__ -#include #include +#include #else #include #endif -#include "globals.hpp" #include "elements.hpp" +#include "globals.hpp" #include "maps.hpp" #include "scheduler.hpp" @@ -31,120 +31,112 @@ int main() { sf::Vector2i end_mouse_pos; bool dragging = false; bool prev_dragging = false; - // int current_level = 0; - // struct { - // sf::Vector2 size { TILESIZE / 2.0f, TILESIZE / 2.0f }; - // sf::Vector2 pos { TILESIZE, TILESIZE }; - // float max_velocity_y { 15.0f }; - // float border_size { -1.0f }; - // float dash_distance { 20.0f }; - // sf::Vector2f velocity { 3.0f, 0 }; - // } player_data; + int current_level = 0; - load_map(wall_list, test_level_0); + load_map(wall_list, ); - // Player player { - // player_data.size, player_data.pos, player_data.velocity, - // player_data.border_size, GRAVITY, player_data.max_velocity_y, - // player_data.dash_distance, sf::Color::Black, sf::Color::White - // }; + player_data player_data; + Player player { player_data.size, player_data.pos, player_data.velocity, + player_data.border_size, GRAVITY, player_data.max_velocity_y, + player_data.dash_distance, sf::Color::Black, sf::Color::White }; - sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "engine", sf::Style::Default); + sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default); window.setFramerateLimit(FPS); #ifdef __APPLE__ - sf::Font font("/Users/andrewhaynes/personal/Projects/CPP/engine/assets/pixel.ttf"); + sf::Font font("/Users/andrew/personal/Projects/CPP/engine/assets/pixel.ttf"); #else sf::Font font("/home/andrew/personal/Projects/CPP/engine/assets/pixel.ttf"); #endif sf::Text text(font, "0, 0", 16); - text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5)}); + text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5) }); - // bool running = true; - // std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); } ); + bool running = true; + std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); }); while (window.isOpen()) { local_position = sf::Mouse::getPosition(window); window.clear(sf::Color::Black); - text.setString(std::to_string((int)std::floor(local_position.x / 32)) + ", " + std::to_string((int)std::floor(local_position.y / 32))); + text.setString(std::to_string((int)std::floor(local_position.x / 32)) + ", " + + std::to_string((int)std::floor(local_position.y / 32))); while (const std::optional event = window.pollEvent()) { if (event->is()) { - // running = false; + running = false; window.close(); } } - if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) { - // running = false; + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) { + running = false; window.close(); } - if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) { + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) { clear_map(wall_list); } - if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { dragging = false; } create_map(window, local_position, start_mouse_pos, end_mouse_pos, dragging, prev_dragging, wall_list); - // if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) { - // clear_map(wall_list); - // if(current_level == 0) { - // load_map(wall_list, test_level_1); - // current_level = 1; - // player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; - // } - // else if(current_level == 1) { - // load_map(wall_list, test_level_2); - // current_level = 2; - // player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; - // } - // else if(current_level == 2) { - // load_map(wall_list, test_level_0); - // current_level = 0; - // player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; - // } - // } - // - // player.handle_movment(); - // if(!player.get_horizontal_collision(wall_list)) { - // std::cout << "\n"; - // } - // else { - // std::cout << "Yes horizontal collision\n"; - // } - // - // player.handle_gravity(); - // if(player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) { - // player.set_velocity_y((TILESIZE / 2) - GRAVITY); - // } - // if(!player.get_vertical_bottom_collision(wall_list)) { - // std::cout << "\n"; - // if(!player.get_vertical_top_collision(wall_list)) { - // std::cout << "\n"; - // } else { - // std::cout << "Yes vertical top collision\n"; - // } - // } - // else { - // std::cout << "Yes vertical bottom collision\n"; - // } - // + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) { + clear_map(wall_list); + if (current_level == 0) { + load_map(wall_list, test_level_1); + current_level = 1; + player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; + } else if (current_level == 1) { + load_map(wall_list, test_level_2); + current_level = 2; + player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; + } else if (current_level == 2) { + load_map(wall_list, test_level_0); + current_level = 0; + player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; + } + } + + player.handle_movment(); + if (!player.get_horizontal_collision(wall_list)) { + std::cout << "\n"; + } else { + std::cout << "Yes horizontal collision\n"; + } + + player.handle_gravity(); + if (player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) { + player.set_velocity_y((TILESIZE / 2) - GRAVITY); + } + if (!player.get_vertical_bottom_collision(wall_list)) { + std::cout << "\n"; + if (!player.get_vertical_top_collision(wall_list)) { + std::cout << "\n"; + } else { + std::cout << "Yes vertical top collision\n"; + } + } else { + std::cout << "Yes vertical bottom collision\n"; + } + #ifdef __APPLE__ - for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { - if(wall_list[i][j] == nullptr) continue; - window.draw(wall_list[i][j]->rect); + for (auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), + ranges::views::iota(0, MAX_COLS))) { + if (wall_list[i][j] == nullptr) + continue; + window.draw(wall_list[i][j]->rect); } #else - for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { - if(wall_list[i][j] == nullptr) continue; - window.draw(wall_list[i][j]->rect); + for (auto [i, j] : + std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { + if (wall_list[i][j] == nullptr) + continue; + window.draw(wall_list[i][j]->rect); } #endif - // window.draw(player.rect); + window.draw(player.rect); window.draw(text); window.display(); } clear_map(wall_list); - // player_dash_cooldown.join(); + player_dash_cooldown.join(); return 0; } diff --git a/src/maps.cpp b/src/maps.cpp index 723adff..50827cf 100644 --- a/src/maps.cpp +++ b/src/maps.cpp @@ -1,105 +1,122 @@ #include "maps.hpp" + #include "elements.hpp" #include "globals.hpp" -#include + #include +#include #ifdef __APPLE__ -#include #include +#include +namespace rv = ranges::views; #else #include +namespace rv = std::views; #endif -void clear_map(Entity* wall_list[MAX_ROWS][MAX_COLS]) { -#ifdef __APPLE__ -for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { - #else - for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { - #endif +void clear_map(std::array, MAX_ROWS> wall_list) { + for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { delete wall_list[i][j]; wall_list[i][j] = nullptr; } } bool is_tiles_clear_x(std::array, MAX_ROWS> draw_list, int y_level, int start_x, int end_x) { - for(int i : std::views::iota(start_x, end_x)) { - if(draw_list[i][y_level] == ' ') continue; + for (int i : rv::iota(start_x, end_x)) { + if (draw_list[i][y_level] == ' ') + continue; return false; } return true; } bool is_tiles_clear_y(std::array, MAX_ROWS> draw_list, int x_level, int start_y, int end_y) { - for(int i : std::views::iota(start_y, end_y)) { - if(draw_list[i][x_level] == ' ') continue; + for (int i : rv::iota(start_y, end_y)) { + if (draw_list[i][x_level] == ' ') + continue; return false; } return true; } -std::array, MAX_ROWS> create_map(sf::RenderWindow &window, sf::Vector2i &local_position, sf::Vector2i &start_mouse_pos, sf::Vector2i &end_mouse_pos, bool &dragging, bool &prev_dragging, Entity *wall_list[MAX_ROWS][MAX_COLS]) { +std::array, MAX_ROWS> create_map(sf::RenderWindow &window, sf::Vector2i &local_position, + sf::Vector2i &start_mouse_pos, sf::Vector2i &end_mouse_pos, + bool &dragging, bool &prev_dragging, + Entity *wall_list[MAX_ROWS][MAX_COLS]) { std::array, MAX_ROWS> draw_list {}; - for(auto &row : draw_list) { + for (auto &row : draw_list) { row.fill(' '); } static bool vertical = false; - if(local_position.x > 0 && local_position.x < WIDTH && local_position.y > 0 && local_position.y < HEIGHT) { - if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && !dragging) { + if (local_position.x > 0 && local_position.x < WIDTH && local_position.y > 0 && local_position.y < HEIGHT) { + if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && !dragging) { dragging = true; start_mouse_pos = local_position; } - if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging) { + if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging) { prev_dragging = true; end_mouse_pos = local_position; - sf::RectangleShape rect; - if(end_mouse_pos.x - start_mouse_pos.x > end_mouse_pos.y - start_mouse_pos.y) { - rect.setSize({ (float) (end_mouse_pos.x - start_mouse_pos.x), 1.0f }); - rect.setPosition({ (float)start_mouse_pos.x, (float)(std::floor(start_mouse_pos.y / 32) * TILESIZE + ((float)TILESIZE / 2))} ); + sf::RectangleShape rect; + if (end_mouse_pos.x - start_mouse_pos.x > end_mouse_pos.y - start_mouse_pos.y) { + rect.setSize({ (float)(end_mouse_pos.x - start_mouse_pos.x), 1.0f }); + rect.setPosition({ (float)start_mouse_pos.x, + (float)(std::floor(start_mouse_pos.y / 32) * TILESIZE + + ((float)TILESIZE / 2)) }); vertical = false; } else { - rect.setSize({ 1.0f, (float) (end_mouse_pos.y - start_mouse_pos.y),}); - rect.setPosition({ (float)(std::floor(start_mouse_pos.x / 32) * TILESIZE + ((float)TILESIZE / 2)), (float)start_mouse_pos.y} ); + rect.setSize({ + 1.0f, + (float)(end_mouse_pos.y - start_mouse_pos.y), + }); + rect.setPosition({ (float)(std::floor(start_mouse_pos.x / 32) * TILESIZE + + ((float)TILESIZE / 2)), + (float)start_mouse_pos.y }); vertical = true; } window.draw(rect); } - if(!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging && prev_dragging) { - sf::Vector2i start_integers = { (int)std::floor(start_mouse_pos.x / 32), (int)std::floor(start_mouse_pos.y / 32) }; - sf::Vector2i end_integers = { (int)std::floor(end_mouse_pos.x / 32), (int)std::floor(end_mouse_pos.y / 32) }; + if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging && prev_dragging) { + sf::Vector2i start_integers = { (int)std::floor(start_mouse_pos.x / 32), + (int)std::floor(start_mouse_pos.y / 32) }; + sf::Vector2i end_integers = { (int)std::floor(end_mouse_pos.x / 32), + (int)std::floor(end_mouse_pos.y / 32) }; - if(!vertical) { - if(wall_list[start_integers.y][start_integers.x] == nullptr) { + if (!vertical) { + if (wall_list[start_integers.y][start_integers.x] == nullptr) { + wall_list[start_integers.y][start_integers.x] = + new Entity { { float(end_integers.x - start_integers.x + 1) * TILESIZE, + TILESIZE }, + { (float)(start_integers.x * TILESIZE), + (float)(start_integers.y * TILESIZE) }, + { 0, 0 }, + -2.0f, + sf::Color::Black }; + draw_list[start_integers.y][start_integers.x] = '1'; + draw_list[end_integers.y][end_integers.x] = '2'; + for (int i : rv::iota(start_integers.x, end_integers.x)) { + draw_list[start_integers.y][i] = '-'; + } + } + } else if (vertical) { + if (wall_list[start_integers.y][start_integers.x] == nullptr) { + // if(is_tiles_clear_y(draw_list, start_integers.x, start_integers.y, + // end_integers.y)) { wall_list[start_integers.y][start_integers.x] = new Entity { - { float(end_integers.x - start_integers.x + 1) * TILESIZE, TILESIZE }, - { (float)(start_integers.x * TILESIZE), (float)(start_integers.y * TILESIZE) }, + { TILESIZE, float(end_integers.y - start_integers.y + 1) * TILESIZE }, + { (float)(start_integers.x * TILESIZE), + (float)(start_integers.y * TILESIZE) }, { 0, 0 }, -2.0f, sf::Color::Black }; draw_list[start_integers.y][start_integers.x] = '1'; draw_list[end_integers.y][end_integers.x] = '2'; - for(int i : std::views::iota(start_integers.x, end_integers.x)) { - draw_list[start_integers.y][i] = '-'; + for (int i : rv::iota(start_integers.y, end_integers.y)) { + draw_list[i][start_integers.x] = '|'; } + // } } - } else if(vertical) { - if(wall_list[start_integers.y][start_integers.x] == nullptr) { - // if(is_tiles_clear_y(draw_list, start_integers.x, start_integers.y, end_integers.y)) { - wall_list[start_integers.y][start_integers.x] = new Entity { - { TILESIZE, float(end_integers.y - start_integers.y + 1) * TILESIZE }, - { (float)(start_integers.x * TILESIZE), (float)(start_integers.y * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black - }; - draw_list[start_integers.y][start_integers.x] = '1'; - draw_list[end_integers.y][end_integers.x] = '2'; - for(int i : std::views::iota(start_integers.y, end_integers.y)) { - draw_list[i][start_integers.x] = '|'; - } - // } - } // } prev_dragging = false; dragging = false; @@ -109,113 +126,126 @@ std::array, MAX_ROWS> create_map(sf::RenderWindow &wi return draw_list; } -void load_map(Entity* wall_list[MAX_ROWS][MAX_COLS], const char map_data[MAX_ROWS][MAX_COLS]) { -#ifdef __APPLE__ -for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { - #else - for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { - #endif - if(map_data[i][j] == ' ') continue; - if(map_data[i][j] == '0') { - wall_list[i][j] = new Entity { - { TILESIZE, TILESIZE }, - { float(j * TILESIZE), float(i * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black - }; +void load_map(std::array, MAX_ROWS> wall_list, + const std::array, MAX_ROWS> map_data) { + for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) { + if (map_data[i][j] == ' ') + continue; + if (map_data[i][j] == '0') { + wall_list[i][j] = new Entity { { TILESIZE, TILESIZE }, + { float(j * TILESIZE), float(i * TILESIZE) }, + { 0, 0 }, + -2.0f, + sf::Color::Black }; } - if(map_data[i][j] == '1' && map_data[i][j + 1] == '2') { + if (map_data[i][j] == '1' && map_data[i][j + 1] == '2') { int start = j, end = j + 1; - wall_list[i][j] = new Entity { - { float(end - start + 1) * TILESIZE, TILESIZE }, - { float(j * TILESIZE), float(i * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black - }; + wall_list[i][j] = new Entity { { float(end - start + 1) * TILESIZE, TILESIZE }, + { float(j * TILESIZE), float(i * TILESIZE) }, + { 0, 0 }, + -2.0f, + sf::Color::Black }; } - if(map_data[i][j] == '1' && map_data[i + 1][j] == '2') { + if (map_data[i][j] == '1' && map_data[i + 1][j] == '2') { int start = i, end = i + 1; - wall_list[i][j] = new Entity { - { TILESIZE, float(end - start + 1) * TILESIZE }, - { float(j * TILESIZE), float(i * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black - }; + wall_list[i][j] = new Entity { { TILESIZE, float(end - start + 1) * TILESIZE }, + { float(j * TILESIZE), float(i * TILESIZE) }, + { 0, 0 }, + -2.0f, + sf::Color::Black }; } - if(map_data[i][j] == '1' && map_data[i][j + 1] == '-') { + if (map_data[i][j] == '1' && map_data[i][j + 1] == '-') { int start = j, end = j; - while(end + 1 < MAX_COLS && map_data[i][end + 1] != '2') end++; - if(map_data[i][end + 1] == '2') end++; - wall_list[i][j] = new Entity { - { float(end - start + 1) * TILESIZE, TILESIZE }, - { float(j * TILESIZE), float(i * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black - }; + while (end + 1 < MAX_COLS && map_data[i][end + 1] != '2') + end++; + if (map_data[i][end + 1] == '2') + end++; + wall_list[i][j] = new Entity { { float(end - start + 1) * TILESIZE, TILESIZE }, + { float(j * TILESIZE), float(i * TILESIZE) }, + { 0, 0 }, + -2.0f, + sf::Color::Black }; } - if(map_data[i][j] == '1' && map_data[i + 1][j] == '|') { + if (map_data[i][j] == '1' && map_data[i + 1][j] == '|') { int start = i, end = i; - while(end + 1 < MAX_ROWS && map_data[end + 1][j] != '2') end++; - if(map_data[end + 1][j] == '2') end++; - wall_list[i][j] = new Entity { - { TILESIZE, float(end - start + 1) * TILESIZE }, - { float(j * TILESIZE), float(i * TILESIZE) }, - { 0, 0 }, - -2.0f, - sf::Color::Black - }; + while (end + 1 < MAX_ROWS && map_data[end + 1][j] != '2') + end++; + if (map_data[end + 1][j] == '2') + end++; + wall_list[i][j] = new Entity { { TILESIZE, float(end - start + 1) * TILESIZE }, + { float(j * TILESIZE), float(i * TILESIZE) }, + { 0, 0 }, + -2.0f, + sf::Color::Black }; } } } -char test_level_0[MAX_ROWS][MAX_COLS] = { - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, - { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, -}; - -char test_level_1[MAX_ROWS][MAX_COLS] = { - { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, - { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, - { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, - { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, -}; - -char test_level_2[MAX_ROWS][MAX_COLS] = { - { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, - { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, - { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, - { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, - { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, -}; +Level levels[] = { + { + .data = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, + {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, }, + .name = "Empty" + }, + { + .data = { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, + { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, + { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, + { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, }, + .name = "Default" + }, + { + .data = { + { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, + { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, + { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, + { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, + { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, }, + .name = "1" + }, + { + .data = { + { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, + { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, + { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, + { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, + { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, + { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, + { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, + { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, + { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, + { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, + { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, + { ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ' }, + { '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0', ' ', '0' }, }, + .name = "3" + } +}; diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 4efbe66..0f3fcdf 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -1,6 +1,7 @@ // timer for player cooldown #include "scheduler.hpp" + #include #include void Timer::update_timers(bool &running, Times ×) {