This commit is contained in:
aozhiwei 2019-03-27 14:56:15 +08:00
parent 3fdfc92394
commit cce493f454
14 changed files with 127 additions and 17 deletions

View File

@ -5,6 +5,8 @@
#include "movement.h"
#include "room.h"
#include "collider.h"
#include "obstacle.h"
#include "player.h"
Bullet::Bullet():Entity()
{
@ -38,6 +40,9 @@ void Bullet::Update(int delta_time)
float distance = (pos - born_pos).Norm();
if (!objects.empty() || distance > gun_meta->i->range()) {
deleted = true;
if (!objects.empty()) {
OnHit(objects);
}
room->AddDeletedObject(entity_uniid);
}
}
@ -52,3 +57,38 @@ void Bullet::RecalcSelfCollider()
self_collider_->pos = Vector2D();
self_collider_->rad = gun_meta->i->bullet_rad();
}
void Bullet::OnHit(std::vector<Entity*>& objects)
{
for (auto& target : objects) {
switch (target->entity_type) {
case ET_Player:
{
}
break;
case ET_Obstacle:
{
Obstacle* obstacle = (Obstacle*)target;
if (!obstacle->dead && obstacle->meta->i->attackable()) {
obstacle->health = std::min(0.0f, obstacle->health - 10);
obstacle->dead = std::min(obstacle->health, 0.001f) <= 0.01f;
if (obstacle->dead) {
obstacle->ClearColliders();
room->ProcDrop(pos, obstacle->meta->i->drop());
}
room->TouchPlayerList(a8::XParams()
.SetSender(obstacle),
[] (Player* hum, a8::XParams& param)
{
Obstacle* obstacle = (Obstacle*)param.sender.GetUserData();
hum->new_objects.insert(obstacle);
});
}
}
break;
default:
break;
}
}
}

View File

@ -26,6 +26,10 @@ class Bullet : public Entity
virtual void Update(int delta_time) override;
void RecalcSelfCollider();
private:
void OnHit(std::vector<Entity*>& objects);
private:
CircleCollider* self_collider_ = nullptr;

View File

@ -4,6 +4,23 @@
#include "collider.h"
Entity::~Entity()
{
ClearColliders();
}
bool Entity::TestCollision(Entity* b)
{
for (auto& a_collider : colliders) {
for (auto& b_collider : b->colliders) {
if (a_collider->Intersect(b_collider)) {
return true;
}
}
}
return false;
}
void Entity::ClearColliders()
{
for (auto& itr : colliders) {
ColliderComponent* collider = itr;
@ -27,15 +44,3 @@ Entity::~Entity()
}
colliders.clear();
}
bool Entity::TestCollision(Entity* b)
{
for (auto& a_collider : colliders) {
for (auto& b_collider : b->colliders) {
if (a_collider->Intersect(b_collider)) {
return true;
}
}
}
return false;
}

View File

@ -53,4 +53,5 @@ class Entity
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) {};
virtual float GetSpeed() { return 1.0f;};
bool TestCollision(Entity* b);
void ClearColliders();
};

View File

@ -5,4 +5,14 @@
namespace MetaData
{
void Drop::Init()
{
}
void Drop::RandItem(std::vector<std::tuple<int, int, int>>& drop_items)
{
}
}

View File

@ -40,10 +40,20 @@ namespace MetaData
const metatable::Player* i = nullptr;
};
struct Building
{
const metatable::BuildingJson* i = nullptr;
};
struct Drop
{
const metatable::Drop* i = nullptr;
void Init();
void RandItem(std::vector<std::tuple<int, int, int>>& drop_items);
private:
std::vector<std::tuple<int, int, int>> items;
};
}

View File

