Non-grid UDP movement
This commit is contained in:
@ -7,38 +7,60 @@
|
||||
class GameEntity
|
||||
{
|
||||
public:
|
||||
GameEntity(std::string,std::string,int,int);
|
||||
GameEntity(std::string,std::string,float,float);
|
||||
std::string get_id(void);
|
||||
std::string get_type(void);
|
||||
int get_x(void);
|
||||
int get_y(void);
|
||||
std::string set_x(int);
|
||||
std::string set_y(int);
|
||||
float get_x(void);
|
||||
float get_y(void);
|
||||
std::string set_x(float);
|
||||
std::string set_y(float);
|
||||
void set_velocity(float, float);
|
||||
std::string get_dump(void);
|
||||
bool movement_tick(void);
|
||||
private:
|
||||
int pos_x;
|
||||
int pos_y;
|
||||
float pos_x;
|
||||
float pos_y;
|
||||
float velocity_x;
|
||||
float velocity_y;
|
||||
std::string id;
|
||||
std::string type;
|
||||
|
||||
};
|
||||
|
||||
GameEntity::GameEntity(std::string entity_id, std::string entity_type, int x = 0, int y = 0)
|
||||
GameEntity::GameEntity(std::string entity_id, std::string entity_type, float x = 0, float y = 0)
|
||||
{
|
||||
id = entity_id;
|
||||
type = entity_type;
|
||||
velocity_x = 0;
|
||||
velocity_y = 0;
|
||||
this->set_x(x);
|
||||
this->set_y(y);
|
||||
std::cout << "Entity created with id: '" << id << "' at " << x << "," << y << std::endl;
|
||||
}
|
||||
|
||||
bool GameEntity::movement_tick()
|
||||
{
|
||||
if(velocity_x != 0 || velocity_y != 0)
|
||||
{
|
||||
set_x(pos_x + velocity_x);
|
||||
set_y(pos_y + velocity_y);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int GameEntity::get_x(void)
|
||||
void GameEntity::set_velocity(float x, float y)
|
||||
{
|
||||
velocity_x = x;
|
||||
velocity_y = y;
|
||||
}
|
||||
|
||||
float GameEntity::get_x(void)
|
||||
{
|
||||
return pos_x;
|
||||
}
|
||||
|
||||
int GameEntity::get_y(void)
|
||||
float GameEntity::get_y(void)
|
||||
{
|
||||
return pos_y;
|
||||
}
|
||||
@ -48,12 +70,12 @@ std::string GameEntity::get_dump(void)
|
||||
return std::to_string(pos_x) + "," + std::to_string(pos_y) + "," + type + ":" + id + '\n';
|
||||
}
|
||||
|
||||
std::string GameEntity::set_x(int x)
|
||||
std::string GameEntity::set_x(float x)
|
||||
{
|
||||
pos_x = x;
|
||||
return this -> get_dump();
|
||||
}
|
||||
std::string GameEntity::set_y(int y)
|
||||
std::string GameEntity::set_y(float y)
|
||||
{
|
||||
pos_y = y;
|
||||
return this -> get_dump();
|
||||
|
Reference in New Issue
Block a user