diff --git a/include/player.hpp b/include/player.hpp index ec2ae7e..73e348a 100644 --- a/include/player.hpp +++ b/include/player.hpp @@ -12,7 +12,6 @@ public: sf::Vector2 m_velocity; float m_acceleration; float m_jump_strength; - float m_thickness; bool m_jumping; void handle_movment(); sf::Vector2 get_velocity(); diff --git a/src/main.cpp b/src/main.cpp index 1038330..cce6ee9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,28 +1,22 @@ #include #include #include +#include #include #include "globals.hpp" #include "player.hpp" int main() { float floor_height = 2.0f; - bool jumping = false; sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default); - Player player { { 16.0f, 16.0f}, { 40, 40}, 1.0f, 20.0f, 2.0f, 2.5 }; window.setFramerateLimit(60); - // sf::RectangleShape player({ player_size, player_size }); - sf::RectangleShape line({ WIDTH, floor_height }); - - /* TODO - * Move these functions to the player - */ + Player player { { 16.0f, 16.0f}, { 40, 40}, 1.0f, 20.0f, 2.0f, 2.5 }; player.rect.setFillColor(sf::Color::Black); - player.rect.setOutlineThickness(2); // 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 player.rect.setOutlineColor(sf::Color::White); - player.rect.setPosition({40, 40}); + sf::RectangleShape line({ WIDTH, floor_height }); + line.setPosition({ 0, HEIGHT - 50}); while (window.isOpen()) { @@ -35,27 +29,17 @@ int main() { window.close(); } player.handle_movment(); - /* TODO - * Move these to a player movement handler - * - * */ - - /* TODO - * Move these to a player update loop to move - * - * */ player.m_velocity.y += player.m_acceleration; // always apply gravity player.rect.move({0, player.m_velocity.y}); - // float groundY = line.getPosition().y - floor_height - player.rect.m_size.x; - float groundY = line.getPosition().y - floor_height - 16; + float groundY = line.getPosition().y - floor_height - player.rect.getSize().x; if (player.rect.getPosition().y >= groundY) { player.rect.setPosition({player.rect.getPosition().x, groundY}); player.m_velocity.y = 0; player.m_jumping = false; } - window.draw(line); window.draw(player.rect); + window.draw(line); window.display(); } } diff --git a/src/player.cpp b/src/player.cpp index ae632aa..a593f3d 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -6,17 +6,17 @@ Player::Player(sf::Vector2 size, sf::Vector2 starting_position, float acceleration, float initial_acceleration, float thickness, float velocity_x) { 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 m_acceleration = acceleration; m_jump_strength = initial_acceleration; - 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}); + rect.move({m_velocity.x, 0}); } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { - rect.move({-2.5f, 0}); + rect.move({m_velocity.x, 0}); } // if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) { // rect.move({0, -2.5});