@ -26,6 +26,8 @@ public:
std::list<MetaData::MapThing> mapthing_list;
std::list<metatable::BuildingJson> building_meta_list;
std::list<MetaData::Building> building_list;
std::list<metatable::Drop> drop_meta_list;
std::list<MetaData::Drop> drop_list;
std::map<std::string, MetaData::Parameter*> parameter_hash;
std::map<int, MetaData::Map*> gamemap_hash;
@ -35,6 +37,7 @@ public:
std::map<int, MetaData::Player*> player_hash;
std::map<int, MetaData::MapThing*> mapthing_hash;
std::map<int, MetaData::Building*> building_hash;
std::map<int, MetaData::Drop*> drop_hash;
void Load()
{
@ -53,6 +56,7 @@ public:
f8::ReadCsvMetaFile(res_path + "player@player.csv", player_meta_list);
f8::ReadCsvMetaFile(res_path + "player@player.csv", player_meta_list);
f8::ReadCsvMetaFile(res_path + "mapThing@mapThing.csv", mapthing_meta_list);
f8::ReadCsvMetaFile(res_path + "drop@drop.csv", drop_meta_list);
f8::ReadJsonMetaFile(res_path + "maps.json", building_meta_list);
BindToMetaData();
}
@ -104,6 +108,12 @@ private:
mapthing_hash[item.i->thing_id()] = &item;
}
for (auto& meta : drop_meta_list) {
MetaData::Drop& item = a8::FastAppend(drop_list);
item.i = &meta;
drop_hash[item.i->drop_id()] = &item;
}
{
int building_id = 0;
for (auto& meta : building_meta_list) {
@ -174,3 +184,9 @@ MetaData::Building* MetaMgr::GetBuilding(int building_id)
auto itr = loader_->building_hash.find(building_id);
return itr != loader_->building_hash.end() ? itr->second : nullptr;
}
MetaData::Drop* MetaMgr::GetDrop(int drop_id)
{
auto itr = loader_->drop_hash.find(drop_id);
return itr != loader_->drop_hash.end() ? itr->second : nullptr;
}

View File

@ -22,6 +22,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
MetaData::Player* GetPlayer(int id);
MetaData::Equip* GetEquip(int id);
MetaData::Building* GetBuilding(int building_id);
MetaData::Drop* GetDrop(int drop_id);
private:
MetaDataLoader* loader_ = nullptr;

View File

@ -17,6 +17,7 @@ Obstacle::~Obstacle()
void Obstacle::Initialize()
{
health = meta->i->hp();
RecalcSelfCollider();
}
@ -78,4 +79,6 @@ void Obstacle::FillMFObjectFull(cs::MFObjectFull* full_data)
p->set_scale(1.0f);
p->set_obstacle_id(meta->i->thing_id());
p->set_health(health);
p->set_dead(dead);
}

View File

@ -16,6 +16,8 @@ class Obstacle : public Entity
{
public:
MetaData::MapThing* meta = nullptr;
float health = 0.0f;
bool dead = false;
Obstacle();
virtual ~Obstacle() override;

View File

@ -328,6 +328,11 @@ void Room::ResetFrameData()
frame_data.shots.Clear();
}
void Room::ProcDrop(Vector2D center, int drop_id)
{
}
void Room::ClearDeletedObjects()
{
for (auto& obj_uniid : frame_data.deleted_objects) {

View File

@ -56,6 +56,7 @@ public:
void TouchPlayerList(a8::XParams param,
std::function<void (Player*, a8::XParams&)> func);
void BeAddedObject(Entity* entity);
void ProcDrop(Vector2D center, int drop_id);
private:
void ClearDeletedObjects();

View File

@ -167,11 +167,12 @@ message MFObstacleFull
optional int32 obstacle_id = 6; //id
optional float health = 7; //
optional bool dead = 8; //
optional bool dead_at_thisframe = 9; //()
optional bool is_door = 9; //
optional int32 door_relative_ori = 10; //
optional bool door_can_use = 11; //
optional int32 door_seq = 12;
optional bool is_door = 20; //
optional int32 door_relative_ori = 21; //
optional bool door_can_use = 22; //
optional int32 door_seq = 23;
}
//-
@ -237,6 +238,7 @@ message MFDeadBodyFull
{
optional int32 obj_uniid = 1; //id
optional MFVector2D pos = 2; //
optional int32 player_id = 3; //id
optional int32 inkjet = 6;
}

View File

@ -23,6 +23,7 @@ message MapThing
optional float damage = 6; //
optional float damage_dia = 7; //
optional int32 drop = 8; //
optional int32 attackable = 9; //
}
message SafeArea
@ -78,6 +79,15 @@ message Skill
optional int32 skill_id = 1; //id
}
message Drop
{
optional int32 drop_id = 1;
optional string item_id = 2;
optional string num = 3;
optional string weight = 4;
optional int32 type = 5;
}
message DoorObjJson
{
optional float height = 1;