data driving walls
This commit is contained in:
@@ -14,6 +14,8 @@ IndentWidth: 8
|
|||||||
ContinuationIndentWidth: 8
|
ContinuationIndentWidth: 8
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
|
ReferenceAlignment: Left
|
||||||
|
IndentAccessModifiers: true
|
||||||
|
|
||||||
# Braces
|
# Braces
|
||||||
BreakBeforeBraces: Custom
|
BreakBeforeBraces: Custom
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ set(SOURCES
|
|||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/elements.cpp
|
src/elements.cpp
|
||||||
src/maps.cpp
|
src/maps.cpp
|
||||||
|
src/data.cpp
|
||||||
src/scheduler.cpp
|
src/scheduler.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
+33
-14
@@ -3,25 +3,44 @@
|
|||||||
|
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
#include "data.hpp"
|
||||||
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
enum class CollisionDir { None, Left, Right, Top, Bottom };
|
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 {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness,
|
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);
|
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(sf::Vector2f velocity);
|
||||||
void set_velocity_x(int velocity);
|
void set_velocity_x(int velocity);
|
||||||
void set_velocity_y(int velocity);
|
void set_velocity_y(int velocity);
|
||||||
sf::Vector2<float> get_velocity();
|
sf::Vector2<float> get_velocity();
|
||||||
sf::RectangleShape rect;
|
sf::RectangleShape rect;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
sf::Vector2f _velocity;
|
sf::Vector2f _velocity;
|
||||||
sf::Color _inside_color;
|
sf::Color _inside_color;
|
||||||
sf::Color _border_color;
|
sf::Color _border_color;
|
||||||
@@ -29,26 +48,26 @@ class Entity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Player : public Entity {
|
class Player : public Entity {
|
||||||
public:
|
public:
|
||||||
Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness,
|
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,
|
float gravity, float max_acceleration, float dash_distance, sf::Color inside_color,
|
||||||
sf::Color border_color);
|
|
||||||
|
sf::Color border_color);
|
||||||
float m_acceleration;
|
float m_acceleration;
|
||||||
float m_jump_strength;
|
float m_jump_strength;
|
||||||
float m_dash_distance;
|
float m_dash_distance;
|
||||||
bool m_jumping;
|
bool m_jumping;
|
||||||
bool m_dash;
|
bool m_dash;
|
||||||
Times timers;
|
void handle_movment(Timer &dash);
|
||||||
void handle_movment();
|
|
||||||
void handle_gravity();
|
void handle_gravity();
|
||||||
bool get_jumping();
|
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);
|
void vertical_no_out_of_bounds(Entity& base);
|
||||||
bool get_horizontal_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<Entity*, 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<Entity*, 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>);
|
bool get_vertical_bottom_collision_by_offset(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
|
||||||
sf::Vector2f _min_velocity;
|
sf::Vector2f _min_velocity;
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-2
@@ -1,10 +1,13 @@
|
|||||||
#ifndef GLOBALS_HPP
|
#ifndef GLOBALS_HPP
|
||||||
#define GLOBALS_HPP
|
#define GLOBALS_HPP
|
||||||
#define TILESIZE 32
|
#define TILESIZE 32
|
||||||
#define MAX_COLS 8 // 19 cols
|
#define MAX_COLS 19 // 19 cols
|
||||||
#define MAX_ROWS 8 // 13 rows
|
#define MAX_ROWS 13 // 13 rows
|
||||||
#define WIDTH TILESIZE * MAX_COLS
|
#define WIDTH TILESIZE * MAX_COLS
|
||||||
#define HEIGHT TILESIZE * MAX_ROWS
|
#define HEIGHT TILESIZE * MAX_ROWS
|
||||||
#define FPS 60
|
#define FPS 60
|
||||||
#define GRAVITY 1
|
#define GRAVITY 1
|
||||||
|
|
||||||
|
#define dash_cooldown .5
|
||||||
|
#define level_switch_cooldown_max 1
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+14
-5
@@ -8,13 +8,22 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
struct Level {
|
struct Level {
|
||||||
char data[MAX_ROWS][MAX_COLS];
|
std::array<std::array<char, MAX_COLS>, MAX_ROWS> data;
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Level levels[];
|
class Manager {
|
||||||
extern const char map[MAX_ROWS][MAX_COLS];
|
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
|
#endif
|
||||||
|
|||||||
+21
-7
@@ -1,14 +1,28 @@
|
|||||||
#ifndef SCHEDULER_HPP
|
#ifndef SCHEDULER_HPP
|
||||||
#define SCHEDULER_HPP
|
#define SCHEDULER_HPP
|
||||||
|
|
||||||
struct Times {
|
#include <ctime>
|
||||||
float dash_cooldown { 0 };
|
#include <string>
|
||||||
float dash_cooldown_max { .5 };
|
#include <vector>
|
||||||
float level_switch_cooldown { 0 };
|
|
||||||
float level_switch_cooldown_max { 1 };
|
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 {
|
struct Scheduler {
|
||||||
void update_timers(bool& running, Times& times);
|
std::vector<Timer> timers;
|
||||||
|
void update(bool& running, std::vector<Timer>& times);
|
||||||
|
int pull(std::vector<Timer>& times, std::string name);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#include "data.hpp"
|
||||||
|
#include <SFML/Graphics/Color.hpp>
|
||||||
|
|
||||||
|
std::vector<ObjectData> object_data {
|
||||||
|
{},
|
||||||
|
};
|
||||||
+47
-9
@@ -15,6 +15,21 @@ namespace rv = ranges::views;
|
|||||||
namespace rv = std::views;
|
namespace rv = std::views;
|
||||||
#endif
|
#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,
|
Entity::Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness,
|
||||||
sf::Color inside_color, sf::Color border_color) {
|
sf::Color inside_color, sf::Color border_color) {
|
||||||
rect.setSize(size);
|
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; }
|
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 a = rect.getGlobalBounds();
|
||||||
sf::FloatRect b = entity.rect.getGlobalBounds();
|
sf::FloatRect b = entity.rect.getGlobalBounds();
|
||||||
auto inter = a.findIntersection(b);
|
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;
|
m_jumping = m_dash = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::handle_movment() {
|
void Player::handle_movment(Timer &dash) {
|
||||||
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 (dash.get_time() <= 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 && dash.get_time() <= 0) {
|
||||||
m_dash = true;
|
m_dash = true;
|
||||||
_velocity.x = m_dash_distance;
|
_velocity.x = m_dash_distance;
|
||||||
timers.dash_cooldown = timers.dash_cooldown_max;
|
dash.reset();
|
||||||
}
|
}
|
||||||
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;
|
||||||
@@ -96,7 +134,7 @@ void Player::handle_gravity() {
|
|||||||
rect.move({ 0, get_velocity().y });
|
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;
|
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 });
|
||||||
@@ -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))) {
|
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
|
||||||
if (wall_list[i][j] == nullptr) continue;
|
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);
|
||||||
@@ -135,7 +173,7 @@ bool Player::get_horizontal_collision(std::array<std::array<Entity*, MAX_COLS>,
|
|||||||
return false;
|
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))) {
|
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
|
||||||
if (wall_list[i][j] == nullptr) continue;
|
if (wall_list[i][j] == nullptr) continue;
|
||||||
auto collision = find_intersection(*wall_list[i][j]);
|
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;
|
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))) {
|
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
|
||||||
if (wall_list[i][j] == nullptr) continue;
|
if (wall_list[i][j] == nullptr) continue;
|
||||||
auto collision = find_intersection(*wall_list[i][j]);
|
auto collision = find_intersection(*wall_list[i][j]);
|
||||||
|
|||||||
+50
-53
@@ -1,3 +1,4 @@
|
|||||||
|
#include "data.hpp"
|
||||||
#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>
|
||||||
@@ -7,6 +8,7 @@
|
|||||||
#include <SFML/Window/Mouse.hpp>
|
#include <SFML/Window/Mouse.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@@ -24,17 +26,18 @@ namespace rv = std::views;
|
|||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Timer time;
|
Scheduler time;
|
||||||
std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list = {};
|
Manager map_manager;
|
||||||
bool dragging = false;
|
std::vector<Timer> timers = {
|
||||||
bool prev_dragging = false;
|
Timer("dash", .5),
|
||||||
int current_level = 0;
|
Timer("level_switch", 1),
|
||||||
|
};
|
||||||
|
|
||||||
load_map(wall_list, levels[3].data);
|
map_manager.load_map(levels[1].data);
|
||||||
|
|
||||||
player_data player_data;
|
player_data player_data;
|
||||||
Player player { 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);
|
||||||
@@ -46,10 +49,10 @@ int main() {
|
|||||||
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 scheduler([&] { time.update(running, timers); });
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
window.clear(sf::Color::Black);
|
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()) {
|
while (const std::optional event = window.pollEvent()) {
|
||||||
if (event->is<sf::Event::Closed>()) {
|
if (event->is<sf::Event::Closed>()) {
|
||||||
running = false;
|
running = false;
|
||||||
@@ -62,64 +65,58 @@ int main() {
|
|||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
|
||||||
clear_map(wall_list);
|
map_manager.clear_map();
|
||||||
}
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
|
||||||
dragging = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && timers.at(1).below_or_zero()) {
|
||||||
clear_map(wall_list);
|
map_manager.clear_map();
|
||||||
if (current_level == 0) {
|
if (map_manager.get_current_level() == 1) {
|
||||||
load_map(wall_list, levels[1].data);
|
map_manager.load_map(levels[1].data);
|
||||||
current_level = 1;
|
map_manager.set_current_level(2);
|
||||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
} else if (map_manager.get_current_level() == 2) {
|
||||||
} else if (current_level == 1) {
|
map_manager.load_map(levels[2].data);
|
||||||
load_map(wall_list, levels[2].data);
|
map_manager.set_current_level(3);
|
||||||
current_level = 2;
|
} else if (map_manager.get_current_level() == 3) {
|
||||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
map_manager.load_map(levels[3].data);
|
||||||
} else if (current_level == 2) {
|
map_manager.set_current_level(1);
|
||||||
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";
|
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Yes vertical top collision\n";
|
map_manager.load_map(levels[1].data);
|
||||||
|
map_manager.set_current_level(1);
|
||||||
}
|
}
|
||||||
} else {
|
timers.at(1).reset();
|
||||||
std::cout << "Yes vertical bottom collision\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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))) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
window.draw(wall_list[i][j]->rect);
|
window.draw(map_manager.wall_list[i][j]->rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.draw(player.rect);
|
window.draw(player.rect);
|
||||||
window.draw(text);
|
window.draw(text);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
scheduler.join();
|
||||||
|
|
||||||
clear_map(wall_list);
|
map_manager.clear_map();
|
||||||
player_dash_cooldown.join();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+91
-114
@@ -1,10 +1,10 @@
|
|||||||
#include "maps.hpp"
|
#include "maps.hpp"
|
||||||
|
|
||||||
|
#include "data.hpp"
|
||||||
#include "elements.hpp"
|
#include "elements.hpp"
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cmath>
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <range/v3/view/cartesian_product.hpp>
|
#include <range/v3/view/cartesian_product.hpp>
|
||||||
#include <range/v3/view/iota.hpp>
|
#include <range/v3/view/iota.hpp>
|
||||||
@@ -14,13 +14,17 @@ namespace rv = ranges::views;
|
|||||||
namespace rv = std::views;
|
namespace rv = std::views;
|
||||||
#endif
|
#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))) {
|
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
|
||||||
delete wall_list[i][j];
|
delete wall_list[i][j];
|
||||||
wall_list[i][j] = nullptr;
|
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) {
|
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)) {
|
for (int i : rv::iota(start_x, end_x)) {
|
||||||
if (draw_list[i][y_level] == ' ') continue;
|
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;
|
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))) {
|
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] == ' ') continue;
|
||||||
if (map_data[i][j] == '0') {
|
if (map_data[i][j] == '0') {
|
||||||
wall_list[i][j] = new Entity { { TILESIZE, TILESIZE },
|
wall_list[i][j] = new Wall { object_data[0] };
|
||||||
{ float(j * TILESIZE), float(i * TILESIZE) },
|
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
|
||||||
{ 0, 0 },
|
wall_list[i][j]->rect.getPosition().y * i });
|
||||||
-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 { { float(end - start + 1) * TILESIZE, TILESIZE },
|
wall_list[i][j] = new Wall { object_data[0] };
|
||||||
{ float(j * TILESIZE), float(i * TILESIZE) },
|
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x * float(end - start + 1),
|
||||||
{ 0, 0 },
|
wall_list[i][j]->rect.getSize().y });
|
||||||
-2.0f,
|
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
|
||||||
sf::Color::Black };
|
wall_list[i][j]->rect.getPosition().y * i });
|
||||||
}
|
}
|
||||||
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 { { TILESIZE, float(end - start + 1) * TILESIZE },
|
wall_list[i][j] = new Wall { object_data[0] };
|
||||||
{ float(j * TILESIZE), float(i * TILESIZE) },
|
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x,
|
||||||
{ 0, 0 },
|
wall_list[i][j]->rect.getSize().y * float(end - start + 1) });
|
||||||
-2.0f,
|
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
|
||||||
sf::Color::Black };
|
wall_list[i][j]->rect.getPosition().y * i });
|
||||||
}
|
}
|
||||||
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') end++;
|
||||||
if (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 },
|
wall_list[i][j] = new Wall { object_data[0] };
|
||||||
{ float(j * TILESIZE), float(i * TILESIZE) },
|
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x * float(end - start + 1),
|
||||||
{ 0, 0 },
|
wall_list[i][j]->rect.getSize().y });
|
||||||
-2.0f,
|
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
|
||||||
sf::Color::Black };
|
wall_list[i][j]->rect.getPosition().y * i });
|
||||||
}
|
}
|
||||||
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') end++;
|
||||||
if (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 },
|
wall_list[i][j] = new Wall { object_data[0] };
|
||||||
{ float(j * TILESIZE), float(i * TILESIZE) },
|
wall_list[i][j]->rect.setSize({ wall_list[i][j]->rect.getSize().x,
|
||||||
{ 0, 0 },
|
wall_list[i][j]->rect.getSize().y * float(end - start + 1) });
|
||||||
-2.0f,
|
wall_list[i][j]->rect.setPosition({ wall_list[i][j]->rect.getPosition().x * j,
|
||||||
sf::Color::Black };
|
wall_list[i][j]->rect.getPosition().y * i });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Level levels[] = {
|
std::vector<Level> levels = {
|
||||||
{
|
{ .data = { { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
.data = {
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
' ' } } },
|
||||||
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, },
|
.name = "Empty" },
|
||||||
.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
@@ -1,14 +1,32 @@
|
|||||||
// 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) {
|
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) {
|
while (running) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
times.dash_cooldown--;
|
for(Timer &val : times) { val.update(); }
|
||||||
times.level_switch_cooldown--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user