1
This commit is contained in:
parent
f1943cc35b
commit
b4004df698
@ -151,36 +151,39 @@ void Human::FindPath()
|
||||
float dot = Vector2D::UP.Dot(move_dir);
|
||||
if (std::abs(dot) <= 0.001f) { //相互垂直
|
||||
//向上
|
||||
pos = pos + Vector2D::UP;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::UP;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
//向下
|
||||
pos = old_pos;
|
||||
pos = pos + Vector2D::DOWN;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::DOWN;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot > 0.001f) { //基本相同
|
||||
//向右
|
||||
pos = pos + Vector2D::RIGHT;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::RIGHT;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
//向上
|
||||
pos = old_pos;
|
||||
pos = pos + Vector2D::UP;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::UP;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot < 0.001f) { //基本相反
|
||||
//向右
|
||||
pos = pos + Vector2D::RIGHT;
|
||||
pos = old_pos + Vector2D::RIGHT;
|
||||
if (IsCollision()) {
|
||||
//向下
|
||||
pos = old_pos;
|
||||
pos = pos + Vector2D::DOWN;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::DOWN;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,34 +191,37 @@ void Human::FindPath()
|
||||
float dot = Vector2D::DOWN.Dot(move_dir);
|
||||
if (std::abs(dot) <= 0.001f) { //相互垂直
|
||||
//向下
|
||||
pos = pos + Vector2D::DOWN;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::DOWN;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
//向上
|
||||
pos = old_pos;
|
||||
pos = pos + Vector2D::UP;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::UP;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot > 0.001f) { //基本相同
|
||||
//向左
|
||||
pos = pos + Vector2D::LEFT;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::LEFT;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
//向下
|
||||
pos = old_pos;
|
||||
pos = pos + Vector2D::DOWN;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::DOWN;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot < 0.001f) { //基本相反
|
||||
//向左
|
||||
pos = pos + Vector2D::LEFT;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::LEFT;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
//向上
|
||||
pos = old_pos;
|
||||
pos = pos + Vector2D::UP;
|
||||
if (IsCollision()) {
|
||||
pos = old_pos + Vector2D::UP;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#include "playermgr.h"
|
||||
#include "player.h"
|
||||
#include "cs_proto.pb.h"
|
||||
@ -147,11 +149,21 @@ void Player::Shot()
|
||||
|
||||
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
|
||||
{
|
||||
bool has_move_dir = msg.has_move_dir();
|
||||
moving = false;
|
||||
if (msg.has_move_dir()) {
|
||||
if (std::abs(msg.move_dir().x()) > FLT_EPSILON ||
|
||||
std::abs(msg.move_dir().y()) > FLT_EPSILON
|
||||
) {
|
||||
move_dir.FromPB(&msg.move_dir());
|
||||
move_dir.Normalize();
|
||||
moving = true;
|
||||
}
|
||||
}
|
||||
assert(!isnan(move_dir.x) && !isnan(move_dir.y));
|
||||
#if 0
|
||||
moving = msg.has_move_dir();
|
||||
#endif
|
||||
if (msg.has_attack_dir()) {
|
||||
attack_dir.FromPB(&msg.attack_dir());
|
||||
attack_dir.Normalize();
|
||||
|
@ -25,7 +25,7 @@ Player* PlayerMgr::GetPlayerBySocket(int socket)
|
||||
return itr != socket_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
Player* PlayerMgr::CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJoin& msg)
|
||||
Player* PlayerMgr::CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, const cs::CMJoin& msg)
|
||||
{
|
||||
Player* hum = new Player();
|
||||
hum->entity_uniid = obj_uniid;
|
||||
@ -39,6 +39,7 @@ Player* PlayerMgr::CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJo
|
||||
hum->use_touch = msg.use_touch();
|
||||
hum->avatar_url = msg.avatar_url();
|
||||
hum->energy_shield = msg.energy_shield();
|
||||
socket_hash_[socket] = hum;
|
||||
// hum->baseskin = msg.baseskin();
|
||||
// hum->basemelee = msg.basemelee();
|
||||
// hum->elo_score = msg.elo_score();
|
||||
|
@ -21,7 +21,7 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||
void Update();
|
||||
|
||||
Player* GetPlayerBySocket(int socket);
|
||||
Player* CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJoin& msg);
|
||||
Player* CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, const cs::CMJoin& msg);
|
||||
|
||||
private:
|
||||
std::map<int, Player*> socket_hash_;
|
||||
|
@ -47,7 +47,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||
room_hash_[room->room_uuid] = room;
|
||||
}
|
||||
unsigned short new_uniid = room->AllocUniid();
|
||||
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(new_uniid, msg);
|
||||
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, new_uniid, msg);
|
||||
hum->meta = hum_meta;
|
||||
hum->socket_handle = hdr.socket_handle;
|
||||
hum->Initialize();
|
||||
|
Loading…
x
Reference in New Issue
Block a user