breaking changes: optimizing code and added .clang-format

This commit is contained in:
Andrew Haynes Macbook
2026-01-09 12:38:38 -05:00
parent 55f604710e
commit b5a79de6c0
10 changed files with 431 additions and 315 deletions
+42
View File
@@ -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
+20 -20
View File
@@ -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 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
@@ -15,32 +15,32 @@ set(SOURCES
include(FetchContent) include(FetchContent)
FetchContent_Declare(SFML FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 3.0.2 GIT_TAG 3.0.2
GIT_SHALLOW ON GIT_SHALLOW ON
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
SYSTEM) SYSTEM)
FetchContent_MakeAvailable(SFML) FetchContent_MakeAvailable(SFML)
if(APPLE) if(APPLE)
message(STATUS "Detected macOS: installing range-v3") message(STATUS "Detected macOS: installing range-v3")
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
range-v3 range-v3
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG 0.12.0 GIT_TAG 0.12.0
GIT_SHALLOW ON GIT_SHALLOW ON
) )
FetchContent_MakeAvailable(range-v3) FetchContent_MakeAvailable(range-v3)
include_directories(${range-v3_SOURCE_DIR}/include) include_directories(${range-v3_SOURCE_DIR}/include)
endif() endif()
add_executable(engine ${SOURCES}) add_executable(engine ${SOURCES})
target_link_libraries(engine target_link_libraries(engine
PRIVATE PRIVATE
SFML::Graphics SFML::Graphics
SFML::Window SFML::Window
SFML::System SFML::System
) )
+22
View File
@@ -0,0 +1,22 @@
#ifndef DATA_HPP
#define DATA_HPP
#include "globals.hpp"
#include <SFML/Graphics/Color.hpp>
#include <SFML/System/Vector2.hpp>
struct Map {
const char map[MAX_ROWS][MAX_COLS];
};
struct Player {
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
sf::Vector2<float> 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
+9
View File
@@ -47,4 +47,13 @@ private:
sf::Vector2f _min_velocity; sf::Vector2f _min_velocity;
}; };
struct player_data {
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
sf::Vector2<float> 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 #endif
+10 -7
View File
@@ -2,22 +2,25 @@
#define MAPS_HPP #define MAPS_HPP
#include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Graphics/RenderWindow.hpp>
#include <array>
#include "globals.hpp" #include "globals.hpp"
#include "elements.hpp" #include "elements.hpp"
extern char test_level_0[MAX_ROWS][MAX_COLS]; struct Level {
extern char test_level_1[MAX_ROWS][MAX_COLS]; char data[MAX_ROWS][MAX_COLS];
extern char test_level_2[MAX_ROWS][MAX_COLS]; std::string name;
};
void clear_map(Entity* wall_list[MAX_ROWS][MAX_COLS]); extern Level levels[];
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]); void clear_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list);
void load_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list, const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data);
std::array<std::array<char, MAX_COLS>, MAX_ROWS> create_map(sf::RenderWindow &window, std::array<std::array<char, MAX_COLS>, MAX_ROWS> create_map(sf::RenderWindow &window,
sf::Vector2i &local_position, sf::Vector2i &local_position,
sf::Vector2i &start_mouse_pos, sf::Vector2i &start_mouse_pos,
sf::Vector2i &end_mouse_pos, sf::Vector2i &end_mouse_pos,
bool &dragging, bool &dragging,
bool &prev_dragging, bool &prev_dragging,
Entity *wall_list[MAX_ROWS][MAX_COLS]); std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list);
#endif #endif
+1
View File
@@ -0,0 +1 @@
#include "data.hpp"
+75 -59
View File
@@ -1,17 +1,20 @@
#include "elements.hpp" #include "elements.hpp"
#include "globals.hpp" #include "globals.hpp"
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp> #include <SFML/Window/Keyboard.hpp>
#ifdef __APPLE__ #ifdef __APPLE__
#include <range/v3/view/iota.hpp>
#include <range/v3/view/cartesian_product.hpp> #include <range/v3/view/cartesian_product.hpp>
#include <range/v3/view/iota.hpp>
#else #else
#include <ranges> #include <ranges>
#endif #endif
Entity::Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, sf::Color inside_color, sf::Color border_color) { Entity::Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness,
sf::Color inside_color, sf::Color border_color) {
rect.setSize(size); rect.setSize(size);
rect.setPosition(pos); rect.setPosition(pos);
rect.setOutlineThickness(border_thickness); rect.setOutlineThickness(border_thickness);
@@ -20,21 +23,13 @@ Entity::Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f vel
_velocity = velocity; _velocity = velocity;
} }
void Entity::set_velocity(sf::Vector2<float> velocity) { void Entity::set_velocity(sf::Vector2<float> velocity) { _velocity = velocity; }
_velocity = velocity;
}
void Entity::set_velocity_x(int velocity) { void Entity::set_velocity_x(int velocity) { _velocity.x = velocity; }
_velocity.x = velocity;
}
void Entity::set_velocity_y(int velocity) { void Entity::set_velocity_y(int velocity) { _velocity.y = velocity; }
_velocity.y = velocity;
}
sf::Vector2<float> Entity::get_velocity() { sf::Vector2<float> Entity::get_velocity() { return _velocity; }
return _velocity;
}
CollisionDir Entity::find_intersection(Entity &entity) { CollisionDir Entity::find_intersection(Entity &entity) {
sf::FloatRect a = rect.getGlobalBounds(); sf::FloatRect a = rect.getGlobalBounds();
@@ -51,17 +46,17 @@ CollisionDir Entity::find_intersection(Entity &entity) {
if (overlapW < overlapH) { if (overlapW < overlapH) {
// Horizontal collision // Horizontal collision
return (a.position.x < b.position.x) return (a.position.x < b.position.x) ? CollisionDir::Right // a hit b from the left side
? CollisionDir::Right // a hit b from the left side : CollisionDir::Left; // a hit b from the right side
: CollisionDir::Left; // a hit b from the right side
} else { } else {
return (a.position.y < b.position.y) return (a.position.y < b.position.y) ? CollisionDir::Bottom : CollisionDir::Top;
? CollisionDir::Bottom
: CollisionDir::Top;
} }
} }
Player::Player(sf::Vector2<float> size, sf::Vector2<float> 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<float> size, sf::Vector2<float> 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; _min_velocity = velocity;
m_acceleration = gravity; m_acceleration = gravity;
m_jump_strength = max_acceleration; m_jump_strength = max_acceleration;
@@ -70,24 +65,28 @@ Player::Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f vel
} }
void Player::handle_movment() { 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}); 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}); rect.move({-_velocity.x, 0});
} if(timers.dash_cooldown <= 0) { }
if (timers.dash_cooldown <= 0) {
m_dash = false; 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; m_dash = true;
_velocity.x = m_dash_distance; _velocity.x = m_dash_distance;
timers.dash_cooldown = timers.dash_cooldown_max; 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; m_jumping = true;
_velocity.y = -m_jump_strength; // push up _velocity.y = -m_jump_strength; // push up
} }
} }
void Player::handle_gravity() { 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); 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) { void Player::horizontal_no_out_of_bounds(Entity &base) {
float right_border = WIDTH - rect.getSize().x; float right_border = WIDTH - rect.getSize().x;
if(rect.getPosition().x > right_border) { if (rect.getPosition().x > right_border) {
rect.setPosition({ right_border, rect.getPosition().y}); rect.setPosition({right_border, rect.getPosition().y});
} }
if(rect.getPosition().x < std::abs(rect.getOutlineThickness())) { if (rect.getPosition().x < std::abs(rect.getOutlineThickness())) {
rect.setPosition({ 0, rect.getPosition().y}); rect.setPosition({0, rect.getPosition().y});
} }
} }
void Player::vertical_no_out_of_bounds(Entity &base) { 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) { if (rect.getPosition().y >= groundY) {
rect.setPosition({rect.getPosition().x, groundY}); rect.setPosition({rect.getPosition().x, groundY});
set_velocity_y(0); 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]) { bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
#ifdef __APPLE__ #ifdef __APPLE__
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { for (auto [i, j] :
#else ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { #else
#endif for (auto [i, j] :
if(wall_list[i][j] == nullptr) continue; 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); auto collision = wall_list[i][j]->find_intersection(*this);
if(collision == CollisionDir::None) continue; if (collision == CollisionDir::None)
if(collision == CollisionDir::Left) { continue;
rect.setPosition({ wall_list[i][j]->rect.getPosition().x - rect.getSize().x, rect.getPosition().y }); if (collision == CollisionDir::Left) {
rect.setPosition(
{wall_list[i][j]->rect.getPosition().x - rect.getSize().x, rect.getPosition().y});
return true; return true;
} }
if(collision == CollisionDir::Right) { if (collision == CollisionDir::Right) {
rect.setPosition({ wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x, rect.getPosition().y }); rect.setPosition({wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x,
rect.getPosition().y});
return true; 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]) { bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
#ifdef __APPLE__ #ifdef __APPLE__
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { for (auto [i, j] :
#else ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { #else
#endif for (auto [i, j] :
if(wall_list[i][j] == nullptr) continue; 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]); auto collision = find_intersection(*wall_list[i][j]);
if(collision == CollisionDir::None) continue; if (collision == CollisionDir::None)
if(collision == CollisionDir::Top) { continue;
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y}); 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); set_velocity_y(0);
return true; 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]) { bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
#ifdef __APPLE__ #ifdef __APPLE__
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { for (auto [i, j] :
#else ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { #else
#endif for (auto [i, j] :
if(wall_list[i][j] == nullptr) continue; 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]); auto collision = find_intersection(*wall_list[i][j]);
if(collision == CollisionDir::None) continue; if (collision == CollisionDir::None)
if(collision == CollisionDir::Bottom && get_velocity().y > 0) { continue;
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y }); 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; m_jumping = false;
set_velocity_y(0); set_velocity_y(0);
return true; return true;
+71 -79
View File
@@ -1,25 +1,25 @@
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/System.hpp>
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Window/Mouse.hpp> #include <SFML/Window/Mouse.hpp>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <iostream>
#include <string> #include <string>
#include <thread> #include <thread>
#include <iostream>
#ifdef __APPLE__ #ifdef __APPLE__
#include <range/v3/view/iota.hpp>
#include <range/v3/view/cartesian_product.hpp> #include <range/v3/view/cartesian_product.hpp>
#include <range/v3/view/iota.hpp>
#else #else
#include <ranges> #include <ranges>
#endif #endif
#include "globals.hpp"
#include "elements.hpp" #include "elements.hpp"
#include "globals.hpp"
#include "maps.hpp" #include "maps.hpp"
#include "scheduler.hpp" #include "scheduler.hpp"
@@ -31,120 +31,112 @@ int main() {
sf::Vector2i end_mouse_pos; sf::Vector2i end_mouse_pos;
bool dragging = false; bool dragging = false;
bool prev_dragging = false; bool prev_dragging = false;
// int current_level = 0; int current_level = 0;
// struct {
// sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
// sf::Vector2<float> 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;
load_map(wall_list, test_level_0); load_map(wall_list, );
// Player player { player_data player_data;
// player_data.size, player_data.pos, player_data.velocity, Player player { player_data.size, player_data.pos, player_data.velocity,
// player_data.border_size, GRAVITY, player_data.max_velocity_y, player_data.border_size, GRAVITY, player_data.max_velocity_y,
// player_data.dash_distance, sf::Color::Black, sf::Color::White 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); window.setFramerateLimit(FPS);
#ifdef __APPLE__ #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 #else
sf::Font font("/home/andrew/personal/Projects/CPP/engine/assets/pixel.ttf"); sf::Font font("/home/andrew/personal/Projects/CPP/engine/assets/pixel.ttf");
#endif #endif
sf::Text text(font, "0, 0", 16); 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; bool running = true;
// std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); } ); std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); });
while (window.isOpen()) { while (window.isOpen()) {
local_position = sf::Mouse::getPosition(window); local_position = sf::Mouse::getPosition(window);
window.clear(sf::Color::Black); 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()) { while (const std::optional event = window.pollEvent()) {
if (event->is<sf::Event::Closed>()) { if (event->is<sf::Event::Closed>()) {
// running = false; running = false;
window.close(); window.close();
} }
} }
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
// running = false; running = false;
window.close(); window.close();
} }
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
clear_map(wall_list); clear_map(wall_list);
} }
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
dragging = false; dragging = false;
} }
create_map(window, local_position, start_mouse_pos, end_mouse_pos, dragging, prev_dragging, wall_list); 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) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
// clear_map(wall_list); clear_map(wall_list);
// if(current_level == 0) { if (current_level == 0) {
// load_map(wall_list, test_level_1); load_map(wall_list, test_level_1);
// current_level = 1; current_level = 1;
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
// } } else if (current_level == 1) {
// else if(current_level == 1) { load_map(wall_list, test_level_2);
// load_map(wall_list, test_level_2); current_level = 2;
// current_level = 2; player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; } else if (current_level == 2) {
// } load_map(wall_list, test_level_0);
// else if(current_level == 2) { current_level = 0;
// load_map(wall_list, test_level_0); player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
// current_level = 0; }
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max; }
// }
// } player.handle_movment();
// if (!player.get_horizontal_collision(wall_list)) {
// player.handle_movment(); std::cout << "\n";
// if(!player.get_horizontal_collision(wall_list)) { } else {
// std::cout << "\n"; std::cout << "Yes horizontal collision\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);
// player.handle_gravity(); }
// if(player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) { if (!player.get_vertical_bottom_collision(wall_list)) {
// player.set_velocity_y((TILESIZE / 2) - GRAVITY); std::cout << "\n";
// } if (!player.get_vertical_top_collision(wall_list)) {
// if(!player.get_vertical_bottom_collision(wall_list)) { std::cout << "\n";
// std::cout << "\n"; } else {
// if(!player.get_vertical_top_collision(wall_list)) { std::cout << "Yes vertical top collision\n";
// std::cout << "\n"; }
// } else { } else {
// std::cout << "Yes vertical top collision\n"; std::cout << "Yes vertical bottom collision\n";
// } }
// }
// else {
// std::cout << "Yes vertical bottom collision\n";
// }
//
#ifdef __APPLE__ #ifdef __APPLE__
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { for (auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS),
if(wall_list[i][j] == nullptr) continue; ranges::views::iota(0, MAX_COLS))) {
if (wall_list[i][j] == nullptr)
continue;
window.draw(wall_list[i][j]->rect); window.draw(wall_list[i][j]->rect);
} }
#else #else
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { for (auto [i, j] :
if(wall_list[i][j] == nullptr) continue; 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); window.draw(wall_list[i][j]->rect);
} }
#endif #endif
// window.draw(player.rect); window.draw(player.rect);
window.draw(text); window.draw(text);
window.display(); window.display();
} }
clear_map(wall_list); clear_map(wall_list);
// player_dash_cooldown.join(); player_dash_cooldown.join();
return 0; return 0;
} }
+175 -145
View File
@@ -1,105 +1,122 @@
#include "maps.hpp" #include "maps.hpp"
#include "elements.hpp" #include "elements.hpp"
#include "globals.hpp" #include "globals.hpp"
#include <cmath>
#include <array> #include <array>
#include <cmath>
#ifdef __APPLE__ #ifdef __APPLE__
#include <range/v3/view/iota.hpp>
#include <range/v3/view/cartesian_product.hpp> #include <range/v3/view/cartesian_product.hpp>
#include <range/v3/view/iota.hpp>
namespace rv = ranges::views;
#else #else
#include <ranges> #include <ranges>
namespace rv = std::views;
#endif #endif
void clear_map(Entity* wall_list[MAX_ROWS][MAX_COLS]) { void clear_map(std::array<std::array<Entity *, MAX_COLS>, MAX_ROWS> wall_list) {
#ifdef __APPLE__ for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
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
delete wall_list[i][j]; delete wall_list[i][j];
wall_list[i][j] = nullptr; wall_list[i][j] = nullptr;
} }
} }
bool is_tiles_clear_x(std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list, int y_level, int start_x, int end_x) { bool is_tiles_clear_x(std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list, int y_level, int start_x, int end_x) {
for(int i : std::views::iota(start_x, end_x)) { for (int i : rv::iota(start_x, end_x)) {
if(draw_list[i][y_level] == ' ') continue; if (draw_list[i][y_level] == ' ')
continue;
return false; return false;
} }
return true; return true;
} }
bool is_tiles_clear_y(std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list, int x_level, int start_y, int end_y) { bool is_tiles_clear_y(std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list, int x_level, int start_y, int end_y) {
for(int i : std::views::iota(start_y, end_y)) { for (int i : rv::iota(start_y, end_y)) {
if(draw_list[i][x_level] == ' ') continue; if (draw_list[i][x_level] == ' ')
continue;
return false; return false;
} }
return true; return true;
} }
std::array<std::array<char, MAX_COLS>, 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<std::array<char, MAX_COLS>, 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<std::array<char, MAX_COLS>, MAX_ROWS> draw_list {}; std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list {};
for(auto &row : draw_list) { for (auto &row : draw_list) {
row.fill(' '); row.fill(' ');
} }
static bool vertical = false; static bool vertical = false;
if(local_position.x > 0 && local_position.x < WIDTH && local_position.y > 0 && local_position.y < HEIGHT) { 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 (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && !dragging) {
dragging = true; dragging = true;
start_mouse_pos = local_position; 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; prev_dragging = true;
end_mouse_pos = local_position; end_mouse_pos = local_position;
sf::RectangleShape rect; sf::RectangleShape rect;
if(end_mouse_pos.x - start_mouse_pos.x > end_mouse_pos.y - start_mouse_pos.y) { 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.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))} ); rect.setPosition({ (float)start_mouse_pos.x,
(float)(std::floor(start_mouse_pos.y / 32) * TILESIZE +
((float)TILESIZE / 2)) });
vertical = false; vertical = false;
} else { } else {
rect.setSize({ 1.0f, (float) (end_mouse_pos.y - start_mouse_pos.y),}); rect.setSize({
rect.setPosition({ (float)(std::floor(start_mouse_pos.x / 32) * TILESIZE + ((float)TILESIZE / 2)), (float)start_mouse_pos.y} ); 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; vertical = true;
} }
window.draw(rect); window.draw(rect);
} }
if(!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && dragging && prev_dragging) { 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 start_integers = { (int)std::floor(start_mouse_pos.x / 32),
sf::Vector2i end_integers = { (int)std::floor(end_mouse_pos.x / 32), (int)std::floor(end_mouse_pos.y / 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 (!vertical) {
if(wall_list[start_integers.y][start_integers.x] == nullptr) { 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 { wall_list[start_integers.y][start_integers.x] = new Entity {
{ float(end_integers.x - start_integers.x + 1) * TILESIZE, TILESIZE }, { TILESIZE, float(end_integers.y - start_integers.y + 1) * TILESIZE },
{ (float)(start_integers.x * TILESIZE), (float)(start_integers.y * TILESIZE) }, { (float)(start_integers.x * TILESIZE),
(float)(start_integers.y * TILESIZE) },
{ 0, 0 }, { 0, 0 },
-2.0f, -2.0f,
sf::Color::Black sf::Color::Black
}; };
draw_list[start_integers.y][start_integers.x] = '1'; draw_list[start_integers.y][start_integers.x] = '1';
draw_list[end_integers.y][end_integers.x] = '2'; draw_list[end_integers.y][end_integers.x] = '2';
for(int i : std::views::iota(start_integers.x, end_integers.x)) { for (int i : rv::iota(start_integers.y, end_integers.y)) {
draw_list[start_integers.y][i] = '-'; 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; prev_dragging = false;
dragging = false; dragging = false;
@@ -109,113 +126,126 @@ std::array<std::array<char, MAX_COLS>, MAX_ROWS> create_map(sf::RenderWindow &wi
return draw_list; return draw_list;
} }
void load_map(Entity* wall_list[MAX_ROWS][MAX_COLS], const char map_data[MAX_ROWS][MAX_COLS]) { void load_map(std::array<std::array<Entity *, MAX_COLS>, MAX_ROWS> wall_list,
#ifdef __APPLE__ const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data) {
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) { for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
#else if (map_data[i][j] == ' ')
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) { continue;
#endif if (map_data[i][j] == '0') {
if(map_data[i][j] == ' ') continue; wall_list[i][j] = new Entity { { TILESIZE, TILESIZE },
if(map_data[i][j] == '0') { { float(j * TILESIZE), float(i * TILESIZE) },
wall_list[i][j] = new Entity { { 0, 0 },
{ TILESIZE, TILESIZE }, -2.0f,
{ float(j * TILESIZE), float(i * TILESIZE) }, sf::Color::Black };
{ 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; int start = j, end = j + 1;
wall_list[i][j] = new Entity { wall_list[i][j] = new Entity { { float(end - start + 1) * TILESIZE, TILESIZE },
{ float(end - start + 1) * TILESIZE, TILESIZE }, { float(j * TILESIZE), float(i * TILESIZE) },
{ float(j * TILESIZE), float(i * TILESIZE) }, { 0, 0 },
{ 0, 0 }, -2.0f,
-2.0f, sf::Color::Black };
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; int start = i, end = i + 1;
wall_list[i][j] = new Entity { wall_list[i][j] = new Entity { { TILESIZE, float(end - start + 1) * TILESIZE },
{ TILESIZE, float(end - start + 1) * TILESIZE }, { float(j * TILESIZE), float(i * TILESIZE) },
{ float(j * TILESIZE), float(i * TILESIZE) }, { 0, 0 },
{ 0, 0 }, -2.0f,
-2.0f, sf::Color::Black };
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; int start = j, end = j;
while(end + 1 < MAX_COLS && map_data[i][end + 1] != '2') end++; while (end + 1 < MAX_COLS && map_data[i][end + 1] != '2')
if(map_data[i][end + 1] == '2') end++; end++;
wall_list[i][j] = new Entity { if (map_data[i][end + 1] == '2')
{ float(end - start + 1) * TILESIZE, TILESIZE }, end++;
{ float(j * TILESIZE), float(i * TILESIZE) }, wall_list[i][j] = new Entity { { float(end - start + 1) * TILESIZE, TILESIZE },
{ 0, 0 }, { float(j * TILESIZE), float(i * TILESIZE) },
-2.0f, { 0, 0 },
sf::Color::Black -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; int start = i, end = i;
while(end + 1 < MAX_ROWS && map_data[end + 1][j] != '2') end++; while (end + 1 < MAX_ROWS && map_data[end + 1][j] != '2')
if(map_data[end + 1][j] == '2') end++; end++;
wall_list[i][j] = new Entity { if (map_data[end + 1][j] == '2')
{ TILESIZE, float(end - start + 1) * TILESIZE }, end++;
{ float(j * TILESIZE), float(i * TILESIZE) }, wall_list[i][j] = new Entity { { TILESIZE, float(end - start + 1) * TILESIZE },
{ 0, 0 }, { float(j * TILESIZE), float(i * TILESIZE) },
-2.0f, { 0, 0 },
sf::Color::Black -2.0f,
}; sf::Color::Black };
} }
} }
} }
char test_level_0[MAX_ROWS][MAX_COLS] = { Level levels[] = {
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, .data = { {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
}; {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, },
.name = "Empty"
char test_level_1[MAX_ROWS][MAX_COLS] = { },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, {
{ '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, .data = { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, { '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, { '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, { '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' },
}; { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, },
.name = "Default"
char test_level_2[MAX_ROWS][MAX_COLS] = { },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, {
{ '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' }, .data = {
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' },
{ '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' }, { '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' }, { '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' }, { '|', ' ', ' ', ' ', ' ', '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"
}
}; };
+1
View File
@@ -1,6 +1,7 @@
// timer for player cooldown // timer for player cooldown
#include "scheduler.hpp" #include "scheduler.hpp"
#include <chrono> #include <chrono>
#include <thread> #include <thread>
void Timer::update_timers(bool &running, Times &times) { void Timer::update_timers(bool &running, Times &times) {