#include #include #include "player.h" #include "network/tcpsocket.h" unsigned int Player::_next_player_id = 0; Player::Player(BettolaLib::Network::TCPSocket* socket) : _socket(socket), _has_udp_addr(false) { /* Try and set a player id to 0 now you audacious pr.ck! */ if(_next_player_id == 0) { _next_player_id = 1; } _id = _next_player_id++; _x = 0.0f; _y = 0.0f; _vx = 0.0f; _vy = 0.0f; _speed = 200.0f; /* Must match client! */ _last_processed_sequence = 0; memset(&_udp_addr, 0, sizeof(_udp_addr)); } void Player::update(double dt) { _x += _vx * dt; _y += _vy * dt; } void Player::set_velocity_direction(float dir_x, float dir_y) { if(dir_x == 0.0f && dir_y == 0.0f) { _vx = _vy = 0.0f; } else { float mag = sqrt(dir_x * dir_x + dir_y * dir_y); _vx = (dir_x / mag) * _speed; _vy = (dir_y / mag) * _speed; } }