moved some things to player
This commit is contained in:
@@ -14,6 +14,7 @@ public:
|
|||||||
float m_jump_strength;
|
float m_jump_strength;
|
||||||
float m_thickness;
|
float m_thickness;
|
||||||
bool m_jumping;
|
bool m_jumping;
|
||||||
|
void handle_movment();
|
||||||
sf::Vector2<float> get_velocity();
|
sf::Vector2<float> get_velocity();
|
||||||
bool get_jumping();
|
bool get_jumping();
|
||||||
|
|
||||||
|
|||||||
+4
-24
@@ -5,15 +5,6 @@
|
|||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include "player.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() {
|
int main() {
|
||||||
float floor_height = 2.0f;
|
float floor_height = 2.0f;
|
||||||
bool jumping = false;
|
bool jumping = false;
|
||||||
@@ -40,25 +31,14 @@ int main() {
|
|||||||
if (event->is<sf::Event::Closed>())
|
if (event->is<sf::Event::Closed>())
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
player.handle_movment();
|
||||||
/* TODO
|
/* TODO
|
||||||
* Move these to a player movement handler
|
* 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
|
/* TODO
|
||||||
* Move these to a player update loop to move
|
* Move these to a player update loop to move
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
|
|
||||||
#include <SFML/System/Vector2.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) {
|
Player::Player(sf::Vector2<float> size, sf::Vector2<float> starting_position, float acceleration, float initial_acceleration, float thickness, float velocity_x) {
|
||||||
rect.setSize(size);
|
rect.setSize(size);
|
||||||
@@ -9,3 +11,21 @@ Player::Player(sf::Vector2<float> size, sf::Vector2<float> starting_position, fl
|
|||||||
m_thickness = thickness;
|
m_thickness = thickness;
|
||||||
m_velocity.x = velocity_x;
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user