完成机器人逻辑
This commit is contained in:
parent
7b8ecf7e39
commit
e232db9547
@ -118,7 +118,8 @@ void AndroidAI::DoMoveAndAttack()
|
||||
if (owner->updated_times % 2 == 0) {
|
||||
Human* enemy = owner->room->SearchEnemy((Human*)owner);
|
||||
if (enemy) {
|
||||
|
||||
Human* sender = (Human*)owner;
|
||||
sender->Shot(enemy->pos, 10.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
Android::Android():Human()
|
||||
{
|
||||
entity_type = ET_Player;
|
||||
entity_subtype = EST_Android;
|
||||
ai = new AndroidAI;
|
||||
ai->owner = this;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
Bullet::Bullet():Entity()
|
||||
{
|
||||
entity_type = ET_Bullet;
|
||||
}
|
||||
|
||||
Bullet::~Bullet()
|
||||
|
@ -17,7 +17,9 @@ enum EntityType_e
|
||||
ET_DeadBody = 6,
|
||||
ET_Decal = 7,
|
||||
ET_Projectile = 8,
|
||||
ET_Smoke = 9
|
||||
ET_Smoke = 9,
|
||||
|
||||
ET_Bullet = 20
|
||||
};
|
||||
|
||||
enum EntitySubType_e
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "cs_proto.pb.h"
|
||||
#include "movement.h"
|
||||
#include "metamgr.h"
|
||||
#include "room.h"
|
||||
#include "bullet.h"
|
||||
|
||||
Human::Human()
|
||||
{
|
||||
@ -55,7 +57,7 @@ void Human::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
p->set_sdmg(sdmg);
|
||||
}
|
||||
|
||||
void Human::Shot(Vector2D& target_point, float speed)
|
||||
void Human::Shot(Vector2D& target_dir, float speed)
|
||||
{
|
||||
{
|
||||
cs::MFShot* shot = frame_data.shots.Add();
|
||||
@ -68,8 +70,18 @@ void Human::Shot(Vector2D& target_point, float speed)
|
||||
cs::MFBullet* bullet = frame_data.bullets.Add();
|
||||
bullet->set_player_id(entity_uniid);
|
||||
bullet->set_bullet_id(10001);
|
||||
target_point.ToPB(bullet->mutable_pos());
|
||||
(pos - target_point).Normalize().ToPB(bullet->mutable_dir());
|
||||
pos.ToPB(bullet->mutable_pos());
|
||||
target_dir.ToPB(bullet->mutable_dir());
|
||||
bullet->set_bulletskin(10001);
|
||||
}
|
||||
{
|
||||
Bullet* bullet = new Bullet();
|
||||
bullet->player = this;
|
||||
bullet->pos = pos;
|
||||
bullet->dir = target_dir;
|
||||
bullet->born_pos = pos;
|
||||
bullet->born_dir = target_dir;
|
||||
bullet->entity_uniid = bullet->room->AllocUniid();
|
||||
room->AddBullet(bullet);
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,6 @@ class Human : public Entity
|
||||
virtual float GetSpeed() override;
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
void Shot(Vector2D& target_point, float speed);
|
||||
void Shot(Vector2D& target_dir, float speed);
|
||||
|
||||
};
|
||||
|
@ -25,6 +25,7 @@ const int F_ack = 24;
|
||||
|
||||
Player::Player()
|
||||
{
|
||||
entity_type = ET_Player;
|
||||
entity_subtype = EST_Player;
|
||||
update_msg = new cs::SMUpdate();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "android.h"
|
||||
#include "metamgr.h"
|
||||
#include "movement.h"
|
||||
#include "bullet.h"
|
||||
|
||||
const int ROOM_MAX_PLAYER_NUM = 50;
|
||||
|
||||
@ -96,3 +97,9 @@ Human* Room::SearchEnemy(Human* hum)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Room::AddBullet(Bullet* bullet)
|
||||
{
|
||||
uniid_hash_[bullet->entity_uniid] = bullet;
|
||||
moveable_hash_[bullet->entity_uniid] = bullet;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ struct RoomFrameData
|
||||
};
|
||||
|
||||
class Entity;
|
||||
class Bullet;
|
||||
class Human;
|
||||
class Player;
|
||||
class Room
|
||||
@ -40,6 +41,7 @@ public:
|
||||
void ShuaAndroid();
|
||||
bool RandomPos(Human* hum, float distance, Vector2D& out_pos);
|
||||
Human* SearchEnemy(Human* hum);
|
||||
void AddBullet(Bullet* bullet);
|
||||
|
||||
private:
|
||||
unsigned short current_uniid = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user