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
+2
View File
@@ -14,6 +14,8 @@ IndentWidth: 8
ContinuationIndentWidth: 8
AlignAfterOpenBracket: Align
PointerAlignment: Left
ReferenceAlignment: Left
IndentAccessModifiers: true
# Braces
BreakBeforeBraces: Custom
+1
View File
@@ -10,6 +10,7 @@ set(SOURCES
src/main.cpp
src/elements.cpp
src/maps.cpp
src/data.cpp
src/scheduler.cpp
)
+26
View File
@@ -0,0 +1,26 @@
#ifndef DATA_HPP
#define DATA_HPP
#include "globals.hpp"
#include <SFML/Graphics/Color.hpp>
#include <SFML/System/Vector2.hpp>
#include <vector>
class ObjectData {
public:
sf::Vector2<float> size = { TILESIZE, TILESIZE };
sf::Vector2<float> pos = { TILESIZE, TILESIZE };
sf::Color interior_color = sf::Color::Black;
sf::Color exterior_color = sf::Color::White;
float edge = -2.0f;
};
class EntityData : public ObjectData {
public:
sf::Vector2<float> velocity;
};
extern std::vector<ObjectData> object_data;
#endif // DATA_HPP
+30 -11
View File
@@ -3,25 +3,44 @@
#include "globals.hpp"
#include "scheduler.hpp"
#include "data.hpp"
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/System/Vector2.hpp>
enum class CollisionDir { None, Left, Right, Top, Bottom };
class Entity;
class Wall;
class Player;
class Wall {
public:
Wall(ObjectData data);
ObjectData data;
sf::Vector2<float> size;
sf::Vector2<float> pos;
sf::Color interior_color;
sf::Color exterior_color;
float edge;
CollisionDir find_intersection(Entity& entity);
sf::RectangleShape rect;
};
class Entity {
public:
public:
Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness,
sf::Color inside_color = sf::Color::Black, sf::Color border_color = sf::Color::White);
CollisionDir find_intersection(Entity& entity);
CollisionDir find_intersection(Wall& entity);
void set_velocity(sf::Vector2f velocity);
void set_velocity_x(int velocity);
void set_velocity_y(int velocity);
sf::Vector2<float> get_velocity();
sf::RectangleShape rect;
protected:
protected:
sf::Vector2f _velocity;
sf::Color _inside_color;
sf::Color _border_color;
@@ -29,26 +48,26 @@ class Entity {
};
class Player : public Entity {
public:
public:
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);
float m_acceleration;
float m_jump_strength;
float m_dash_distance;
bool m_jumping;
bool m_dash;
Times timers;
void handle_movment();
void handle_movment(Timer &dash);
void handle_gravity();
bool get_jumping();
void horizontal_no_out_of_bounds(Entity& base);
void horizontal_no_out_of_bounds();
void vertical_no_out_of_bounds(Entity& base);
bool get_horizontal_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
bool get_vertical_top_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
bool get_vertical_bottom_collision(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
bool get_horizontal_collision(std::array<std::array<Wall*, MAX_COLS>, MAX_ROWS>);
bool get_vertical_top_collision(std::array<std::array<Wall*, MAX_COLS>, MAX_ROWS>);
bool get_vertical_bottom_collision(std::array<std::array<Wall*, MAX_COLS>, MAX_ROWS>);
private:
private:
bool get_vertical_bottom_collision_by_offset(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
sf::Vector2f _min_velocity;
};
+5 -2
View File
@@ -1,10 +1,13 @@
#ifndef GLOBALS_HPP
#define GLOBALS_HPP
#define TILESIZE 32
#define MAX_COLS 8 // 19 cols
#define MAX_ROWS 8 // 13 rows
#define MAX_COLS 19 // 19 cols
#define MAX_ROWS 13 // 13 rows
#define WIDTH TILESIZE * MAX_COLS
#define HEIGHT TILESIZE * MAX_ROWS
#define FPS 60
#define GRAVITY 1
#define dash_cooldown .5
#define level_switch_cooldown_max 1
#endif
+14 -5
View File
@@ -8,13 +8,22 @@
#include <array>
struct Level {
char data[MAX_ROWS][MAX_COLS];
std::array<std::array<char, MAX_COLS>, MAX_ROWS> data;
std::string name;
};
extern Level levels[];
extern const char map[MAX_ROWS][MAX_COLS];
class Manager {
public:
void clear_map();
void load_map(const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data);
int get_current_level();
void set_current_level(int level);
std::array<std::array<Wall*, MAX_COLS>, MAX_ROWS> wall_list = {};
private:
int current_level = 1;
};
extern std::vector<Level> levels;
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 char map_data[MAX_ROWS][MAX_COLS]);
#endif
+21 -7
View File
@@ -1,14 +1,28 @@
#ifndef SCHEDULER_HPP
#define SCHEDULER_HPP
struct Times {
float dash_cooldown { 0 };
float dash_cooldown_max { .5 };
float level_switch_cooldown { 0 };
float level_switch_cooldown_max { 1 };
#include <ctime>
#include <string>
#include <vector>
class Timer {
public:
Timer(std::string name, float max_time) : name(name), max_time(max_time) {};
bool below_or_zero();
float get_time();
std::string get_name();
void reset();
void update();
private:
float time = 0;
const float max_time;
const std::string name;
};
struct Timer {
void update_timers(bool& running, Times& times);
struct Scheduler {
std::vector<Timer> timers;
void update(bool& running, std::vector<Timer>& times);
int pull(std::vector<Timer>& times, std::string name);
};
#endif
+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]);
+48 -51
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,13 +26,14 @@ 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,
@@ -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";
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 horizontal collision\n";
map_manager.load_map(levels[1].data);
map_manager.set_current_level(1);
}
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";
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(); }
}
}