1
This commit is contained in:
commit
24c8d74094
@ -83,7 +83,7 @@ bool IntersectAabbCircle(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b
|
||||
b_pos.y >= a_min.y && b_pos.y <= a_max.y) {
|
||||
return true;
|
||||
}
|
||||
Vector2D nearest_point(a8::Clamp(b_pos.x, a_min.x, a_max.y),
|
||||
Vector2D nearest_point(a8::Clamp(b_pos.x, a_min.x, a_max.x),
|
||||
a8::Clamp(b_pos.y, a_min.y, a_max.y));
|
||||
Vector2D i = b_pos - nearest_point;
|
||||
float n = a8::LengthSqr(i);
|
||||
|
@ -33,9 +33,9 @@ bool Entity::TestCollision(Entity* b)
|
||||
for (auto& a_collider : colliders) {
|
||||
for (auto& b_collider : b->colliders) {
|
||||
if (a_collider->Intersect(b_collider)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -144,8 +144,19 @@ bool Human::IsCollision()
|
||||
return !objects.empty();
|
||||
}
|
||||
|
||||
ColliderComponent* Human::GetFirstCollision()
|
||||
{
|
||||
int detection_flags = 0;
|
||||
a8::SetBitFlag(detection_flags, ET_Obstacle);
|
||||
a8::SetBitFlag(detection_flags, ET_Building);
|
||||
std::vector<Entity*> objects;
|
||||
room->CollisionDetection(this, detection_flags, objects);
|
||||
return objects.empty() ? *objects[0]->colliders.begin() : nullptr;
|
||||
}
|
||||
|
||||
void Human::FindPath()
|
||||
{
|
||||
ColliderComponent* first_collider = nullptr;
|
||||
Vector2D old_pos = pos;
|
||||
{
|
||||
float up_dot = Vector2D::UP.Dot(move_dir);
|
||||
|
@ -59,6 +59,7 @@ class Human : public Entity
|
||||
void Shot(Vector2D& target_dir);
|
||||
void RecalcSelfCollider();
|
||||
bool IsCollision();
|
||||
ColliderComponent* GetFirstCollision();
|
||||
void FindPath();
|
||||
float GetRadius();
|
||||
|
||||
|
@ -22,13 +22,41 @@ void Obstacle::Initialize()
|
||||
|
||||
void Obstacle::RecalcSelfCollider()
|
||||
{
|
||||
#if 0
|
||||
if (meta->i->thing_id() == 61001) {
|
||||
if (!self_collider2_) {
|
||||
self_collider2_ = new AabbCollider();
|
||||
self_collider2_->owner = this;
|
||||
colliders.push_back(self_collider2_);
|
||||
}
|
||||
self_collider2_->_min = Vector2D(-16.0f, -16.0f);
|
||||
self_collider2_->_max = Vector2D(16.0f, 16.0f);
|
||||
} else if (meta->i->thing_id() == 61007) {
|
||||
if (!self_collider_) {
|
||||
self_collider_ = new CircleCollider();
|
||||
self_collider_->owner = this;
|
||||
colliders.push_back(self_collider_);
|
||||
}
|
||||
self_collider_->pos = Vector2D();
|
||||
self_collider_->rad = gun_meta->i->bullet_rad();
|
||||
#endif
|
||||
self_collider_->rad = 32 / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
void Obstacle::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
{
|
||||
part_data->set_object_type(ET_Obstacle);
|
||||
cs::MFObstaclePart* p = part_data->mutable_union_obj_2();
|
||||
p->set_obj_uniid(entity_uniid);
|
||||
pos.ToPB(p->mutable_pos());
|
||||
p->set_scale(1.0f);
|
||||
}
|
||||
|
||||
void Obstacle::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
{
|
||||
full_data->set_object_type(ET_Obstacle);
|
||||
cs::MFObstacleFull* p = full_data->mutable_union_obj_2();
|
||||
p->set_obj_uniid(entity_uniid);
|
||||
pos.ToPB(p->mutable_pos());
|
||||
p->set_scale(1.0f);
|
||||
|
||||
p->set_obstacle_id(meta->i->thing_id());
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ namespace MetaData
|
||||
|
||||
class Human;
|
||||
class CircleCollider;
|
||||
class AabbCollider;
|
||||
class Obstacle : public Entity
|
||||
{
|
||||
public:
|
||||
@ -20,8 +21,11 @@ class Obstacle : public Entity
|
||||
virtual ~Obstacle() override;
|
||||
virtual void Initialize() override;
|
||||
void RecalcSelfCollider();
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
AabbCollider* self_collider2_ = nullptr;
|
||||
|
||||
};
|
||||
|
@ -139,18 +139,24 @@ void Room::ShuaAndroid()
|
||||
|
||||
void Room::ShuaObstacle(Human* hum)
|
||||
{
|
||||
#if 0
|
||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61001);
|
||||
if (thing) {
|
||||
Obstacle* entity = new Obstacle();
|
||||
entity->room = this;
|
||||
entity->meta = thing;
|
||||
entity->entity_uniid = AllocUniid();
|
||||
MetaData::MapThing* a_thing = MetaMgr::Instance()->GetMapThing(61001);
|
||||
MetaData::MapThing* b_thing = MetaMgr::Instance()->GetMapThing(61007);
|
||||
if (!a_thing || !b_thing) {
|
||||
return;
|
||||
}
|
||||
#if 1
|
||||
{
|
||||
Vector2D dir = hum->pos;
|
||||
dir.Normalize();
|
||||
}
|
||||
Obstacle* entity = new Obstacle();
|
||||
entity->room = this;
|
||||
entity->meta = a_thing;
|
||||
entity->entity_uniid = AllocUniid();
|
||||
#if 0
|
||||
entity->dir = Vector2D::UP;
|
||||
#endif
|
||||
#if 0
|
||||
entity->pos = Vector2D(100.0f, 164.0f);
|
||||
#else
|
||||
entity->pos = hum->pos - Vector2D::LEFT * hum->meta->i->radius() - 100;
|
||||
#endif
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
@ -158,18 +164,31 @@ void Room::ShuaObstacle(Human* hum)
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
MetaData::MapThing* a_thing = MetaMgr::Instance()->GetMapThing(61001);
|
||||
MetaData::MapThing* b_thing = MetaMgr::Instance()->GetMapThing(61007);
|
||||
if (!a_thing || !b_thing) {
|
||||
return;
|
||||
}
|
||||
#if 1
|
||||
{
|
||||
Obstacle* obj = new Obstacle();
|
||||
obj->entity_uniid = AllocUniid();
|
||||
obj->room = this;
|
||||
Obstacle* entity = new Obstacle();
|
||||
entity->room = this;
|
||||
entity->meta = b_thing;
|
||||
entity->entity_uniid = AllocUniid();
|
||||
#if 0
|
||||
entity->dir = Vector2D::UP;
|
||||
#endif
|
||||
#if 0
|
||||
entity->pos = Vector2D(100.0f, 100.0f);
|
||||
#else
|
||||
entity->pos = hum->pos + Vector2D::RIGHT * hum->meta->i->radius() + 100;
|
||||
#endif
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Room::RandomPos(Human* hum, float distance, Vector2D& out_pos)
|
||||
{
|
||||
@ -222,7 +241,7 @@ void Room::AddBullet(Bullet* bullet)
|
||||
be_added_hash_[bullet->entity_uniid] = bullet;
|
||||
}
|
||||
|
||||
void Room::CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*> objects)
|
||||
void Room::CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects)
|
||||
{
|
||||
assert(uniid_hash_.size() < 1000);
|
||||
for (auto& pair : uniid_hash_) {
|
||||
@ -239,8 +258,8 @@ void Room::CollisionDetection(Entity* sender, int detection_flags, std::vector<E
|
||||
}
|
||||
}
|
||||
if (a8::HasBitFlag(detection_flags, ET_Obstacle) && pair.second->entity_type == ET_Obstacle) {
|
||||
if (sender->entity_type == ET_Bullet || pair.second->entity_type == ET_Player) {
|
||||
if (sender->TestCollision(pair.second)) {
|
||||
if (sender->entity_type == ET_Bullet || sender->entity_type == ET_Player) {
|
||||
if (pair.second != sender && sender->TestCollision(pair.second)) {
|
||||
objects.push_back(pair.second);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
void ShuaObstacle(Human* hum);
|
||||
bool RandomPos(Human* hum, float distance, Vector2D& out_pos);
|
||||
Human* FindEnemy(Human* hum);
|
||||
void CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*> objects);
|
||||
void CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects);
|
||||
void AddDeletedObject(unsigned short obj_uniid);
|
||||
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
|
||||
void ResetFrameData();
|
||||
|
@ -52,6 +52,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||
hum->socket_handle = hdr.socket_handle;
|
||||
hum->Initialize();
|
||||
room->AddPlayer(hum);
|
||||
room->ShuaObstacle(hum);
|
||||
|
||||
{
|
||||
cs::SMJoinedNotify notifymsg;
|
||||
|
Loading…
x
Reference in New Issue
Block a user