完成门逻辑改造

This commit is contained in:
aozhiwei 2020-05-20 10:38:15 +08:00
parent dd8d5ab3e8
commit 41699f3b91
6 changed files with 82 additions and 28 deletions

View File

@ -51,6 +51,7 @@ class Entity
void BroadcastDeleteState();
void AddCollider(ColliderComponent* collider);
a8::Vec2 GetPos() { return pos_; };
bool IsPermanent() { return is_permanent;};
void SetPos(a8::Vec2 pos)
{
#if 0

View File

@ -244,3 +244,51 @@ void Obstacle::Explosion(Bullet* bullet)
self_collider_->rad = old_rad;
}
}
void Obstacle::SetDoorInfo(Building* building, int door_idx)
{
MetaData::Building::Door* door_meta = &building->meta->doors[door_idx];
building = building;
is_door = true;
door_id = door_meta->door_id;
door_state = DoorStateClose;
building = building;
door_house_uniid = building->entity_uniid;
door_state0 = door_meta->state0;
door_state1 = door_meta->state1;
}
bool Obstacle::IsDoor()
{
return is_door;
}
DoorState_e Obstacle::GetDoorState()
{
return door_state;
}
void Obstacle::SetDoorState(DoorState_e state)
{
door_state = state;
}
Building* Obstacle::GetBuilding()
{
return building;
}
const metatable::DoorObjJson* Obstacle::GetDoorState0()
{
return door_state0;
}
const metatable::DoorObjJson* Obstacle::GetDoorState1()
{
return door_state1;
}
void Obstacle::IncDoorOpenTimes()
{
++door_open_times;
}

View File

@ -26,15 +26,6 @@ class Obstacle : public Entity
MetaData::MapThing* meta = nullptr;
float health = 0.0f;
bool is_door = false;
int door_id = 0;
int door_open_times = 0;
DoorState_e door_state = DoorStateClose;
Building* building = nullptr;
int door_house_uniid = 0;
const metatable::DoorObjJson* door_state0 = nullptr;
const metatable::DoorObjJson* door_state1 = nullptr;
Obstacle();
virtual ~Obstacle() override;
virtual void Initialize() override;
@ -44,9 +35,27 @@ class Obstacle : public Entity
virtual void GetAabbBox(AabbCollider& aabb_box) override;
virtual void GetCircleBox(CircleCollider& circle_box) override;
void Explosion(Bullet* bullet);
void SetDoorInfo(Building* building, int door_idx);
bool IsDoor();
DoorState_e GetDoorState();
void SetDoorState(DoorState_e state);
Building* GetBuilding();
const metatable::DoorObjJson* GetDoorState0();
const metatable::DoorObjJson* GetDoorState1();
void IncDoorOpenTimes();
private:
CircleCollider* self_collider_ = nullptr;
AabbCollider* self_collider2_ = nullptr;
bool is_door = false;
int door_id = 0;
int door_open_times = 0;
DoorState_e door_state = DoorStateClose;
Building* building = nullptr;
int door_house_uniid = 0;
const metatable::DoorObjJson* door_state0 = nullptr;
const metatable::DoorObjJson* door_state1 = nullptr;
};

View File

@ -471,17 +471,19 @@ void Player::ProcInteraction()
void Player::ObstacleInteraction(Obstacle* entity)
{
if (entity->is_door) {
if (entity->door_state == DoorStateClose) {
entity->door_state = DoorStateOpen;
entity->SetPos(a8::Vec2(entity->building->GetX() + entity->door_state1->x() - entity->building->meta->i->tilewidth() / 2.0,
entity->building->GetY() + entity->door_state1->y() - entity->building->meta->i->tileheight() / 2.0));
if (entity->IsDoor()) {
if (entity->GetDoorState() == DoorStateClose) {
entity->SetDoorState(DoorStateOpen);
float x = entity->GetBuilding()->GetX() + entity->GetDoorState1()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
float y = entity->GetBuilding()->GetY() + entity->GetDoorState1()->y() - entity->GetBuilding()->meta->i->tileheight() / 2.0;
entity->SetPos(a8::Vec2(x, y));
} else {
entity->door_state = DoorStateClose;
entity->SetPos(a8::Vec2(entity->building->GetX() + entity->door_state0->x() - entity->building->meta->i->tilewidth() / 2.0,
entity->building->GetY() + entity->door_state0->y() - entity->building->meta->i->tileheight() / 2.0));
entity->SetDoorState(DoorStateClose);
float x = entity->GetBuilding()->GetX() + entity->GetDoorState0()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
float y = entity->GetBuilding()->GetY() + entity->GetDoorState0()->y() - entity->GetBuilding()->meta->i->tileheight() / 2.0;
entity->SetPos(a8::Vec2(x, y));
}
++entity->door_open_times;
entity->IncDoorOpenTimes();
entity->RecalcSelfCollider();
room->TouchHumanList(a8::XParams(),
[entity] (Human* hum, a8::XParams& param) -> bool

View File

@ -1166,7 +1166,6 @@ Obstacle* Room::InternalCreateObstacle(int id, float x, float y,
Obstacle* entity = new Obstacle();
entity->room = this;
entity->meta = thing;
entity->building = nullptr;
entity->entity_uniid = AllocUniid();
entity->SetPos(a8::Vec2(x, y));
entity->Initialize();

View File

@ -442,16 +442,9 @@ void RoomMgr::CreateBuilding(int thing_id, float building_x, float building_y)
float x = building->GetX() + door_meta->state0->x() - building->meta->i->tilewidth() / 2.0;
float y = building->GetY() + door_meta->state0->y() - building->meta->i->tileheight() / 2.0;
InternalCreateObstacle(DOOR_THING_ID, x, y,
[building, door_meta] (Obstacle* entity)
[building, door_idx] (Obstacle* entity)
{
entity->building = building;
entity->is_door = true;
entity->door_id = door_meta->door_id;
entity->door_state = DoorStateClose;
entity->building = building;
entity->door_house_uniid = building->entity_uniid;
entity->door_state0 = door_meta->state0;
entity->door_state1 = door_meta->state1;
entity->SetDoorInfo(building, door_idx);
});
}
}
@ -465,7 +458,9 @@ void RoomMgr::CreateBuilding(int thing_id, float building_x, float building_y)
InternalCreateObstacle(pair.key(), x, y,
[building] (Obstacle* entity)
{
#if 0
entity->building = building;
#endif
});
break;
}