wip
This commit is contained in:
@@ -31,12 +31,15 @@ public:
|
|||||||
float m_jump_strength;
|
float m_jump_strength;
|
||||||
bool m_jumping;
|
bool m_jumping;
|
||||||
void handle_movment();
|
void handle_movment();
|
||||||
|
void handle_gravity();
|
||||||
bool get_jumping();
|
bool get_jumping();
|
||||||
void horizontal_no_out_of_bounds(Entity &base);
|
void horizontal_no_out_of_bounds(Entity &base);
|
||||||
void vertical_no_out_of_bounds(Entity &base);
|
void vertical_no_out_of_bounds(Entity &base);
|
||||||
bool get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
bool get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||||
bool get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
bool get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||||
bool get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
bool get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||||
|
private:
|
||||||
|
sf::Vector2f _min_velocity;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ CollisionDir Entity::find_intersection(Entity &entity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player::Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, float gravity, float max_acceleration, sf::Color inside_color, sf::Color border_color) : Entity(size, pos, velocity, border_thickness, inside_color, border_color) {
|
Player::Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, float gravity, float max_acceleration, sf::Color inside_color, sf::Color border_color) : Entity(size, pos, velocity, border_thickness, inside_color, border_color) {
|
||||||
|
_min_velocity = velocity;
|
||||||
m_acceleration = gravity;
|
m_acceleration = gravity;
|
||||||
m_jump_strength = max_acceleration;
|
m_jump_strength = max_acceleration;
|
||||||
}
|
}
|
||||||
@@ -76,6 +77,15 @@ void Player::handle_movment() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::handle_gravity() {
|
||||||
|
if(get_velocity().x > _min_velocity.x) {
|
||||||
|
set_velocity_x(get_velocity().x - m_acceleration);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_velocity_y(get_velocity().y + m_acceleration);
|
||||||
|
rect.move({0, get_velocity().y});
|
||||||
|
}
|
||||||
|
|
||||||
void Player::horizontal_no_out_of_bounds(Entity &base) {
|
void Player::horizontal_no_out_of_bounds(Entity &base) {
|
||||||
float right_border = WIDTH - rect.getSize().x;
|
float right_border = WIDTH - rect.getSize().x;
|
||||||
if(rect.getPosition().x > right_border) {
|
if(rect.getPosition().x > right_border) {
|
||||||
|
|||||||
+1
-7
@@ -100,13 +100,7 @@ int main() {
|
|||||||
player.get_horizontal_collision(wall_list);
|
player.get_horizontal_collision(wall_list);
|
||||||
player.horizontal_no_out_of_bounds(line);
|
player.horizontal_no_out_of_bounds(line);
|
||||||
|
|
||||||
if(player.get_velocity().x > 4) {
|
player.handle_gravity();
|
||||||
player.set_velocity_x(player.get_velocity().x - player.m_acceleration);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Vertical movement and collisions
|
|
||||||
player.set_velocity_y(player.get_velocity().y + player.m_acceleration);
|
|
||||||
player.rect.move({0, player.get_velocity().y});
|
|
||||||
|
|
||||||
if(!player.get_vertical_bottom_collision(wall_list)) {
|
if(!player.get_vertical_bottom_collision(wall_list)) {
|
||||||
player.get_vertical_top_collision(wall_list);
|
player.get_vertical_top_collision(wall_list);
|
||||||
|
|||||||
Reference in New Issue
Block a user