This commit is contained in:
aozhiwei 2022-12-31 19:50:22 +08:00
parent d4b03e49ba
commit befa38e799
2 changed files with 12 additions and 66 deletions

View File

@ -769,74 +769,21 @@ void Room::OnHumanRevive(Human* hum)
bool Room::OverBorder(const Position& pos, float radius)
{
CircleCollider collider;
collider.pos.x = pos.x;
collider.pos.y = pos.z;
collider.rad = radius;
return OverBorder(pos, &collider);
}
bool Room::OverBorder(const Position& pos, ColliderComponent* collider)
{
switch (collider->type) {
case CT_Aabb:
{
AabbCollider* aabb_box = (AabbCollider*)collider;
//检查x轴
{
float left_x = (pos.ToVec2() + aabb_box->_min).x;
if (left_x < 0.001f) {
return true;
}
float right_x = (pos.ToVec2() + aabb_box->_max).x;
if (right_x > map_meta_->map_width()) {
return true;
}
}
//检查y轴
{
float down_y = (pos.ToVec2() + aabb_box->_min).y;
if (down_y < 0.001f) {
return true;
}
float up_y = (pos.ToVec2() + aabb_box->_max).y;
if (up_y > map_meta_->map_height()) {
return true;
}
}
{
if (pos.GetX() - radius < 0.0001f) {
return true;
}
break;
case CT_Circle:
{
CircleCollider* circle_collider = (CircleCollider*)collider;
//检查x轴
{
float left_x = pos.x - circle_collider->rad;
if (left_x < 0.001f) {
return true;
}
float right_x = pos.x + circle_collider->rad;
if (right_x > map_meta_->map_width()) {
return true;
}
}
//检查y轴
{
float down_y = pos.y - circle_collider->rad;
if (down_y < 0.001f) {
return true;
}
float up_y = pos.y + circle_collider->rad;
if (up_y > map_meta_->map_height()) {
return true;
}
}
if (pos.GetX() + radius > map_meta_->map_width()) {
return true;
}
break;
default:
{
}
{
if (pos.GetZ() - radius < 0.0001f) {
return true;
}
if (pos.GetZ() + radius > map_meta_->map_height()) {
return true;
}
break;
}
return false;
}

View File

@ -161,7 +161,6 @@ public:
void OnHumanDie(Human* hum);
void OnHumanRevive(Human* hum);
bool OverBorder(const Position& pos, float radius);
bool OverBorder(const Position& pos, ColliderComponent* collider);
Human* GetWatchWarTarget(Human* hum);
bool BattleStarted();
int GetTeamNum();