2020-07-03 18:31:17 +00:00
|
|
|
//
|
|
|
|
// Created by SeanOMik on 7/2/2020.
|
|
|
|
// Github: https://github.com/SeanOMik
|
|
|
|
// Email: seanomik@gmail.com
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SIMPLEENGINE_MOVEMENT_COMPONENT_H
|
|
|
|
#define SIMPLEENGINE_MOVEMENT_COMPONENT_H
|
|
|
|
|
|
|
|
#include "../../component.h"
|
|
|
|
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
|
|
|
namespace simpleengine {
|
|
|
|
class Entity;
|
2021-03-22 00:55:29 +00:00
|
|
|
class Game;
|
2020-07-03 18:31:17 +00:00
|
|
|
|
|
|
|
class MovementComponent : public Component {
|
|
|
|
public:
|
2021-03-22 00:55:29 +00:00
|
|
|
MovementComponent(Entity& owning_entity, Game& game, float max_velocity, float acceleration = 7, float deceleration = 2.5);
|
2020-07-03 18:31:17 +00:00
|
|
|
|
2021-03-22 00:55:29 +00:00
|
|
|
void OnKeyPress(sf::Event::KeyEvent event);
|
|
|
|
void OnKeyRelease(sf::Event::KeyEvent event);
|
|
|
|
|
2020-07-06 05:44:06 +00:00
|
|
|
void Move(const float& delta_time, const float& dir_x, const float& dir_y);
|
2021-03-22 00:55:29 +00:00
|
|
|
|
2020-07-06 05:44:06 +00:00
|
|
|
void Update(const float& delta_time) override;
|
|
|
|
|
|
|
|
const sf::Vector2f& GetVelocity() const;
|
|
|
|
const sf::Vector2f& GetLastDirection() const;
|
2020-07-03 18:31:17 +00:00
|
|
|
private:
|
2021-03-22 00:55:29 +00:00
|
|
|
sf::Vector2f direction;
|
2020-07-04 18:15:56 +00:00
|
|
|
float max_velocity;
|
|
|
|
sf::Vector2f velocity;
|
2020-07-06 05:44:06 +00:00
|
|
|
sf::Vector2f last_direction;
|
2020-07-04 18:15:56 +00:00
|
|
|
float acceleration;
|
|
|
|
float deceleration;
|
2020-07-03 18:31:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //SIMPLEENGINE_MOVEMENT_COMPONENT_H
|