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