wip
This commit is contained in:
@@ -12,7 +12,6 @@ public:
|
|||||||
sf::Vector2<float> m_velocity;
|
sf::Vector2<float> m_velocity;
|
||||||
float m_acceleration;
|
float m_acceleration;
|
||||||
float m_jump_strength;
|
float m_jump_strength;
|
||||||
float m_thickness;
|
|
||||||
bool m_jumping;
|
bool m_jumping;
|
||||||
void handle_movment();
|
void handle_movment();
|
||||||
sf::Vector2<float> get_velocity();
|
sf::Vector2<float> get_velocity();
|
||||||
|
|||||||
+6
-22
@@ -1,27 +1,21 @@
|
|||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <SFML/Graphics/RectangleShape.hpp>
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
|
#include <SFML/System/Angle.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
float floor_height = 2.0f;
|
float floor_height = 2.0f;
|
||||||
bool jumping = false;
|
|
||||||
sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default);
|
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);
|
window.setFramerateLimit(60);
|
||||||
|
|
||||||
// sf::RectangleShape player({ player_size, player_size });
|
Player player { { 16.0f, 16.0f}, { 40, 40}, 1.0f, 20.0f, 2.0f, 2.5 };
|
||||||
sf::RectangleShape line({ WIDTH, floor_height });
|
|
||||||
|
|
||||||
/* TODO
|
|
||||||
* Move these functions to the player
|
|
||||||
*/
|
|
||||||
player.rect.setFillColor(sf::Color::Black);
|
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.setOutlineColor(sf::Color::White);
|
||||||
player.rect.setPosition({40, 40});
|
|
||||||
|
sf::RectangleShape line({ WIDTH, floor_height });
|
||||||
|
|
||||||
line.setPosition({ 0, HEIGHT - 50});
|
line.setPosition({ 0, HEIGHT - 50});
|
||||||
|
|
||||||
@@ -35,27 +29,17 @@ int main() {
|
|||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
player.handle_movment();
|
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.m_velocity.y += player.m_acceleration; // always apply gravity
|
||||||
player.rect.move({0, player.m_velocity.y});
|
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 - player.rect.getSize().x;
|
||||||
float groundY = line.getPosition().y - floor_height - 16;
|
|
||||||
if (player.rect.getPosition().y >= groundY) {
|
if (player.rect.getPosition().y >= groundY) {
|
||||||
player.rect.setPosition({player.rect.getPosition().x, groundY});
|
player.rect.setPosition({player.rect.getPosition().x, groundY});
|
||||||
player.m_velocity.y = 0;
|
player.m_velocity.y = 0;
|
||||||
player.m_jumping = false;
|
player.m_jumping = false;
|
||||||
}
|
}
|
||||||
window.draw(line);
|
|
||||||
window.draw(player.rect);
|
window.draw(player.rect);
|
||||||
|
window.draw(line);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -6,17 +6,17 @@
|
|||||||
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);
|
||||||
rect.setPosition(starting_position);
|
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_acceleration = acceleration;
|
||||||
m_jump_strength = initial_acceleration;
|
m_jump_strength = initial_acceleration;
|
||||||
m_thickness = thickness;
|
|
||||||
m_velocity.x = velocity_x;
|
m_velocity.x = velocity_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::handle_movment() {
|
void Player::handle_movment() {
|
||||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
|
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)) {
|
} 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)) {
|
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
|
||||||
// rect.move({0, -2.5});
|
// rect.move({0, -2.5});
|
||||||
|
|||||||
Reference in New Issue
Block a user