bettola/srv/game/player.h

50 lines
1.4 KiB
C++

#pragma once
#include <netinet/in.h>
#include "bettola/network/tcpsocket.h"
#include "math/vec3.h"
class Player {
public:
struct InputState {
bool up;
bool down;
bool left;
bool right;
};
Player(BettolaLib::Network::TCPSocket* socket);
void update(double dt);
void set_velocity_direction(const InputState& input, const BettolaMath::Vec3& cam_front);
void set_position(float x, float y) { _x = x; _y = y; }
void set_yaw(float yaw) { _yaw = yaw; }
void set_udp_addr(const sockaddr_in& addr) { _udp_addr = addr; _has_udp_addr = true; }
unsigned int get_id(void) const { return _id; }
float get_x(void) const { return _x; }
float get_y(void) const { return _y; }
float get_yaw(void) const { return _yaw; }
BettolaLib::Network::TCPSocket& get_socket(void) const { return *_socket; }
const sockaddr_in& get_udp_addr(void) const { return _udp_addr; }
bool has_udp_addr(void) const { return _has_udp_addr; }
void set_last_processed_sequence(unsigned int sequence) { _last_processed_sequence = sequence; }
unsigned int get_last_processed_sequence(void) const { return _last_processed_sequence; }
private:
static unsigned int _next_player_id;
unsigned int _id;
float _x;
float _y;
float _yaw;
BettolaLib::Network::TCPSocket* _socket;
sockaddr_in _udp_addr;
bool _has_udp_addr;
unsigned int _last_processed_sequence;
float _vx, _vy;
float _speed;
};