wip
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#include "elements.hpp"
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
|
||||
/* Entitiy
|
||||
* Parent class
|
||||
* Holds all 4 corners of rect
|
||||
* Bounding checks for if a rect1_top_left is between rect2_top_right - rect2_top_left
|
||||
*
|
||||
*
|
||||
* */
|
||||
|
||||
Player::Player(sf::Vector2<float> size, sf::Vector2<float> starting_position, float acceleration, float initial_acceleration, float thickness, float velocity_x, sf::Color inside_color, sf::Color border_color) {
|
||||
rect.setSize(size);
|
||||
rect.setPosition(starting_position);
|
||||
rect.setOutlineThickness(thickness); // Needs to be the same as floor height to be properly on the line; else it will just show up above the line or in the line
|
||||
rect.setFillColor(inside_color);
|
||||
rect.setOutlineColor(border_color);
|
||||
m_acceleration = acceleration;
|
||||
m_jump_strength = initial_acceleration;
|
||||
m_velocity.x = velocity_x;
|
||||
m_thickness = thickness;
|
||||
}
|
||||
|
||||
void Player::handle_movment() {
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
|
||||
rect.move({m_velocity.x, 0});
|
||||
} if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
||||
rect.move({-m_velocity.x, 0});
|
||||
}
|
||||
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
|
||||
// rect.move({0, -2.5});
|
||||
// } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) {
|
||||
// rect.move({0, 2.5});
|
||||
// }
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !m_jumping) {
|
||||
m_jumping = true;
|
||||
m_velocity.y = -m_jump_strength; // push up
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user