moved some things to player

This commit is contained in:
DarthMooMancer
2025-10-15 21:40:33 -04:00
parent 399ccc8617
commit 69b05d6bc5
3 changed files with 25 additions and 24 deletions
+1
View File
@@ -14,6 +14,7 @@ public:
float m_jump_strength;
float m_thickness;
bool m_jumping;
void handle_movment();
sf::Vector2<float> get_velocity();
bool get_jumping();
+4 -24
View File
@@ -5,15 +5,6 @@
#include "globals.hpp"
#include "player.hpp"
struct Player_Attributes {
sf::Vector2<float> m_size;
const float m_gravity;
const float jump_strength;
float m_thickness;
float m_velocityY;
bool jumping;
};
int main() {
float floor_height = 2.0f;
bool jumping = false;
@@ -40,25 +31,14 @@ int main() {
if (event->is<sf::Event::Closed>())
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
window.close();
}
player.handle_movment();
/* TODO
* Move these to a player movement handler
*
* */
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
player.rect.move({2.5f, 0});
} if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
player.rect.move({-2.5f, 0});
} if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
player.rect.move({0, -2.5});
} if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) {
player.rect.move({0, 2.5});
} if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !player.m_jumping) {
player.m_jumping = true;
player.m_velocity.y = -player.m_jump_strength; // push up
}
/* TODO
* Move these to a player update loop to move
+20
View File
@@ -1,5 +1,7 @@
#include "player.hpp"
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp>
Player::Player(sf::Vector2<float> size, sf::Vector2<float> starting_position, float acceleration, float initial_acceleration, float thickness, float velocity_x) {
rect.setSize(size);
@@ -9,3 +11,21 @@ Player::Player(sf::Vector2<float> size, sf::Vector2<float> starting_position, fl
m_thickness = thickness;
m_velocity.x = velocity_x;
}
void Player::handle_movment() {
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
rect.move({2.5f, 0});
} if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
rect.move({-2.5f, 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
}
}