From 7b076cdc135e7e9b9079bdc2f234c1fa7804cfd9 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 29 Aug 2012 00:33:59 -0400 Subject: [PATCH] temporarily be able to move player around --- src/client/Client.cc | 36 ++++++++++++++++++++++++++++++++++++ src/client/Client.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/client/Client.cc b/src/client/Client.cc index 6403bdf..31170bb 100755 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -3,6 +3,7 @@ #include #include #include "Client.h" +#include Client::Client(bool fullscreen) { @@ -23,6 +24,7 @@ Client::Client(bool fullscreen) void Client::run() { + m_clock.restart(); while (m_window->isOpen()) { sf::Event event; @@ -51,6 +53,7 @@ void Client::run() } } + update(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); @@ -88,6 +91,39 @@ void Client::resize_window(int width, int height) glLoadIdentity(); } +void Client::update() +{ + static double last_time = 0.0; + const double move_speed = 300.0; + const double current_time = m_clock.getElapsedTime().asSeconds(); + const double elapsed_time = current_time - last_time; + if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) + { + double direction = m_player->direction + M_PI_2; + m_player->x += cos(direction) * move_speed * elapsed_time; + m_player->y += sin(direction) * move_speed * elapsed_time; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) + { + double direction = m_player->direction - M_PI_2; + m_player->x += cos(direction) * move_speed * elapsed_time; + m_player->y += sin(direction) * move_speed * elapsed_time; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) + { + double direction = m_player->direction; + m_player->x += cos(direction) * move_speed * elapsed_time; + m_player->y += sin(direction) * move_speed * elapsed_time; + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) + { + double direction = m_player->direction + M_PI; + m_player->x += cos(direction) * move_speed * elapsed_time; + m_player->y += sin(direction) * move_speed * elapsed_time; + } + last_time = current_time; +} + void Client::draw_players() { static const float vertices[][3] = { diff --git a/src/client/Client.h b/src/client/Client.h index 1ee283a..8d38c64 100755 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -15,6 +15,7 @@ class Client protected: void initgl(); void resize_window(int width, int height); + void update(); void draw_players(); void draw_map(); refptr m_window;