player bounding box almost there
This commit is contained in:
+14
-8
@@ -10,8 +10,7 @@
|
||||
#define DEFAULT 1
|
||||
#define PLATFORM1 2
|
||||
#define CHECKERED 3
|
||||
|
||||
#include "globals.hpp"
|
||||
#define BASE 4
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
@@ -19,7 +18,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct ObjectData {
|
||||
#include "globals.hpp"
|
||||
|
||||
struct ObjectData
|
||||
{
|
||||
sf::Vector2<float> size { TILESIZE, TILESIZE };
|
||||
sf::Vector2<float> pos { TILESIZE, TILESIZE };
|
||||
sf::Color interior_color { sf::Color::Black };
|
||||
@@ -27,20 +29,24 @@ struct ObjectData {
|
||||
float edge { -2.0f };
|
||||
};
|
||||
|
||||
struct EntityData : ObjectData {
|
||||
struct EntityData : ObjectData
|
||||
{
|
||||
sf::Vector2<float> velocity { 0, 0 };
|
||||
};
|
||||
|
||||
struct PlayerData : EntityData {
|
||||
float dash_length { 0.0f };
|
||||
struct PlayerData : EntityData
|
||||
{
|
||||
float max_dash_acceleration { 0.0f };
|
||||
float max_vertical_acceleration { 0.0f };
|
||||
};
|
||||
|
||||
struct LevelData {
|
||||
struct LevelData
|
||||
{
|
||||
std::array<std::array<char, MAX_COLS>, MAX_ROWS> data {};
|
||||
};
|
||||
|
||||
struct TimerData {
|
||||
struct TimerData
|
||||
{
|
||||
std::string name { "NULL" };
|
||||
float max_time { 1.f };
|
||||
};
|
||||
|
||||
+68
-43
@@ -1,63 +1,88 @@
|
||||
#ifndef PLAYER_HPP
|
||||
#define PLAYER_HPP
|
||||
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include "data.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#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 };
|
||||
enum class CollisionDir
|
||||
{
|
||||
None,
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom
|
||||
};
|
||||
class Entity;
|
||||
class Object;
|
||||
class Player;
|
||||
|
||||
class Object {
|
||||
public:
|
||||
Object(ObjectData data);
|
||||
CollisionDir find_intersection(Object& entity);
|
||||
sf::RectangleShape rect;
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
Object(ObjectData data);
|
||||
CollisionDir find_intersection(Object& entity);
|
||||
float find_horizontal_difference_from_interesection(Object& entity);
|
||||
sf::RectangleShape rect;
|
||||
};
|
||||
|
||||
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();
|
||||
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();
|
||||
|
||||
protected:
|
||||
sf::Vector2f _velocity;
|
||||
protected:
|
||||
sf::Vector2f _velocity;
|
||||
};
|
||||
|
||||
class Player : public Entity {
|
||||
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 };
|
||||
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();
|
||||
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>);
|
||||
class Player : public Entity
|
||||
{
|
||||
public:
|
||||
Player(PlayerData data, float gravity)
|
||||
: Entity(data),
|
||||
max_dash_acceleration(data.max_vertical_acceleration),
|
||||
max_vertical_acceleration(data.max_vertical_acceleration),
|
||||
gravity(gravity), _min_velocity(data.velocity) {};
|
||||
float max_vertical_acceleration;
|
||||
float max_dash_acceleration;
|
||||
float gravity;
|
||||
bool m_jumping { false };
|
||||
std::unique_ptr<Object> bounding_box;
|
||||
void initialize_bounding_box();
|
||||
void update_bounding_box();
|
||||
int check_bounding_box(
|
||||
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
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<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
bool get_vertical_top_collision(
|
||||
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
bool get_vertical_bottom_collision(
|
||||
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>& tilemap);
|
||||
|
||||
private:
|
||||
bool get_vertical_bottom_collision_by_offset(std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS>);
|
||||
sf::Vector2f _min_velocity { 0, 0 };
|
||||
private:
|
||||
sf::Vector2f _min_velocity { 0, 0 };
|
||||
std::string direction;
|
||||
};
|
||||
|
||||
float
|
||||
total_distance(int k);
|
||||
|
||||
float
|
||||
distance_to_acceleration(int target);
|
||||
|
||||
#endif
|
||||
|
||||
+11
-8
@@ -1,24 +1,27 @@
|
||||
#ifndef MAPS_HPP
|
||||
#define 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>
|
||||
|
||||
class Manager {
|
||||
public:
|
||||
class Manager
|
||||
{
|
||||
public:
|
||||
void clear();
|
||||
void load(const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data);
|
||||
void load(LevelData level);
|
||||
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 = {};
|
||||
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS> tilemap = {};
|
||||
|
||||
private:
|
||||
private:
|
||||
int _active = 1;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include "data.hpp"
|
||||
|
||||
@@ -24,7 +25,7 @@ private:
|
||||
struct Scheduler {
|
||||
Scheduler();
|
||||
std::vector<Timer> timers;
|
||||
void update(bool& running);
|
||||
void update(std::atomic<bool>& running);
|
||||
int pull(std::string name);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user