add collider.*

This commit is contained in:
aozhiwei 2019-03-16 10:17:10 +08:00
parent e33223ddd5
commit 081ea350b0
7 changed files with 176 additions and 3 deletions

View File

@ -3,6 +3,108 @@
#include "android.ai.h"
void AndroidAI::Update(int delta_time)
{
state_elapsed_time += delta_time;
switch (state) {
case AS_thinking:
{
if (state_elapsed_time < 1000) {
UpdateThink();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoMove();
} else if (rnd % 100 < 50) {
DoAttack();
}
}
}
break;
case AS_moving:
{
if (state_elapsed_time < 1000) {
UpdateMove();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoThink();
} else if (rnd % 100 < 50) {
DoAttack();
}
}
}
break;
case AS_attack:
{
if (state_elapsed_time < 1000) {
UpdateAttack();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoMove();
} else if (rnd % 100 < 50) {
DoThink();
}
}
}
break;
case AS_moving_and_attack:
{
if (state_elapsed_time < 1000) {
UpdateMoveAndAttack();
} else {
int rnd = rand();
if (rnd % 100 < 30) {
DoMove();
} else if (rnd % 100 < 50) {
DoAttack();
}
}
}
break;
}
}
void AndroidAI::UpdateThink()
{
}
void AndroidAI::UpdateMove()
{
}
void AndroidAI::UpdateAttack()
{
}
void AndroidAI::UpdateMoveAndAttack()
{
}
void AndroidAI::DoThink()
{
state = AS_thinking;
state_elapsed_time = 0;
}
void AndroidAI::DoMove()
{
state = AS_moving;
state_elapsed_time = 0;
}
void AndroidAI::DoAttack()
{
state = AS_attack;
state_elapsed_time = 0;
}
void AndroidAI::DoMoveAndAttack()
{
state = AS_moving_and_attack;
state_elapsed_time = 0;
}

View File

@ -2,9 +2,34 @@
#include "aicomponent.h"
enum AndroidState_e
{
AS_thinking,
AS_moving,
AS_attack,
AS_moving_and_attack,
};
class Human;
class AndroidAI : public AIComponent
{
public:
AndroidState_e state = AS_thinking;
int state_elapsed_time = 0;
Human* last_hiter = nullptr;
virtual void Update(int delta_time) override;
private:
void UpdateThink();
void UpdateMove();
void UpdateAttack();
void UpdateMoveAndAttack();
void DoThink();
void DoMove();
void DoAttack();
void DoMoveAndAttack();
virtual void Update(int delta_time);
};

View File

@ -9,7 +9,7 @@ class Android : public Human
AndroidAI* ai = nullptr;
Android();
~Android();
virtual ~Android() override;
virtual void Initialize() override;
virtual void Update(int delta_time) override;
};

View File

@ -0,0 +1,5 @@
#include "precompile.h"
#include "entity.h"
#include "collider.h"

View File

@ -0,0 +1,30 @@
#pragma once
enum ColliderType_e
{
CT_None,
CT_Aabb,
CT_Circle
};
class Entity;
class ColliderComponent
{
public:
Entity* owner = nullptr;
ColliderType_e type = CT_None;
};
class AabbCollider : public ColliderComponent
{
public:
Vector2D center;
Vector2D size;
};
class CircleCollider : public ColliderComponent
{
public:
Vector2D pos;
float rad = 0.0f;
};

View File

@ -1,3 +1,12 @@
#include "precompile.h"
#include "entity.h"
Entity::~Entity()
{
for (auto& itr : colliders) {
ColliderComponent* collider = itr;
delete collider;
}
colliders.clear();
}

View File

@ -28,6 +28,7 @@ enum EntitySubType_e
};
class Room;
class ColliderComponent;
class MovementComponent;
class Entity
{
@ -40,9 +41,10 @@ class Entity
Vector2D dir;
int updated_times = 0;
MovementComponent* movement_component = nullptr;
std::list<ColliderComponent*> colliders;
Entity() {};
virtual ~Entity() {};
virtual ~Entity();
virtual void Initialize() {};
virtual void Update(int delta_time) {};
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) {};