70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
#ifndef PLAYER_HPP
|
|
#define PLAYER_HPP
|
|
|
|
#include <SFML/Graphics/CircleShape.hpp>
|
|
#include <SFML/Graphics/Color.hpp>
|
|
#include <SFML/Graphics/Rect.hpp>
|
|
#include <SFML/Graphics/RectangleShape.hpp>
|
|
#include <SFML/System/Vector2.hpp>
|
|
#include <memory>
|
|
#include <optional>
|
|
|
|
#include "data.hpp"
|
|
#include "globals.hpp"
|
|
#include "scheduler.hpp"
|
|
|
|
struct Object;
|
|
class Entity;
|
|
class Player;
|
|
|
|
struct Object
|
|
{
|
|
Object(ObjectData data)
|
|
{
|
|
rect.setSize(data.size);
|
|
rect.setPosition(data.pos);
|
|
rect.setOutlineThickness(data.edge);
|
|
rect.setFillColor(data.interior_color);
|
|
rect.setOutlineColor(data.exterior_color);
|
|
};
|
|
|
|
sf::RectangleShape rect;
|
|
};
|
|
|
|
class Entity : public Object
|
|
{
|
|
public:
|
|
Entity(EntityData data)
|
|
: Object(data.object), _velocity(data.velocity) {};
|
|
void set_velocity(sf::Vector2f velocity);
|
|
void set_velocity_x(int velocity);
|
|
void set_velocity_y(int velocity);
|
|
const sf::Vector2<float> get_velocity();
|
|
|
|
protected:
|
|
sf::Vector2f _velocity;
|
|
};
|
|
|
|
class Player : public Entity
|
|
{
|
|
public:
|
|
Player(PlayerData data)
|
|
: Entity(data.entity),
|
|
max_dash_acceleration(data.max_dash_acceleration),
|
|
max_vertical_acceleration(data.max_vertical_acceleration) {};
|
|
|
|
float max_vertical_acceleration;
|
|
float max_dash_acceleration;
|
|
bool m_jumping { false };
|
|
void handle_movment(std::optional<Timer*> dash);
|
|
void handle_gravity();
|
|
void handle_collision(
|
|
std::array<std::array<std::unique_ptr<Object>, MAX_COLS>, MAX_ROWS>&
|
|
tilemap);
|
|
|
|
private:
|
|
std::string direction { "left" };
|
|
};
|
|
|
|
#endif
|