This commit is contained in:
aozhiwei 2019-04-28 16:20:48 +08:00
parent 1b7064b92a
commit d6fec365aa
5 changed files with 82 additions and 3 deletions

View File

@ -20,6 +20,7 @@ enum EntityType_e
//ET_Decal = 7, //ET_Decal = 7,
//ET_Projectile = 8, //ET_Projectile = 8,
ET_Smoke = 9, ET_Smoke = 9,
ET_Hero = 10,
ET_Bullet = 20, ET_Bullet = 20,

View File

@ -0,0 +1,65 @@
#include "precompile.h"
#include "hero.h"
#include "collider.h"
#include "human.h"
Hero::Hero(): Entity()
{
entity_type = ET_Hero;
}
Hero::~Hero()
{
}
void Hero::Initialize()
{
Entity::Initialize();
RecalcSelfCollider();
}
void Hero::RecalcSelfCollider()
{
if (!self_collider_) {
self_collider_ = new CircleCollider();
self_collider_->owner = this;
colliders.push_back(self_collider_);
}
self_collider_->pos = Vector2D();
self_collider_->rad = master->GetRadius();
}
void Hero::FillMFObjectPart(cs::MFObjectPart* part_data)
{
part_data->set_object_type(entity_type);
cs::MFHeroPart* p = part_data->mutable_union_obj_10();
p->set_obj_uniid(entity_uniid);
pos.ToPB(p->mutable_pos());
attack_dir.ToPB(p->mutable_dir());
}
void Hero::FillMFObjectFull(cs::MFObjectFull* full_data)
{
full_data->set_object_type(entity_type);
cs::MFHeroFull* p = full_data->mutable_union_obj_10();
p->set_obj_uniid(entity_uniid);
pos.ToPB(p->mutable_pos());
attack_dir.ToPB(p->mutable_dir());
p->set_skin(skin);
p->set_backpack(backpack);
p->set_helmet(helmet);
p->set_chest(chest);
weapon.ToPB(p->mutable_weapon());
}
ColliderComponent* Hero::GetBoxBound()
{
CircleCollider* collider = new CircleCollider();
collider->owner = this;
collider->pos = Vector2D();
collider->rad = master->GetRadius();
return collider;
}

View File

@ -2,6 +2,10 @@
#include "entity.h" #include "entity.h"
class Building;
class CircleCollider;
class AabbCollider;
class Human;
class Hero : public Entity class Hero : public Entity
{ {
public: public:
@ -9,7 +13,7 @@ class Hero : public Entity
Vector2D move_dir; Vector2D move_dir;
Vector2D attack_dir; Vector2D attack_dir;
int master_uniid = 0; Human* master = nullptr;
int skin = 0; int skin = 0;
int backpack = 0; int backpack = 0;
@ -17,6 +21,14 @@ class Hero : public Entity
int chest = 0; int chest = 0;
Weapon weapon; Weapon weapon;
Hero();
virtual ~Hero() override;
virtual void Initialize() override;
void RecalcSelfCollider();
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual ColliderComponent* GetBoxBound() override;
private: private:
CircleCollider* self_collider_ = nullptr; CircleCollider* self_collider_ = nullptr;

View File

@ -10,7 +10,7 @@
#include "collision.h" #include "collision.h"
#include "building.h" #include "building.h"
Human::Human() Human::Human():Entity()
{ {
default_weapon.weapon_idx = 0; default_weapon.weapon_idx = 0;
default_weapon.weapon_id = 12101; default_weapon.weapon_id = 12101;

View File

@ -12,7 +12,7 @@
#include "building.h" #include "building.h"
#include "loot.h" #include "loot.h"
Player::Player() Player::Player():Human()
{ {
entity_type = ET_Player; entity_type = ET_Player;
entity_subtype = EST_Player; entity_subtype = EST_Player;
@ -20,6 +20,7 @@ Player::Player()
Player::~Player() Player::~Player()
{ {
} }
void Player::Initialize() void Player::Initialize()