temporarily be able to move player around
This commit is contained in:
parent
ee38a6f655
commit
7b076cdc13
@ -3,6 +3,7 @@
|
|||||||
#include <SFML/OpenGL.hpp>
|
#include <SFML/OpenGL.hpp>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
Client::Client(bool fullscreen)
|
Client::Client(bool fullscreen)
|
||||||
{
|
{
|
||||||
@ -23,6 +24,7 @@ Client::Client(bool fullscreen)
|
|||||||
|
|
||||||
void Client::run()
|
void Client::run()
|
||||||
{
|
{
|
||||||
|
m_clock.restart();
|
||||||
while (m_window->isOpen())
|
while (m_window->isOpen())
|
||||||
{
|
{
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
@ -51,6 +53,7 @@ void Client::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
@ -88,6 +91,39 @@ void Client::resize_window(int width, int height)
|
|||||||
glLoadIdentity();
|
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()
|
void Client::draw_players()
|
||||||
{
|
{
|
||||||
static const float vertices[][3] = {
|
static const float vertices[][3] = {
|
||||||
|
@ -15,6 +15,7 @@ class Client
|
|||||||
protected:
|
protected:
|
||||||
void initgl();
|
void initgl();
|
||||||
void resize_window(int width, int height);
|
void resize_window(int width, int height);
|
||||||
|
void update();
|
||||||
void draw_players();
|
void draw_players();
|
||||||
void draw_map();
|
void draw_map();
|
||||||
refptr<sf::Window> m_window;
|
refptr<sf::Window> m_window;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user