data driving walls

This commit is contained in:
Andrew Haynes Macbook
2026-01-14 16:05:17 -05:00
parent 1fa3293df0
commit ad2d01ab05
12 changed files with 319 additions and 209 deletions
+6
View File
@@ -0,0 +1,6 @@
#include "data.hpp"
#include <SFML/Graphics/Color.hpp>
std::vector<ObjectData> object_data {
{},
};
+47 -9
View File
@@ -15,6 +15,21 @@ namespace rv = ranges::views;
namespace rv = std::views;
#endif
Wall::Wall(ObjectData data) {
this->data = data;
// rect.setSize(data.size);
// pos = data.pos;
// interior_color = data.interior_color;
// exterior_color = data.exterior_color;
// edge = data.edge;
rect.setSize(data.size);
rect.setPosition(data.pos);
rect.setOutlineThickness(data.edge);
rect.setFillColor(data.interior_color);
rect.setOutlineColor(data.exterior_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);
@@ -33,7 +48,30 @@ void Entity::set_velocity_y(int velocity) { _velocity.y = velocity; }
sf::Vector2<float> Entity::get_velocity() { return _velocity; }
CollisionDir Entity::find_intersection(Entity& entity) {
CollisionDir Wall::find_intersection(Entity& entity) {
sf::FloatRect a = rect.getGlobalBounds();
sf::FloatRect b = entity.rect.getGlobalBounds();
auto inter = a.findIntersection(b);
if (!inter) {
return CollisionDir::None;
}
const auto overlap = *inter;
float overlapW = overlap.size.x;
float overlapH = overlap.size.y;
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
} else {
return (a.position.y < b.position.y) ? CollisionDir::Bottom : CollisionDir::Top;
}
}
CollisionDir Entity::find_intersection(Wall& entity) {
sf::FloatRect a = rect.getGlobalBounds();
sf::FloatRect b = entity.rect.getGlobalBounds();
auto inter = a.findIntersection(b);
@@ -66,20 +104,20 @@ Player::Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f vel
m_jumping = m_dash = false;
}
void Player::handle_movment() {
void Player::handle_movment(Timer &dash) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
rect.move({ _velocity.x, 0 });
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
rect.move({ -_velocity.x, 0 });
}
if (timers.dash_cooldown <= 0) {
if (dash.get_time() <= 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 && dash.get_time() <= 0) {
m_dash = true;
_velocity.x = m_dash_distance;
timers.dash_cooldown = timers.dash_cooldown_max;
dash.reset();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !m_jumping) {
m_jumping = true;
@@ -96,7 +134,7 @@ void Player::handle_gravity() {
rect.move({ 0, get_velocity().y });
}
void Player::horizontal_no_out_of_bounds(Entity& base) {
void Player::horizontal_no_out_of_bounds() {
float right_border = WIDTH - rect.getSize().x;
if (rect.getPosition().x > right_border) {
rect.setPosition({ right_border, rect.getPosition().y });
@@ -116,7 +154,7 @@ void Player::vertical_no_out_of_bounds(Entity& base) {
}
}
bool Player::get_horizontal_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list) {
bool Player::get_horizontal_collision(std::array<std::array<Wall*, MAX_COLS>, MAX_ROWS> wall_list) {
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
if (wall_list[i][j] == nullptr) continue;
auto collision = wall_list[i][j]->find_intersection(*this);
@@ -135,7 +173,7 @@ bool Player::get_horizontal_collision(std::array<std::array<Entity*, MAX_COLS>,
return false;
}
bool Player::get_vertical_top_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list) {
bool Player::get_vertical_top_collision(std::array<std::array<Wall*, MAX_COLS>, MAX_ROWS> wall_list) {
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
if (wall_list[i][j] == nullptr) continue;
auto collision = find_intersection(*wall_list[i][j]);
@@ -150,7 +188,7 @@ bool Player::get_vertical_top_collision(std::array<std::array<Entity*, MAX_COLS>
return false;
}
bool Player::get_vertical_bottom_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list) {
bool Player::get_vertical_bottom_collision(std::array<std::array<Wall*, MAX_COLS>, MAX_ROWS> wall_list) {
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
if (wall_list[i][j] == nullptr) continue;
auto collision = find_intersection(*wall_list[i][j]);
+50 -53
View File
@@ -1,3 +1,4 @@
#include "data.hpp"
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
@@ -7,6 +8,7 @@
#include <SFML/Window/Mouse.hpp>
#include <cstdlib>
#include <iostream>
#include <string>
#include <thread>
#ifdef __APPLE__
@@ -24,17 +26,18 @@ namespace rv = std::views;
#include "scheduler.hpp"
int main() {
Timer time;
std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list = {};
bool dragging = false;
bool prev_dragging = false;
int current_level = 0;
Scheduler time;
Manager map_manager;
std::vector<Timer> timers = {
Timer("dash", .5),
Timer("level_switch", 1),
};
load_map(wall_list, levels[3].data);
map_manager.load_map(levels[1].data);
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 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);
@@ -46,10 +49,10 @@ int main() {
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); });
std::thread scheduler([&] { time.update(running, timers); });
while (window.isOpen()) {
window.clear(sf::Color::Black);
text.setString("Test");
text.setString(std::to_string(timers.at(0).get_time()));
while (const std::optional event = window.pollEvent()) {
if (event->is<sf::Event::Closed>()) {
running = false;
@@ -62,64 +65,58 @@ int main() {
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
clear_map(wall_list);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
dragging = false;
map_manager.clear_map();
}
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, levels[1].data);
current_level = 1;
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
} else if (current_level == 1) {
load_map(wall_list, levels[2].data);
current_level = 2;
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
} else if (current_level == 2) {
load_map(wall_list, levels[3].data);
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";
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && timers.at(1).below_or_zero()) {
map_manager.clear_map();
if (map_manager.get_current_level() == 1) {
map_manager.load_map(levels[1].data);
map_manager.set_current_level(2);
} else if (map_manager.get_current_level() == 2) {
map_manager.load_map(levels[2].data);
map_manager.set_current_level(3);
} else if (map_manager.get_current_level() == 3) {
map_manager.load_map(levels[3].data);
map_manager.set_current_level(1);
} else {
std::cout << "Yes vertical top collision\n";
map_manager.load_map(levels[1].data);
map_manager.set_current_level(1);
}
} else {
std::cout << "Yes vertical bottom collision\n";
timers.at(1).reset();
}
// player.handle_movment(timers.at(time.pull(timers, "dash")));
// if (!player.get_horizontal_collision(map_manager.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(map_manager.wall_list)) {
// std::cout << "\n";
// if (!player.get_vertical_top_collision(map_manager.wall_list)) {
// std::cout << "\n";
// } else {
// std::cout << "Yes vertical top collision\n";
// }
// } else { std::cout << "Yes vertical bottom collision\n"; }
//
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
if (wall_list[i][j] == nullptr) {
if (map_manager.wall_list[i][j] == nullptr) {
continue;
}
window.draw(wall_list[i][j]->rect);
window.draw(map_manager.wall_list[i][j]->rect);
}
window.draw(player.rect);
window.draw(text);
window.display();
}
scheduler.join();
clear_map(wall_list);
player_dash_cooldown.join();
map_manager.clear_map();
return 0;
}
+91 -114
View File
@@ -1,10 +1,10 @@
#include "maps.hpp"
#include "data.hpp"
#include "elements.hpp"
#include "globals.hpp"
#include <array>
#include <cmath>
#ifdef __APPLE__
#include <range/v3/view/cartesian_product.hpp>
#include <range/v3/view/iota.hpp>
@@ -14,13 +14,17 @@ namespace rv = ranges::views;
namespace rv = std::views;
#endif
void clear_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>& wall_list) {
void Manager::clear_map() {
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;
}
}
int Manager::get_current_level() { return current_level; }
void Manager::set_current_level(int level) { current_level = level; }
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 : rv::iota(start_x, end_x)) {
if (draw_list[i][y_level] == ' ') continue;
@@ -37,139 +41,112 @@ bool is_tiles_clear_y(std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list
return true;
}
void load_map(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>& wall_list, const char map_data[MAX_ROWS][MAX_COLS]) {
void Manager::load_map(const std::array<std::array<char, MAX_COLS>, 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 };
wall_list[i][j] = new Wall { object_data[0] };
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
wall_list[i][j]->rect.getPosition().y * i });
}
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 Wall { object_data[0] };
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x * float(end - start + 1),
wall_list[i][j]->rect.getSize().y });
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
wall_list[i][j]->rect.getPosition().y * i });
}
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 Wall { object_data[0] };
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x,
wall_list[i][j]->rect.getSize().y * float(end - start + 1) });
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
wall_list[i][j]->rect.getPosition().y * i });
}
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 };
wall_list[i][j] = new Wall { object_data[0] };
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x * float(end - start + 1),
wall_list[i][j]->rect.getSize().y });
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
wall_list[i][j]->rect.getPosition().y * i });
}
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 };
wall_list[i][j] = new Wall { object_data[0] };
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x,
wall_list[i][j]->rect.getSize().y * float(end - start + 1) });
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
wall_list[i][j]->rect.getPosition().y * i });
}
}
}
Level levels[] = {
{
.data = {
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, },
.name = "Empty"
}
std::vector<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 = "Plat1" },
{ .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 = "Check" }
};
// 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"
// }
// };
+23 -5
View File
@@ -1,14 +1,32 @@
// timer for player cooldown
#include "scheduler.hpp"
#include <chrono>
#include <thread>
void Timer::update_timers(bool& running, Times& times) {
bool Timer::below_or_zero() {
if(time <= 0) { return true; }
return false;
}
float Timer::get_time() { return time; }
std::string Timer::get_name() { return name; }
void Timer::reset() { time = max_time; }
void Timer::update() { if(!below_or_zero()) { time--; } }
int Scheduler::pull(std::vector<Timer>& times, std::string name) {
for(int i = 0; i < times.size(); i++) {
if(times[i].get_name() == name) { return i; }
}
return -1;
}
void Scheduler::update(bool& running, std::vector<Timer>& times) {
while (running) {
std::this_thread::sleep_for(std::chrono::seconds(1));
times.dash_cooldown--;
times.level_switch_cooldown--;
for(Timer &val : times) { val.update(); }
}
}