1
This commit is contained in:
parent
06c3a6cd80
commit
8eec4e7b55
@ -22,23 +22,62 @@ Bullet::~Bullet()
|
||||
void Bullet::Initialize()
|
||||
{
|
||||
Entity::Initialize();
|
||||
RecalcSelfCollider();
|
||||
}
|
||||
|
||||
void Bullet::Update(int delta_time)
|
||||
{
|
||||
MapServiceUpdate();
|
||||
}
|
||||
|
||||
void Bullet::RecalcSelfCollider()
|
||||
{
|
||||
if (!self_collider_) {
|
||||
self_collider_ = new CircleCollider();
|
||||
self_collider_->owner = this;
|
||||
AddCollider(self_collider_);
|
||||
if (dead) {
|
||||
return;
|
||||
}
|
||||
pos = pos + dir * meta->i->bullet_speed() / (float)SERVER_FRAME_RATE;
|
||||
float distance = (pos - born_pos).Norm();
|
||||
if (room->OverBorder(pos, meta->i->bullet_rad())) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
}
|
||||
PostAttack();
|
||||
room->RemoveObjectLater(this);
|
||||
} else {
|
||||
room->grid_service.MoveBullet(this);
|
||||
CircleCollider bullet_collider;
|
||||
bullet_collider.owner = this;
|
||||
bullet_collider.rad = meta->i->bullet_rad();
|
||||
std::set<Entity*> objects;
|
||||
for (auto& grid : grid_list) {
|
||||
for (Human* hum: grid->human_list) {
|
||||
if (hum != master && !hum->dead &&
|
||||
(hum->team_id == 0 || master->team_id != hum->team_id)) {
|
||||
if (hum->TestCollision(&bullet_collider)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
{
|
||||
std::set<ColliderComponent*> colliders;
|
||||
room->map_service.GetColliders(pos.x, pos.y, colliders);
|
||||
for (ColliderComponent* collider : colliders) {
|
||||
if (collider->Intersect(&bullet_collider)) {
|
||||
objects.insert(collider->owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
float bullet_range = meta->i->range();
|
||||
if (!objects.empty() || distance > bullet_range ||
|
||||
(IsBomb() && distance >= fly_distance)
|
||||
) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
deleted = true;
|
||||
if (!objects.empty()) {
|
||||
OnHit(objects);
|
||||
}
|
||||
}
|
||||
PostAttack();
|
||||
room->RemoveObjectLater(this);
|
||||
}
|
||||
}
|
||||
self_collider_->pos = a8::Vec2();
|
||||
self_collider_->rad = meta->i->bullet_rad();
|
||||
}
|
||||
|
||||
void Bullet::OnHit(std::set<Entity*>& objects)
|
||||
@ -107,20 +146,22 @@ void Bullet::OnHit(std::set<Entity*>& objects)
|
||||
|
||||
void Bullet::ProcBomb()
|
||||
{
|
||||
self_collider_->rad = meta->i->explosion_range();
|
||||
CircleCollider collider;
|
||||
collider.owner = this;
|
||||
collider.rad = meta->i->explosion_range();
|
||||
|
||||
std::set<Entity*> objects;
|
||||
for (auto& grid : grid_list) {
|
||||
for (Human* hum: grid->human_list) {
|
||||
if (TestCollision(hum)) {
|
||||
if (hum->TestCollision(&collider)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
for (Entity* entity : grid->entity_list) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Obstacle:
|
||||
case ET_Building:
|
||||
{
|
||||
if (TestCollision(entity)) {
|
||||
if (entity->TestCollision(&collider)) {
|
||||
objects.insert(entity);
|
||||
}
|
||||
}
|
||||
@ -139,59 +180,6 @@ bool Bullet::IsBomb()
|
||||
return false;
|
||||
}
|
||||
|
||||
void Bullet::MapServiceUpdate()
|
||||
{
|
||||
if (dead) {
|
||||
return;
|
||||
}
|
||||
pos = pos + dir * meta->i->bullet_speed() / (float)SERVER_FRAME_RATE;
|
||||
float distance = (pos - born_pos).Norm();
|
||||
if (room->OverBorder(pos, meta->i->bullet_rad())) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
}
|
||||
PostAttack();
|
||||
room->RemoveObjectLater(this);
|
||||
} else {
|
||||
room->grid_service.MoveBullet(this);
|
||||
std::set<Entity*> objects;
|
||||
for (auto& grid : grid_list) {
|
||||
for (Human* hum: grid->human_list) {
|
||||
if (hum != master && !hum->dead &&
|
||||
(hum->team_id == 0 || master->team_id != hum->team_id)) {
|
||||
if (TestCollision(hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
{
|
||||
std::set<ColliderComponent*> colliders;
|
||||
room->map_service.GetColliders(pos.x, pos.y, colliders);
|
||||
for (ColliderComponent* collider : colliders) {
|
||||
if (TestCollision(collider)) {
|
||||
objects.insert(collider->owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
float bullet_range = meta->i->range();
|
||||
if (!objects.empty() || distance > bullet_range ||
|
||||
(IsBomb() && distance >= fly_distance)
|
||||
) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
deleted = true;
|
||||
if (!objects.empty()) {
|
||||
OnHit(objects);
|
||||
}
|
||||
}
|
||||
PostAttack();
|
||||
room->RemoveObjectLater(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Bullet::PostAttack()
|
||||
{
|
||||
dead = true;
|
||||
@ -282,4 +270,3 @@ void Bullet::ProcMissible(const a8::XParams& param)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,15 +4,10 @@
|
||||
|
||||
namespace MetaData
|
||||
{
|
||||
struct Player;
|
||||
struct Equip;
|
||||
struct Skill;
|
||||
}
|
||||
|
||||
class Human;
|
||||
class Obstacle;
|
||||
class CircleCollider;
|
||||
class MovementComponent;
|
||||
class Bullet : public Entity
|
||||
{
|
||||
public:
|
||||
@ -28,7 +23,6 @@ class Bullet : public Entity
|
||||
virtual ~Bullet() override;
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(int delta_time) override;
|
||||
void RecalcSelfCollider();
|
||||
|
||||
static void ProcMissible(const a8::XParams& param);
|
||||
|
||||
@ -37,9 +31,5 @@ class Bullet : public Entity
|
||||
void OnHit(std::set<Entity*>& objects);
|
||||
void ProcBomb();
|
||||
bool IsBomb();
|
||||
void MapServiceUpdate();
|
||||
void PostAttack();
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
};
|
||||
|
@ -9,7 +9,6 @@ namespace cs
|
||||
}
|
||||
|
||||
class Room;
|
||||
class Obstacle;
|
||||
class ColliderComponent;
|
||||
class AabbCollider;
|
||||
class CircleCollider;
|
||||
|
Loading…
x
Reference in New Issue
Block a user