add roomobstacle

This commit is contained in:
aozhiwei 2020-05-20 16:33:08 +08:00
parent 51adf8e366
commit 1102b43384
12 changed files with 107 additions and 18 deletions

View File

@ -21,7 +21,7 @@ Bullet::~Bullet()
void Bullet::Initialize()
{
Entity::Initialize();
MoveableEntity::Initialize();
RecalcSelfCollider();
}

View File

@ -31,7 +31,6 @@ class Entity
Entity();
virtual ~Entity();
virtual void Initialize();
virtual void Update(int delta_time) {};
virtual void FillMFObjectPart(Room* room, cs::MFObjectPart* part_data) {};
virtual void FillMFObjectFull(Room* room, cs::MFObjectFull* full_data) {};
virtual float GetSpeed() { return 1.0f;};

View File

@ -68,7 +68,7 @@ Human::~Human()
void Human::Initialize()
{
Entity::Initialize();
MoveableEntity::Initialize();
skill_xtimer_attacher_.xtimer = &room->xtimer;
RecalcSelfCollider();
volume_ = meta->volume;

View File

@ -21,7 +21,7 @@ Loot::~Loot()
void Loot::Initialize()
{
Entity::Initialize();
RoomEntity::Initialize();
RecalcSelfCollider();
}

View File

@ -6,5 +6,5 @@ class MoveableEntity : public RoomEntity
{
public:
int updated_times = 0;
virtual void Update(int delta_time) {};
};

View File

@ -27,7 +27,7 @@ class Obstacle : public Entity
Obstacle();
virtual ~Obstacle() override;
virtual void Initialize() override;
void RecalcSelfCollider();
virtual void RecalcSelfCollider();
virtual void FillMFObjectPart(Room* room, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Room* room, cs::MFObjectFull* full_data) override;
virtual void GetAabbBox(AabbCollider& aabb_box) override;
@ -49,7 +49,7 @@ class Obstacle : public Entity
void SetHealth(Room* room, float value);
void Die(Room* room);
private:
protected:
CircleCollider* self_collider_ = nullptr;
AabbCollider* self_collider2_ = nullptr;

View File

@ -16,6 +16,7 @@
#include "bullet.h"
#include "collider.h"
#include "obstacle.h"
#include "roomobstacle.h"
#include "building.h"
#include "loot.h"
#include "roommgr.h"
@ -367,12 +368,12 @@ void Room::DropItem(a8::Vec2 pos, int item_id, int item_count, int item_lv)
}
}
Obstacle* Room::CreateObstacle(int id, float x, float y)
RoomObstacle* Room::CreateObstacle(int id, float x, float y)
{
Obstacle* entity = InternalCreateObstacle(id, x, y,
[] (Obstacle*)
{
});
RoomObstacle* entity = InternalCreateObstacle(id, x, y,
[] (Obstacle*)
{
});
assert(entity);
if (entity) {
entity->BroadcastFullState(this);
@ -1159,13 +1160,14 @@ void Room::AirDrop(int appear_time, int box_id)
}
}
Obstacle* Room::InternalCreateObstacle(int id, float x, float y,
std::function<void (Obstacle*)> on_precreate)
RoomObstacle* Room::InternalCreateObstacle(int id, float x, float y,
std::function<void (Obstacle*)> on_precreate)
{
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(id);
if (thing) {
Obstacle* entity = new Obstacle();
RoomObstacle* entity = new RoomObstacle();
entity->meta = thing;
entity->room = this;
entity->entity_uniid = AllocUniid();
entity->SetPos(a8::Vec2(x, y));
entity->Initialize();

View File

@ -28,6 +28,7 @@ class Entity;
class RoomEntity;
class MoveableEntity;
class Obstacle;
class RoomObstacle;
class Bullet;
class Human;
class Player;
@ -128,9 +129,9 @@ private:
void AirDrop(int appear_time, int box_id);
void ShuaPlane();
int NewTeam();
Obstacle* CreateObstacle(int id, float x, float y);
Obstacle* InternalCreateObstacle(int id, float x, float y,
std::function<void (Obstacle*)> on_precreate);
RoomObstacle* CreateObstacle(int id, float x, float y);
RoomObstacle* InternalCreateObstacle(int id, float x, float y,
std::function<void (Obstacle*)> on_precreate);
void AddObjectLater(RoomEntity* entity);
void OnGameOver();
void RandRemoveAndroid();

View File

@ -0,0 +1,10 @@
#include "precompile.h"
#include "roomentity.h"
#include "room.h"
void RoomEntity::Initialize()
{
Entity::Initialize();
xtimer_attacher.xtimer = &room->xtimer;
}

View File

@ -8,4 +8,5 @@ class RoomEntity : public Entity
Room* room = nullptr;
a8::XTimerAttacher xtimer_attacher;
virtual void Initialize() override;
};

View File

@ -0,0 +1,60 @@
#include "precompile.h"
#include "metamgr.h"
#include "room.h"
#include "collider.h"
#include "building.h"
#include "human.h"
#include "app.h"
#include "typeconvert.h"
#include "bullet.h"
#include "mapservice.h"
#include "roomobstacle.h"
RoomObstacle::RoomObstacle():Obstacle()
{
}
RoomObstacle::~RoomObstacle()
{
}
void RoomObstacle::Initialize()
{
Obstacle::Initialize();
xtimer_attacher.xtimer = &room->xtimer;
}
void RoomObstacle::RecalcSelfCollider()
{
if (meta->i->attack_type() != 2){
switch (meta->i->type()) {
case 1:
{
if (!self_collider_) {
self_collider_ = new CircleCollider();
self_collider_->owner = this;
AddCollider(self_collider_);
}
self_collider_->pos = a8::Vec2();
self_collider_->rad = meta->i->height() / 2.0;
permanent_map_service->AddCollider(self_collider_);
}
break;
case 2:
{
if (!self_collider2_) {
self_collider2_ = new AabbCollider();
self_collider2_->owner = this;
AddCollider(self_collider2_);
}
self_collider2_->_min = a8::Vec2(meta->i->width() / -2.0f, meta->i->height() / -2.0f);
self_collider2_->_max = a8::Vec2(meta->i->width() / 2.0f, meta->i->height() / 2.0f);
permanent_map_service->AddCollider(self_collider2_);
}
break;
}
}
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "obstacle.h"
class RoomObstacle : public Obstacle
{
public:
Room* room = nullptr;
a8::XTimerAttacher xtimer_attacher;
RoomObstacle();
virtual ~RoomObstacle() override;
virtual void Initialize() override;
virtual void RecalcSelfCollider() override;
};