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