This commit is contained in:
aozhiwei 2021-04-07 13:23:04 +08:00
parent dc3dacc865
commit 440a1be16c
3 changed files with 43 additions and 26 deletions

View File

@ -884,8 +884,13 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
case kBET_FlashMove: case kBET_FlashMove:
{ {
a8::Vec2 old_pos = GetPos(); a8::Vec2 old_pos = GetPos();
a8::Vec2 new_pos = GetPos() + skill_dir_ * skill_distance_; a8::Vec2 new_pos = GetPos() + skill_dir_ * std::max(skill_distance_, 300.0f);
SetPos(new_pos); SetPos(new_pos);
if (CollisonDetection()) {
SetPos(old_pos);
} else {
room->grid_service->MoveCreature(this);
}
} }
break; break;
default: default:
@ -1347,7 +1352,6 @@ RoomObstacle* Creature::SummonObstacle(int id, const a8::Vec2& pos)
bool Creature::CollisonDetection() bool Creature::CollisonDetection()
{ {
#if 0
if (room->OverBorder(GetPos(), GetRadius())){ if (room->OverBorder(GetPos(), GetRadius())){
return true; return true;
} }
@ -1367,10 +1371,8 @@ bool Creature::CollisonDetection()
{ {
Obstacle* obstacle = (Obstacle*)collider->owner; Obstacle* obstacle = (Obstacle*)collider->owner;
if (!obstacle->IsDead(room) && if (!obstacle->IsDead(room) &&
( (collider->type == CT_Aabb && aabb_box.Intersect((ColliderComponent*)collider))
(collider->type == CT_Aabb && aabb_box.Intersect((ColliderComponent*)collider)) || ) {
(collider->type == CT_Circle && self_collider_->Intersect((ColliderComponent*)collider))
)) {
return true; return true;
} }
} }
@ -1378,10 +1380,7 @@ bool Creature::CollisonDetection()
case ET_Building: case ET_Building:
{ {
if ( if (
( (collider->type == CT_Aabb && aabb_box.Intersect((ColliderComponent*)collider))
(collider->type == CT_Aabb && aabb_box.Intersect((ColliderComponent*)collider)) ||
(collider->type == CT_Circle && self_collider_->Intersect((ColliderComponent*)collider))
)
) { ) {
return true; return true;
} }
@ -1391,6 +1390,5 @@ bool Creature::CollisonDetection()
break; break;
} }
} }
#endif
return false; return false;
} }

View File

@ -56,19 +56,6 @@ void Hero::Update(int delta_time)
++updated_times_; ++updated_times_;
} }
void Hero::GetAabbBox(AabbCollider& aabb_box)
{
if (!meta) {
abort();
}
aabb_box.active = true;
aabb_box.owner = this;
aabb_box._min.x = -meta->i->radius();
aabb_box._min.y = -meta->i->radius();
aabb_box._max.x = meta->i->radius();
aabb_box._max.y = meta->i->radius();
}
float Hero::GetSpeed() float Hero::GetSpeed()
{ {
float speed = meta->i->move_speed(); float speed = meta->i->move_speed();
@ -193,3 +180,34 @@ float Hero::GetRadius()
{ {
return meta->i->radius(); return meta->i->radius();
} }
float Hero::GetHitRadius()
{
return meta->i->hit_radius();
}
void Hero::GetAabbBox(AabbCollider& aabb_box)
{
if (!meta) {
abort();
}
aabb_box.active = true;
aabb_box.owner = this;
aabb_box._min.x = -GetRadius();
aabb_box._min.y = -GetRadius();
aabb_box._max.x = GetRadius();
aabb_box._max.y = GetRadius();
}
void Hero::GetHitAabbBox(AabbCollider& aabb_box)
{
if (!meta) {
abort();
}
aabb_box.active = true;
aabb_box.owner = this;
aabb_box._min.x = -GetHitRadius();
aabb_box._min.y = -GetHitRadius();
aabb_box._max.x = GetHitRadius();
aabb_box._max.y = GetHitRadius();
}

View File

@ -27,11 +27,12 @@ public:
virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override; virtual void FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) override;
virtual void Update(int delta_time) override; virtual void Update(int delta_time) override;
virtual void GetAabbBox(AabbCollider& aabb_box) override;
virtual float GetSpeed() override; virtual float GetSpeed() override;
virtual float GetRadius() override; virtual float GetRadius() override;
virtual float GetHitRadius() override;
virtual void GetAabbBox(AabbCollider& aabb_box) override;
virtual void GetHitAabbBox(AabbCollider& aabb_box) override;
protected: protected:
virtual void _UpdateMove(int speed) override; virtual void _UpdateMove(int speed) override;
void InternalUpdateMove(float speed); void InternalUpdateMove(float speed);