完成门逻辑改造
This commit is contained in:
parent
dd8d5ab3e8
commit
41699f3b91
@ -51,6 +51,7 @@ class Entity
|
|||||||
void BroadcastDeleteState();
|
void BroadcastDeleteState();
|
||||||
void AddCollider(ColliderComponent* collider);
|
void AddCollider(ColliderComponent* collider);
|
||||||
a8::Vec2 GetPos() { return pos_; };
|
a8::Vec2 GetPos() { return pos_; };
|
||||||
|
bool IsPermanent() { return is_permanent;};
|
||||||
void SetPos(a8::Vec2 pos)
|
void SetPos(a8::Vec2 pos)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -244,3 +244,51 @@ void Obstacle::Explosion(Bullet* bullet)
|
|||||||
self_collider_->rad = old_rad;
|
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;
|
||||||
|
}
|
||||||
|
@ -26,15 +26,6 @@ class Obstacle : public Entity
|
|||||||
MetaData::MapThing* meta = nullptr;
|
MetaData::MapThing* meta = nullptr;
|
||||||
float health = 0.0f;
|
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();
|
Obstacle();
|
||||||
virtual ~Obstacle() override;
|
virtual ~Obstacle() override;
|
||||||
virtual void Initialize() override;
|
virtual void Initialize() override;
|
||||||
@ -44,9 +35,27 @@ class Obstacle : public Entity
|
|||||||
virtual void GetAabbBox(AabbCollider& aabb_box) override;
|
virtual void GetAabbBox(AabbCollider& aabb_box) override;
|
||||||
virtual void GetCircleBox(CircleCollider& circle_box) override;
|
virtual void GetCircleBox(CircleCollider& circle_box) override;
|
||||||
void Explosion(Bullet* bullet);
|
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:
|
private:
|
||||||
CircleCollider* self_collider_ = nullptr;
|
CircleCollider* self_collider_ = nullptr;
|
||||||
AabbCollider* self_collider2_ = 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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -471,17 +471,19 @@ void Player::ProcInteraction()
|
|||||||
|
|
||||||
void Player::ObstacleInteraction(Obstacle* entity)
|
void Player::ObstacleInteraction(Obstacle* entity)
|
||||||
{
|
{
|
||||||
if (entity->is_door) {
|
if (entity->IsDoor()) {
|
||||||
if (entity->door_state == DoorStateClose) {
|
if (entity->GetDoorState() == DoorStateClose) {
|
||||||
entity->door_state = DoorStateOpen;
|
entity->SetDoorState(DoorStateOpen);
|
||||||
entity->SetPos(a8::Vec2(entity->building->GetX() + entity->door_state1->x() - entity->building->meta->i->tilewidth() / 2.0,
|
float x = entity->GetBuilding()->GetX() + entity->GetDoorState1()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
|
||||||
entity->building->GetY() + entity->door_state1->y() - entity->building->meta->i->tileheight() / 2.0));
|
float y = entity->GetBuilding()->GetY() + entity->GetDoorState1()->y() - entity->GetBuilding()->meta->i->tileheight() / 2.0;
|
||||||
|
entity->SetPos(a8::Vec2(x, y));
|
||||||
} else {
|
} else {
|
||||||
entity->door_state = DoorStateClose;
|
entity->SetDoorState(DoorStateClose);
|
||||||
entity->SetPos(a8::Vec2(entity->building->GetX() + entity->door_state0->x() - entity->building->meta->i->tilewidth() / 2.0,
|
float x = entity->GetBuilding()->GetX() + entity->GetDoorState0()->x() - entity->GetBuilding()->meta->i->tilewidth() / 2.0;
|
||||||
entity->building->GetY() + entity->door_state0->y() - entity->building->meta->i->tileheight() / 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();
|
entity->RecalcSelfCollider();
|
||||||
room->TouchHumanList(a8::XParams(),
|
room->TouchHumanList(a8::XParams(),
|
||||||
[entity] (Human* hum, a8::XParams& param) -> bool
|
[entity] (Human* hum, a8::XParams& param) -> bool
|
||||||
|
@ -1166,7 +1166,6 @@ Obstacle* Room::InternalCreateObstacle(int id, float x, float y,
|
|||||||
Obstacle* entity = new Obstacle();
|
Obstacle* entity = new Obstacle();
|
||||||
entity->room = this;
|
entity->room = this;
|
||||||
entity->meta = thing;
|
entity->meta = thing;
|
||||||
entity->building = nullptr;
|
|
||||||
entity->entity_uniid = AllocUniid();
|
entity->entity_uniid = AllocUniid();
|
||||||
entity->SetPos(a8::Vec2(x, y));
|
entity->SetPos(a8::Vec2(x, y));
|
||||||
entity->Initialize();
|
entity->Initialize();
|
||||||
|
@ -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 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;
|
float y = building->GetY() + door_meta->state0->y() - building->meta->i->tileheight() / 2.0;
|
||||||
InternalCreateObstacle(DOOR_THING_ID, x, y,
|
InternalCreateObstacle(DOOR_THING_ID, x, y,
|
||||||
[building, door_meta] (Obstacle* entity)
|
[building, door_idx] (Obstacle* entity)
|
||||||
{
|
{
|
||||||
entity->building = building;
|
entity->SetDoorInfo(building, door_idx);
|
||||||
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;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -465,7 +458,9 @@ void RoomMgr::CreateBuilding(int thing_id, float building_x, float building_y)
|
|||||||
InternalCreateObstacle(pair.key(), x, y,
|
InternalCreateObstacle(pair.key(), x, y,
|
||||||
[building] (Obstacle* entity)
|
[building] (Obstacle* entity)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
entity->building = building;
|
entity->building = building;
|
||||||
|
#endif
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user