player bounding box almost there

This commit is contained in:
Andrew Haynes Macbook
2026-01-23 09:22:39 -05:00
parent 06d3f27b1e
commit a3589fd93d
12 changed files with 679 additions and 490 deletions
+148 -79
View File
@@ -1,12 +1,17 @@
#include "data.hpp"
#include "globals.hpp"
#include <SFML/Graphics/Color.hpp>
#include <vector>
#include "globals.hpp"
std::vector<ObjectData> object_data {
{},
{
.interior_color = sf::Color::Transparent,
.exterior_color = sf::Color::White,
.edge = -1,
},
};
/*
@@ -27,99 +32,163 @@ std::vector<EntityData> entity_data {
std::vector<TimerData> timer_data {
{},
{
.name = "Dash",
.max_time = .5,
.name = "Dash",
.max_time = 1,
},
{
.name = "Level_Switch",
.max_time = 1,
.name = "Level_Switch",
.max_time = 1,
},
};
PlayerData player_data = [] {
PlayerData player_data = []
{
PlayerData data;
data.size = { TILESIZE / 2.0f, TILESIZE / 2.0f };
data.edge = -1.0f;
data.velocity = { 3.0f, 0.0f };
data.dash_length = 15.0f; // 15
data.max_dash_acceleration = 15.0f; // 15
data.max_vertical_acceleration = 12.5f;
return data;
}();
std::vector<LevelData> level_data = {
{ .data = { { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ' } } }
{ .data = { { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' } } } },
{
.data = { { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-', '-', '2' },
{ '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '1' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ',
' ', ' ', ' ', '|' },
{ '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ',
' ', ' ', ' ', '2' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-', '-', '2' } } },
},
{ .data = { { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' },
{ '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', '1', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' },
{ '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'2' } } },
{
.data = { { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-', '-', '2' },
{ '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '1' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ',
' ', ' ', ' ', '|' },
{ '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ',
' ', ' ', ' ', '2' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-', '-', '2' } } },
},
{ .data = { { { '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2' },
{ '1', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', '-', '-', '-', '-', '2', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|' },
{ '|', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '1', ' ', ' ', ' ', ' ', '|' },
{ '2', ' ', ' ', ' ', ' ', '2', '0', ' ', ' ', ' ', ' ', ' ', ' ', '2', ' ', ' ', ' ', ' ', '2' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'2' } } },
{
.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' } } },
},
{ .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' } } },
},
{ .data = { { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'2' } } },
{
.data = { { { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' },
{ '1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
'-', '-', '-', '2' } } },
},
};
+214 -71
View File
@@ -1,12 +1,16 @@
#include "elements.hpp"
#include "data.hpp"
#include "globals.hpp"
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <cmath>
#include <iostream>
#include <memory>
#include "data.hpp"
#include "globals.hpp"
#ifdef __APPLE__
#include <range/v3/view/cartesian_product.hpp>
#include <range/v3/view/iota.hpp>
@@ -16,7 +20,8 @@ namespace rv = ranges::views;
namespace rv = std::views;
#endif
Object::Object(ObjectData data) {
Object::Object(ObjectData data)
{
rect.setSize(data.size);
rect.setPosition(data.pos);
rect.setOutlineThickness(data.edge);
@@ -24,19 +29,38 @@ Object::Object(ObjectData data) {
rect.setOutlineColor(data.exterior_color);
}
void Entity::set_velocity(sf::Vector2<float> velocity) { _velocity = velocity; }
void
Entity::set_velocity(sf::Vector2<float> velocity)
{
_velocity = velocity;
}
void Entity::set_velocity_x(int velocity) { _velocity.x = velocity; }
void
Entity::set_velocity_x(int velocity)
{
_velocity.x = velocity;
}
void Entity::set_velocity_y(int velocity) { _velocity.y = velocity; }
void
Entity::set_velocity_y(int velocity)
{
_velocity.y = velocity;
}
sf::Vector2<float> Entity::get_velocity() { return _velocity; }
sf::Vector2<float>
Entity::get_velocity()
{
return _velocity;
}
CollisionDir Object::find_intersection(Object& entity) {
CollisionDir
Object::find_intersection(Object& entity)
{
sf::FloatRect a = rect.getGlobalBounds();
sf::FloatRect b = entity.rect.getGlobalBounds();
auto inter = a.findIntersection(b);
if (!inter) {
if (!inter)
{
return CollisionDir::None;
}
@@ -45,121 +69,234 @@ CollisionDir Object::find_intersection(Object& entity) {
float overlapW = overlap.size.x;
float overlapH = overlap.size.y;
if (overlapW < overlapH) {
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.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;
}
}
float
Object::find_horizontal_difference_from_interesection(Object& entity)
{
sf::FloatRect a = rect.getGlobalBounds();
sf::FloatRect b = entity.rect.getGlobalBounds();
auto inter = a.findIntersection(b);
if (!inter)
{
return 0;
}
const auto overlap = *inter;
return (a.position.x < b.position.x)
? b.position.x - a.position.x // a hit b from the left side
: a.position.x - b.position.x; // a hit b from the right side
}
/* Bounding Box
* Create on dash in front of player and check if the box collides with a wall,
* if so find the difference of the wall and the player and set the dash_distance
* to difference.
* */
void Player::initialize_bounding_box() {
bounding_box.setOutlineColor(sf::Color::White);
bounding_box.setFillColor(sf::Color::Transparent);
bounding_box.setOutlineThickness(-1);
bounding_box.setSize({ dash_length, rect.getSize().y });
bounding_box.setOrigin({ rect.getPosition().x, rect.getPosition().y / 2 });
bounding_box.setPosition({ bounding_box.getOrigin().x, bounding_box.getOrigin().y });
float
total_distance(int k)
{
if (k > 0) return k + total_distance(k - 1);
else return 0;
}
void Player::update_bounding_box() {
// Player and box positive distances are 108 in both x and y
bounding_box.setOrigin(
{ -rect.getPosition().x + bounding_box.getGeometricCenter().x + (rect.getSize().x / 2),
-rect.getPosition().y + bounding_box.getGeometricCenter().y + (rect.getSize().y / 2) });
float
distance_to_acceleration(int target)
{
return roundf(-1 + sqrtf(1 + 8 * target) / 2);
}
void Player::check_bounding_box(std::array<std::array<Object*, 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;
void
Player::initialize_bounding_box()
{
bounding_box = std::make_unique<Object>(object_data[1]);
float length = total_distance(max_dash_acceleration);
if (direction == "left")
{
bounding_box->rect.setSize({ -length, rect.getSize().y });
}
else if (direction == "right")
{
bounding_box->rect.setSize({ length, rect.getSize().y });
}
bounding_box->rect.setPosition({ rect.getPosition().x, rect.getPosition().y });
}
void Player::handle_movment(Timer& dash) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
void
Player::update_bounding_box()
{
bounding_box->rect.setPosition({ rect.getPosition().x, rect.getPosition().y });
}
int
Player::check_bounding_box(
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap)
{
int distance = 0;
/*
* The box checks the wall farthest into the hitbox and not the closest one to the player
*
* Best idea is to just check if there is a collision and set hitbox to that size and then
* see if that checks the one closest to the player
*
* Make a way to find the shortest distance on the collsion becuase the wall closest to the
* player will ahve a shorter difference_from_interesection than a one further from it will
*
* */
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS)))
{
if (tilemap[i][j] == nullptr) continue;
if (bounding_box->find_horizontal_difference_from_interesection(*tilemap[i][j]) > 0)
{
std::cout << "Intersection: "
<< bounding_box->find_horizontal_difference_from_interesection(
*tilemap[i][j])
<< "\n";
bounding_box->rect.setSize(
{ bounding_box->find_horizontal_difference_from_interesection(
*tilemap[i][j]),
bounding_box->rect.getSize().y });
distance = bounding_box->rect.getSize().x;
max_dash_acceleration = distance_to_acceleration(distance);
}
else if (bounding_box->find_horizontal_difference_from_interesection(
*tilemap[i][j]) <= 0 &&
bounding_box->rect.getSize().x <= total_distance(15))
{
bounding_box->rect.setSize(
{ bounding_box->rect.getSize().x + 1, bounding_box->rect.getSize().y });
max_dash_acceleration =
distance_to_acceleration(bounding_box->rect.getSize().x);
}
}
return distance;
}
void
Player::handle_movment(Timer& dash)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
{
direction = "right";
rect.move({ _velocity.x, 0 });
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
{
direction = "left";
rect.move({ -_velocity.x, 0 });
}
if (dash.get_time() <= 0) {
m_dash = false;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W) && !m_dash && dash.get_time() <= 0) {
m_dash = true;
_velocity.x = dash_length;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W) && dash.get_time() <= 0)
{
// Dash order: spawn hitbox, check distance and set max_dash_acceleration
// Outside of this set max_dash_acceleration back to 15 { default }
max_dash_acceleration = player_data.max_dash_acceleration;
initialize_bounding_box();
_velocity.x = max_dash_acceleration;
dash.reset();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !m_jumping && _velocity.x <= 3) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !m_jumping && _velocity.x <= 3)
{
m_jumping = true;
_velocity.y = -max_vertical_acceleration; // push up
_velocity.y = -max_vertical_acceleration; // push up
}
}
void Player::handle_gravity() {
if (get_velocity().x > player_data.velocity.x) {
void
Player::handle_gravity()
{
if (get_velocity().x > player_data.velocity.x)
{
set_velocity_x(get_velocity().x - gravity);
}
if (get_velocity().x <= player_data.velocity.x)
{
bounding_box.reset();
}
set_velocity_y(get_velocity().y + gravity);
rect.move({ 0, get_velocity().y });
}
void Player::horizontal_no_out_of_bounds() {
void
Player::horizontal_no_out_of_bounds()
{
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 });
}
if (rect.getPosition().x < std::abs(rect.getOutlineThickness())) {
if (rect.getPosition().x < std::abs(rect.getOutlineThickness()))
{
rect.setPosition({ 0, rect.getPosition().y });
}
}
void Player::vertical_no_out_of_bounds(Entity& base) {
void
Player::vertical_no_out_of_bounds(Entity& base)
{
float groundY = base.rect.getPosition().y - base.rect.getSize().y - rect.getSize().y -
base.rect.getOutlineThickness() - rect.getOutlineThickness();
if (rect.getPosition().y >= groundY) {
if (rect.getPosition().y >= groundY)
{
rect.setPosition({ rect.getPosition().x, groundY });
set_velocity_y(0);
m_jumping = false;
}
}
bool Player::get_horizontal_collision(std::array<std::array<Object*, 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);
bool
Player::get_horizontal_collision(
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap)
{
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS)))
{
if (tilemap[i][j] == nullptr) continue;
auto collision = tilemap[i][j]->find_intersection(*this);
if (collision == CollisionDir::None) continue;
if (collision == CollisionDir::Left) {
rect.setPosition(
{ wall_list[i][j]->rect.getPosition().x - rect.getSize().x, rect.getPosition().y });
if (collision == CollisionDir::Left)
{
rect.setPosition({ tilemap[i][j]->rect.getPosition().x - rect.getSize().x,
rect.getPosition().y });
return true;
}
if (collision == CollisionDir::Right) {
rect.setPosition({ wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x,
rect.getPosition().y });
if (collision == CollisionDir::Right)
{
rect.setPosition(
{ tilemap[i][j]->rect.getPosition().x + tilemap[i][j]->rect.getSize().x,
rect.getPosition().y });
return true;
}
}
return false;
}
bool Player::get_vertical_top_collision(std::array<std::array<Object*, 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]);
bool
Player::get_vertical_top_collision(
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap)
{
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS)))
{
if (tilemap[i][j] == nullptr) continue;
auto collision = find_intersection(*tilemap[i][j]);
if (collision == CollisionDir::None) continue;
if (collision == CollisionDir::Top) {
rect.setPosition({ rect.getPosition().x,
wall_list[i][j]->rect.getSize().y + wall_list[i][j]->rect.getPosition().y });
if (collision == CollisionDir::Top)
{
rect.setPosition(
{ rect.getPosition().x, tilemap[i][j]->rect.getSize().y +
tilemap[i][j]->rect.getPosition().y });
set_velocity_y(0);
return true;
}
@@ -167,14 +304,20 @@ bool Player::get_vertical_top_collision(std::array<std::array<Object*, MAX_COLS>
return false;
}
bool Player::get_vertical_bottom_collision(std::array<std::array<Object*, 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]);
bool
Player::get_vertical_bottom_collision(
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap)
{
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS)))
{
if (tilemap[i][j] == nullptr) continue;
auto collision = find_intersection(*tilemap[i][j]);
if (collision == CollisionDir::None) continue;
if (collision == CollisionDir::Bottom && get_velocity().y > 0) {
if (collision == CollisionDir::Bottom && get_velocity().y > 0)
{
rect.setPosition(
{ rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y });
{ rect.getPosition().x,
tilemap[i][j]->rect.getPosition().y - rect.getSize().y });
m_jumping = false;
set_velocity_y(0);
return true;
+52 -39
View File
@@ -1,5 +1,3 @@
#include "data.hpp"
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/CircleShape.hpp>
@@ -31,85 +29,100 @@ std::string assets = "/home/andrew/personal/Projects/CPP/engine/assets/";
#include "maps.hpp"
#include "scheduler.hpp"
int main() {
int
main()
{
// float dist = total_distance(12);
// std::cout << "Distance: " << dist << "\n";
// float acc = distance_to_acceleration(total_distance(12));
// std::cout << "Distance: " << acc << "\n";
Scheduler scheduler;
Manager map_manager;
sf::Font font(assets + "pixel.ttf");
Player player { player_data, GRAVITY };
Object test_object { object_data[0] };
sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default);
bool running { true };
sf::Text text(font, "0, 0", 16);
map_manager.load(level_data[BASE]);
std::atomic<bool> running { true };
sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default);
window.setFramerateLimit(FPS);
player.initialize_bounding_box();
map_manager.load(level_data[4].data);
Player player { player_data, GRAVITY };
// player.initialize_bounding_box(player.get_velocity().x);
sf::Font font(assets + "pixel.ttf");
sf::Text text(font, "0, 0", 16);
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5) });
std::thread scheduler_thread([&] { scheduler.update(running); });
std::jthread scheduler_thread([&] { scheduler.update(running); });
while (window.isOpen()) {
std::cout <<
while (window.isOpen())
{
window.clear(sf::Color::Black);
test_object.rect.setPosition(
{ player.rect.getPosition().x + 108 - player.rect.getSize().x, player.rect.getPosition().y });
test_object.rect.setPosition({ player.rect.getPosition().x - 108, player.rect.getPosition().y });
text.setString(std::to_string(scheduler.timers.at(0).get_time()));
while (const std::optional event = window.pollEvent()) {
if (event->is<sf::Event::Closed>()) {
while (const std::optional event = window.pollEvent())
{
if (event->is<sf::Event::Closed>())
{
running = false;
window.close();
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
{
running = false;
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
for (int i = 0; i < player.bounding_box.getPointCount(); i++) {
std::cout << "(" << player.bounding_box.getPoint(i).x << ", " << player.bounding_box.getPoint(i).y
<< ")\n";
}
std::cout << "\n";
// sf::FloatRect a = player.bounding_box.getGlobalBounds();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::C))
{
player.bounding_box->rect.setSize(
{ total_distance(player.max_dash_acceleration),
player.bounding_box->rect.getSize().y });
}
if (map_manager.get_active() >= level_data.size()) {
if (map_manager.get_active() >= level_data.size())
{
map_manager.set_active(DEFAULT);
map_manager.load(level_data[DEFAULT].data);
map_manager.load(level_data[DEFAULT]);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && scheduler.timers.at(1).below_or_zero()) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) &&
scheduler.timers.at(1).below_or_zero())
{
map_manager.set_next();
scheduler.timers.at(1).reset();
}
player.update_bounding_box();
player.handle_movment(scheduler.timers.at(scheduler.pull("Dash")));
player.get_horizontal_collision(map_manager.wall_list);
player.get_horizontal_collision(map_manager.tilemap);
player.handle_gravity();
if (player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) {
std::cout << "Vel: " << player.get_velocity().x << ", " << player.get_velocity().y
<< "\n";
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)) {
player.get_vertical_top_collision(map_manager.wall_list);
if (!player.get_vertical_bottom_collision(map_manager.tilemap))
{
player.get_vertical_top_collision(map_manager.tilemap);
}
if (player.bounding_box != nullptr)
{
player.update_bounding_box();
player.check_bounding_box(map_manager.tilemap);
}
map_manager.draw(window);
window.draw(player.rect);
window.draw(player.bounding_box);
if (player.bounding_box != nullptr)
{
window.draw(player.bounding_box->rect);
}
window.draw(text);
window.draw(test_object.rect);
window.display();
}
scheduler_thread.join();
map_manager.clear();
return 0;
+75 -47
View File
@@ -1,11 +1,12 @@
#include "maps.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <array>
#include <memory>
#include "data.hpp"
#include "elements.hpp"
#include "globals.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <array>
#ifdef __APPLE__
#include <range/v3/view/cartesian_product.hpp>
#include <range/v3/view/iota.hpp>
@@ -15,79 +16,106 @@ namespace rv = ranges::views;
namespace rv = std::views;
#endif
void Manager::clear() {
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;
void
Manager::clear()
{
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS)))
{
tilemap[i][j] = nullptr;
}
}
int Manager::get_active() { return _active; }
int
Manager::get_active()
{
return _active;
}
void Manager::set_active(int level) { _active = level; }
void
Manager::set_active(int new_level)
{
_active = new_level;
}
void Manager::set_next() {
void
Manager::set_next()
{
_active++;
clear();
load(level_data[_active].data);
load(level_data[_active]);
}
void Manager::set_previous() {
void
Manager::set_previous()
{
_active--;
clear();
load(level_data[_active].data);
load(level_data[_active]);
}
void Manager::draw(sf::RenderWindow& window) {
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
if (wall_list[i][j] == nullptr) continue;
window.draw(wall_list[i][j]->rect);
void
Manager::draw(sf::RenderWindow& window)
{
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS)))
{
if (tilemap[i][j] == nullptr) continue;
window.draw(tilemap[i][j]->rect);
}
}
void Manager::load(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))) {
void
Manager::load(LevelData level)
{
const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data = level.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 Object { 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] == '0')
{
tilemap[i][j] = std::make_unique<Object>(object_data[0]);
// tilemap[i][j] = new Object { object_data[0] };
tilemap[i][j]->rect.setPosition(
{ tilemap[i][j]->rect.getPosition().x * j, tilemap[i][j]->rect.getPosition().y * i });
}
if (map_data[i][j] == '1' && j + 1 < MAX_COLS && map_data[i][j + 1] == '2') {
if (map_data[i][j] == '1' && j + 1 < MAX_COLS && map_data[i][j + 1] == '2')
{
int start = j, end = j + 1;
wall_list[i][j] = new Object { 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 });
tilemap[i][j] = std::make_unique<Object>(object_data[0]);
tilemap[i][j]->rect.setSize({ tilemap[i][j]->rect.getSize().x * float(end - start + 1),
tilemap[i][j]->rect.getSize().y });
tilemap[i][j]->rect.setPosition(
{ tilemap[i][j]->rect.getPosition().x * j, tilemap[i][j]->rect.getPosition().y * i });
}
if (map_data[i][j] == '1' && i + 1 < MAX_ROWS && map_data[i + 1][j] == '2') {
if (map_data[i][j] == '1' && i + 1 < MAX_ROWS && map_data[i + 1][j] == '2')
{
int start = i, end = i + 1;
wall_list[i][j] = new Object { 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 });
tilemap[i][j] = std::make_unique<Object>(object_data[0]);
tilemap[i][j]->rect.setSize({ tilemap[i][j]->rect.getSize().x,
tilemap[i][j]->rect.getSize().y * float(end - start + 1) });
tilemap[i][j]->rect.setPosition(
{ tilemap[i][j]->rect.getPosition().x * j, tilemap[i][j]->rect.getPosition().y * i });
}
if (map_data[i][j] == '1' && j + 1 < MAX_COLS && map_data[i][j + 1] == '-') {
if (map_data[i][j] == '1' && j + 1 < MAX_COLS && 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 Object { 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 });
tilemap[i][j] = std::make_unique<Object>(object_data[0]);
tilemap[i][j]->rect.setSize({ tilemap[i][j]->rect.getSize().x * float(end - start + 1),
tilemap[i][j]->rect.getSize().y });
tilemap[i][j]->rect.setPosition(
{ tilemap[i][j]->rect.getPosition().x * j, tilemap[i][j]->rect.getPosition().y * i });
}
if (map_data[i][j] == '1' && i + 1 < MAX_ROWS && map_data[i + 1][j] == '|') {
if (map_data[i][j] == '1' && i + 1 < MAX_ROWS && 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 Object { 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 });
tilemap[i][j] = std::make_unique<Object>(object_data[0]);
tilemap[i][j]->rect.setSize({ tilemap[i][j]->rect.getSize().x,
tilemap[i][j]->rect.getSize().y * float(end - start + 1) });
tilemap[i][j]->rect.setPosition(
{ tilemap[i][j]->rect.getPosition().x * j, tilemap[i][j]->rect.getPosition().y * i });
}
}
}
+48 -15
View File
@@ -1,47 +1,80 @@
#include "scheduler.hpp"
#include "data.hpp"
#include <chrono>
#include <iostream>
#include <thread>
#include <vector>
Scheduler::Scheduler() {
#include "data.hpp"
Scheduler::Scheduler()
{
timers.push_back(timer_data[DASH]);
timers.push_back(timer_data[LEVEL_SWITCH]);
}
bool Timer::below_or_zero() {
if(time <= 0) { return true; }
bool
Timer::below_or_zero()
{
if (time <= 0) {
return true;
}
return false;
}
float Timer::get_time() { return time; }
float
Timer::get_time()
{
return time;
}
std::string Timer::get_name() { return name; }
std::string
Timer::get_name()
{
return name;
}
void Timer::reset() { time = max_time; }
void
Timer::reset()
{
time = max_time;
}
void Timer::update() { if(!below_or_zero()) { time--; } }
void
Timer::update()
{
if (!below_or_zero()) {
time--;
}
}
int Scheduler::pull(std::string name) {
int
Scheduler::pull(std::string name)
{
try {
for(int i = 0; i < timers.size(); i++) {
if(timers[i].get_name() == name) { return i; }
for (int i = 0; i < timers.size(); i++) {
if (timers[i].get_name() == name) {
return i;
}
}
throw -1;
} catch (int x) {
}
catch (int x) {
std::cout << "No valid timer with name: (" << name << ") as a value\n";
std::cout << "Using defualt timer values\n";
return -1;
}
return 0;
}
void Scheduler::update(bool& running) {
void
Scheduler::update(std::atomic<bool>& running)
{
while (running) {
std::this_thread::sleep_for(std::chrono::seconds(1));
for(Timer &val : timers) { val.update(); }
for (Timer& val : timers) {
val.update();
}
}
}