1
This commit is contained in:
parent
3854633a19
commit
b52ba4ee77
@ -7,6 +7,7 @@
|
||||
#include "obstacle.h"
|
||||
#include "player.h"
|
||||
#include "app.h"
|
||||
#include "movement.h"
|
||||
|
||||
Bullet::Bullet():Entity()
|
||||
{
|
||||
@ -16,6 +17,8 @@ Bullet::Bullet():Entity()
|
||||
|
||||
Bullet::~Bullet()
|
||||
{
|
||||
delete movement;
|
||||
movement = nullptr;
|
||||
--App::Instance()->perf.entity_num[ET_Bullet];
|
||||
}
|
||||
|
||||
@ -23,6 +26,8 @@ void Bullet::Initialize()
|
||||
{
|
||||
Entity::Initialize();
|
||||
RecalcSelfCollider();
|
||||
movement = new MovementComponent();
|
||||
movement->owner = this;
|
||||
}
|
||||
|
||||
void Bullet::Update(int delta_time)
|
||||
@ -194,7 +199,6 @@ bool Bullet::IsBomb()
|
||||
meta->i->_inventory_slot() == 6;
|
||||
}
|
||||
|
||||
#ifdef RAY_DETECTION
|
||||
void Bullet::RayDetectionUpdate()
|
||||
{
|
||||
pos = pos + dir * gun_meta->i->bullet_speed() / (float)SERVER_FRAME_RATE;
|
||||
@ -219,11 +223,12 @@ void Bullet::RayDetectionUpdate()
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
movement->GetCollisionObjects(objects);
|
||||
float bullet_range = gun_meta->i->range();
|
||||
if (gun_upgrade_meta && gun_upgrade_meta->attr[EA_ShotRange] > 0) {
|
||||
bullet_range += gun_upgrade_meta->attr[EA_ShotRange];
|
||||
}
|
||||
if (!objects.empty() || distance > bullet_range || distance >= target_distance ||
|
||||
if (!objects.empty() || distance > bullet_range || distance >= movement->target_distance ||
|
||||
(IsBomb() && meta->i->_inventory_slot() != 4 && distance >= fly_distance)
|
||||
) {
|
||||
if (IsBomb()) {
|
||||
@ -239,7 +244,6 @@ void Bullet::RayDetectionUpdate()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Bullet::ClearRayData()
|
||||
{
|
||||
@ -263,12 +267,8 @@ void Bullet::FrameDetectionUpdate()
|
||||
std::set<Entity*> objects;
|
||||
for (auto& grid : grid_list) {
|
||||
for (Human* hum: grid->human_list) {
|
||||
#if 0
|
||||
if (hum != player && !hum->dead) {
|
||||
#else
|
||||
if (hum != player && !hum->dead &&
|
||||
(hum->team_id == 0 || player->team_id != hum->team_id)) {
|
||||
#endif
|
||||
if (TestCollision(hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ namespace MetaData
|
||||
class Human;
|
||||
class Obstacle;
|
||||
class CircleCollider;
|
||||
class MovementComponent;
|
||||
class Bullet : public Entity
|
||||
{
|
||||
public:
|
||||
@ -23,15 +24,14 @@ class Bullet : public Entity
|
||||
Vector2D born_pos;
|
||||
Vector2D born_dir;
|
||||
float fly_distance = 0.0f;
|
||||
MovementComponent* movement = nullptr;
|
||||
|
||||
Bullet();
|
||||
virtual ~Bullet() override;
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(int delta_time) override;
|
||||
void RecalcSelfCollider();
|
||||
#ifdef RAY_DETECTION
|
||||
void RayDetection();
|
||||
#endif
|
||||
void ClearRayData();
|
||||
|
||||
private:
|
||||
@ -39,9 +39,7 @@ class Bullet : public Entity
|
||||
void OnHit(std::set<Entity*>& objects);
|
||||
void ProcBomb();
|
||||
bool IsBomb();
|
||||
#ifdef RAY_DETECTION
|
||||
void RayDetectionUpdate();
|
||||
#endif
|
||||
void FrameDetectionUpdate();
|
||||
|
||||
private:
|
||||
|
@ -0,0 +1,13 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
void MovementComponent::GetCollisionObjects(std::set<Entity*>& objects)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MovementComponent::TestCollision()
|
||||
{
|
||||
return false;
|
||||
}
|
@ -5,10 +5,10 @@ class MovementComponent
|
||||
{
|
||||
public:
|
||||
Entity* owner = nullptr;
|
||||
#ifdef RAY_DETECTION
|
||||
float target_distance = 0.0f;
|
||||
Vector2D target_point;
|
||||
std::set<Entity*> detection_objects;
|
||||
#endif
|
||||
|
||||
void GetCollisionObjects(std::set<Entity*>& objects);
|
||||
bool TestCollision();
|
||||
};
|
||||
|
@ -604,6 +604,9 @@ void Room::CreateBullet(Human* hum, Weapon* weapon,
|
||||
bullet->Initialize();
|
||||
AddObjectLater(bullet);
|
||||
grid_service.AddBullet(bullet);
|
||||
#ifdef RAY_DETECTION
|
||||
bullet->RayDetection();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Room::RemoveObjectLater(Entity* entity)
|
||||
|
Loading…
x
Reference in New Issue
Block a user