This commit is contained in:
Gentoo
2026-01-14 20:57:15 -05:00
parent ad2d01ab05
commit 7bbf50b581
7 changed files with 204 additions and 254 deletions
+25 -9
View File
@@ -5,22 +5,38 @@
#include <SFML/Graphics/Color.hpp>
#include <SFML/System/Vector2.hpp>
#include <array>
#include <string>
#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;
struct ObjectData {
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 {
struct EntityData : ObjectData {
sf::Vector2<float> velocity { 0, 0 };
};
struct PlayerData : EntityData {
ObjectData object;
EntityData entity;
float dash_length { 0.0f };
float max_vertical_acceleration { 0.0f };
};
class LevelData {
public:
sf::Vector2<float> velocity;
std::array<std::array<char, MAX_COLS>, MAX_ROWS> data = {};
std::string name = "Null";
};
extern std::vector<ObjectData> object_data;
extern std::vector<EntityData> entity_data;
extern std::vector<LevelData> level_data;
extern PlayerData player_data;
#endif // DATA_HPP
+34 -60
View File
@@ -1,9 +1,9 @@
#ifndef PLAYER_HPP
#define PLAYER_HPP
#include "data.hpp"
#include "globals.hpp"
#include "scheduler.hpp"
#include "data.hpp"
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
@@ -11,74 +11,48 @@
enum class CollisionDir { None, Left, Right, Top, Bottom };
class Entity;
class Wall;
class Object;
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 Object {
public:
Object(ObjectData data);
CollisionDir find_intersection(Object& entity);
sf::RectangleShape rect;
};
class Entity {
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);
class Entity : public Object {
public:
Entity(EntityData data) : Object(data), _velocity(data.velocity) {};
void set_velocity(sf::Vector2f velocity);
void set_velocity_x(int velocity);
void set_velocity_y(int velocity);
sf::Vector2<float> get_velocity();
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:
sf::Vector2f _velocity;
sf::Color _inside_color;
sf::Color _border_color;
float _border_thickness;
protected:
sf::Vector2f _velocity;
};
class Player : public Entity {
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,
public:
Player(PlayerData data, float gravity) : Entity(data), dash_length(data.dash_length), max_vertical_acceleration(data.max_vertical_acceleration), gravity(gravity) {};
float max_vertical_acceleration;
float dash_length;
float gravity;
bool m_jumping { false };
bool m_dash { false };
void handle_movment(Timer& dash);
void handle_gravity();
bool get_jumping();
void horizontal_no_out_of_bounds();
void vertical_no_out_of_bounds(Entity& base);
bool get_horizontal_collision(std::array<std::array<Object*, MAX_COLS>, MAX_ROWS>);
bool get_vertical_top_collision(std::array<std::array<Object*, MAX_COLS>, MAX_ROWS>);
bool get_vertical_bottom_collision(std::array<std::array<Object*, MAX_COLS>, MAX_ROWS>);
sf::Color border_color);
float m_acceleration;
float m_jump_strength;
float m_dash_distance;
bool m_jumping;
bool m_dash;
void handle_movment(Timer &dash);
void handle_gravity();
bool get_jumping();
void horizontal_no_out_of_bounds();
void vertical_no_out_of_bounds(Entity& base);
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:
bool get_vertical_bottom_collision_by_offset(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
sf::Vector2f _min_velocity;
};
struct player_data {
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
sf::Vector2<float> pos { TILESIZE, TILESIZE };
float max_velocity_y { 15.0f };
float border_size { -1.0f };
float dash_distance { 20.0f };
sf::Vector2f velocity { 3.0f, 0 };
private:
bool get_vertical_bottom_collision_by_offset(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
sf::Vector2f _min_velocity;
};
#endif
+1 -9
View File
@@ -7,23 +7,15 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <array>
struct Level {
std::array<std::array<char, MAX_COLS>, MAX_ROWS> data;
std::string name;
};
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 = {};
std::array<std::array<Object*, MAX_COLS>, MAX_ROWS> wall_list = {};
private:
int current_level = 1;
};
extern std::vector<Level> levels;
#endif