#include #include #include "player.h" #include #include "config.h" Player::Player() { x = 0.5; y = 0.1; move_factor = 0.005; focus_factor = 0.5; texture = new TextureSTBI("textures/player.png"); } void Player::draw() { glPointSize(32.0); glColor4f(1, 1, 1, 1); glEnable(GL_TEXTURE_2D); texture->bind(); glBegin(GL_POINTS); glVertex2f(x, y); glEnd(); glDisable(GL_TEXTURE_2D); } void Player::update() { sf::Input input; float factor = move_factor * (input.IsKeyDown(sf::Key::LShift) ? focus_factor : 1); float x_speed = factor * input.IsKeyDown(sf::Key::Right) - factor * input.IsKeyDown(sf::Key::Left); float y_speed = factor * input.IsKeyDown(sf::Key::Up) - factor * input.IsKeyDown(sf::Key::Down); if(x_speed && y_speed) { x_speed /= sqrtf(2); y_speed /= sqrtf(2); } x = fmaxf(fminf(x + x_speed, 1.0 - 0.018), 0.018); y = fmaxf(fminf(y + y_speed, Config::viewport_aspect - 0.018), 0.018); }