This commit is contained in:
aozhiwei 2019-11-22 13:48:34 +08:00
parent 984d115404
commit f2a768d95d
6 changed files with 57 additions and 3 deletions

View File

@ -53,6 +53,7 @@ void Human::FillMFObjectPart(cs::MFObjectPart* part_data)
part_data->set_object_type(ET_Player);
cs::MFPlayerPart* p = part_data->mutable_union_obj_1();
p->set_obj_uniid(entity_uniid);
FillMFSnake(p->mutable_snake());
}
void Human::FillMFObjectFull(cs::MFObjectFull* full_data)
@ -60,6 +61,7 @@ void Human::FillMFObjectFull(cs::MFObjectFull* full_data)
full_data->set_object_type(ET_Player);
cs::MFPlayerFull* p = full_data->mutable_union_obj_1();
p->set_obj_uniid(entity_uniid);
FillMFSnake(p->mutable_snake());
p->set_dead(dead);
p->set_disconnected(disconnected);
@ -823,5 +825,49 @@ void Human::Revive()
void Human::CreateSnake()
{
a8::Vec2 init_pos;
room->GenSnakeBornPos(init_pos);
head_ = new SnakeBodyNode();
head_->node_id = ++curr_node_id_;
head_->speed = meta->p->speed_normal();
head_->radius = meta->p->init_radius();
head_->pos = init_pos;
//head_->dir = meta->p->init_radius();
a8::Vec2 node_pos = init_pos;
SnakeBodyNode* pre_node = head_;
for (int i = 0; i < meta->p->init_body_size(); ++i) {
node_pos.y -= (1 - meta->p->body_interval()) * meta->p->init_radius();
SnakeBodyNode* node = new SnakeBodyNode();
node->node_id = ++curr_node_id_;
node->pre_node = pre_node;
node->speed = meta->p->speed_normal();
node->radius = meta->p->init_radius();
node->pos = node_pos;
body_list.push_back(node);
pre_node = node;
}
tail_ = pre_node;
}
void Human::FillMFSnake(cs::MFSnake* snake_pb)
{
{
cs::MFSnakeHead* head_pb = snake_pb->mutable_snake_head();
TypeConvert::ToPb(head_->pos, head_pb->mutable_pos());
TypeConvert::ToPb(head_->dir, head_pb->mutable_dir());
head_pb->set_radius(head_->radius);
head_pb->set_speed(head_->speed);
}
{
for (auto& body : body_list) {
TypeConvert::ToPb(
body->pos,
snake_pb->add_snake_body()->mutable_pos()
);
}
}
}

View File

@ -115,12 +115,13 @@ private:
void OnDie();
void Revive();
void CreateSnake();
void FillMFSnake(cs::MFSnake* snake_pb);
protected:
int node_id_ = 1;
int curr_node_id_ = 1;
SnakeBodyNode* head_ = nullptr;
SnakeBodyNode* tail_ = nullptr;
std::list<SnakeBodyNode> body_list;
std::list<SnakeBodyNode*> body_list;
long long last_sync_teamdata_frameno_ = 0;
bool leave_ = false;
long long leave_frameno_ = 0;

View File

@ -757,3 +757,8 @@ void Room::NotifyWxVoip()
},
&xtimer_attacher.timer_list_);
}
bool Room::GenSnakeBornPos(a8::Vec2& pos)
{
return true;
}

View File

@ -78,6 +78,7 @@ public:
float& new_x, float& new_y);
void FillSMUiUpdate(cs::SMUiUpdate& msg);
void NotifyUiUpdate();
bool GenSnakeBornPos(a8::Vec2& pos);
private:
int AllocUniid();

View File

@ -61,6 +61,7 @@ struct SnakeBodyNode
{
int node_id = 0;
float speed = 0.0f;
float radius = 0.0f;
a8::Vec2 pos;
a8::Vec2 dir;
a8::Vec2 last_move;

View File

@ -16,7 +16,7 @@ message Snake
{
optional int32 snake_id = 100;
optional float init_radius = 1;
optional float interval = 2;
optional float body_interval = 2;
optional float speed_normal = 3;
optional float level_of_accelation = 4;
optional float spawn_interval = 5;