data drivin all code sucess

This commit is contained in:
Andrew Haynes Macbook
2026-01-16 15:03:16 -05:00
parent 7bbf50b581
commit 06d3f27b1e
13 changed files with 358 additions and 115 deletions
+19 -7
View File
@@ -1,6 +1,16 @@
#ifndef DATA_HPP
#define DATA_HPP
// Timers
#define DASH 1
#define LEVEL_SWITCH 2
// Maps
#define EMPTY 0
#define DEFAULT 1
#define PLATFORM1 2
#define CHECKERED 3
#include "globals.hpp"
#include <SFML/Graphics/Color.hpp>
@@ -22,21 +32,23 @@ struct EntityData : ObjectData {
};
struct PlayerData : EntityData {
ObjectData object;
EntityData entity;
float dash_length { 0.0f };
float max_vertical_acceleration { 0.0f };
};
class LevelData {
public:
std::array<std::array<char, MAX_COLS>, MAX_ROWS> data = {};
std::string name = "Null";
struct LevelData {
std::array<std::array<char, MAX_COLS>, MAX_ROWS> data {};
};
struct TimerData {
std::string name { "NULL" };
float max_time { 1.f };
};
extern std::vector<ObjectData> object_data;
extern std::vector<EntityData> entity_data;
extern std::vector<LevelData> level_data;
extern std::vector<TimerData> timer_data;
extern PlayerData player_data;
#endif // DATA_HPP
#endif
+6 -1
View File
@@ -8,6 +8,7 @@
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/CircleShape.hpp>
enum class CollisionDir { None, Left, Right, Top, Bottom };
class Entity;
@@ -41,6 +42,10 @@ class Player : public Entity {
float gravity;
bool m_jumping { false };
bool m_dash { false };
sf::RectangleShape bounding_box { { 0, 100 } };
void initialize_bounding_box();
void update_bounding_box();
void check_bounding_box(std::array<std::array<Object*, MAX_COLS>, MAX_ROWS> wall_list);
void handle_movment(Timer& dash);
void handle_gravity();
bool get_jumping();
@@ -52,7 +57,7 @@ class Player : public Entity {
private:
bool get_vertical_bottom_collision_by_offset(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
sf::Vector2f _min_velocity;
sf::Vector2f _min_velocity { 0, 0 };
};
#endif
-2
View File
@@ -8,6 +8,4 @@
#define FPS 60
#define GRAVITY 1
#define dash_cooldown .5
#define level_switch_cooldown_max 1
#endif
+11 -7
View File
@@ -8,14 +8,18 @@
#include <array>
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);
public:
void clear();
void load(const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data);
void draw(sf::RenderWindow& window);
void set_next();
void set_previous();
int get_active();
void set_active(int level);
std::array<std::array<Object*, MAX_COLS>, MAX_ROWS> wall_list = {};
private:
int current_level = 1;
private:
int _active = 1;
};
#endif
+7 -3
View File
@@ -4,10 +4,11 @@
#include <ctime>
#include <string>
#include <vector>
#include "data.hpp"
class Timer {
public:
Timer(std::string name, float max_time) : name(name), max_time(max_time) {};
Timer(TimerData data) : name(data.name), max_time(data.max_time) {};
bool below_or_zero();
float get_time();
std::string get_name();
@@ -21,8 +22,11 @@ private:
};
struct Scheduler {
Scheduler();
std::vector<Timer> timers;
void update(bool& running, std::vector<Timer>& times);
int pull(std::vector<Timer>& times, std::string name);
void update(bool& running);
int pull(std::string name);
};
#endif