1
This commit is contained in:
parent
529ca37af4
commit
714e755a96
@ -27,65 +27,11 @@ void Bullet::Initialize()
|
||||
|
||||
void Bullet::Update(int delta_time)
|
||||
{
|
||||
pos = pos + dir * gun_meta->i->bullet_speed() / 20.0f;
|
||||
float distance = (pos - born_pos).Norm();
|
||||
if (room->OverBorder(pos, gun_meta->i->bullet_rad())) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
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 0
|
||||
if (hum != player && !hum->dead) {
|
||||
#ifdef RAY_DETECTION
|
||||
RayDetectionUpdate();
|
||||
#else
|
||||
if (hum != player && !hum->dead &&
|
||||
(hum->team_id == 0 || player->team_id != hum->team_id)) {
|
||||
FrameDetectionUpdate();
|
||||
#endif
|
||||
if (TestCollision(hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entity* entity : grid->entity_list) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Obstacle:
|
||||
case ET_Building:
|
||||
{
|
||||
if (TestCollision(entity)) {
|
||||
objects.insert(entity);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
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 ||
|
||||
(IsBomb() && meta->i->_inventory_slot() != 4 && distance >= fly_distance)
|
||||
) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
deleted = true;
|
||||
if (!objects.empty()) {
|
||||
OnHit(objects);
|
||||
}
|
||||
room->RemoveObjectLater(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Bullet::RecalcSelfCollider()
|
||||
@ -99,6 +45,13 @@ void Bullet::RecalcSelfCollider()
|
||||
self_collider_->rad = gun_meta->i->bullet_rad();
|
||||
}
|
||||
|
||||
#ifdef RAY_DETECTION
|
||||
void Bullet::RayDetection()
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void Bullet::OnHit(std::set<Entity*>& objects)
|
||||
{
|
||||
for (auto& target : objects) {
|
||||
@ -231,3 +184,111 @@ bool Bullet::IsBomb()
|
||||
meta->i->_inventory_slot() == 5 ||
|
||||
meta->i->_inventory_slot() == 6;
|
||||
}
|
||||
|
||||
#ifdef RAY_DETECTION
|
||||
void Bullet::RayDetectionUpdate()
|
||||
{
|
||||
pos = pos + dir * gun_meta->i->bullet_speed() / (float)SERVER_FRAME_RATE;
|
||||
float distance = (pos - born_pos).Norm();
|
||||
if (room->OverBorder(pos, gun_meta->i->bullet_rad())) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
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 != player && !hum->dead &&
|
||||
(hum->team_id == 0 || player->team_id != hum->team_id)) {
|
||||
if (TestCollision(hum)) {
|
||||
objects.insert(hum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
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 ||
|
||||
(IsBomb() && meta->i->_inventory_slot() != 4 && distance >= fly_distance)
|
||||
) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
deleted = true;
|
||||
if (!objects.empty()) {
|
||||
OnHit(objects);
|
||||
}
|
||||
room->RemoveObjectLater(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Bullet::FrameDetectionUpdate()
|
||||
{
|
||||
pos = pos + dir * gun_meta->i->bullet_speed() / (float)SERVER_FRAME_RATE;
|
||||
float distance = (pos - born_pos).Norm();
|
||||
if (room->OverBorder(pos, gun_meta->i->bullet_rad())) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Entity* entity : grid->entity_list) {
|
||||
switch (entity->entity_type) {
|
||||
case ET_Obstacle:
|
||||
case ET_Building:
|
||||
{
|
||||
if (TestCollision(entity)) {
|
||||
objects.insert(entity);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
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 ||
|
||||
(IsBomb() && meta->i->_inventory_slot() != 4 && distance >= fly_distance)
|
||||
) {
|
||||
if (IsBomb()) {
|
||||
ProcBomb();
|
||||
} else {
|
||||
deleted = true;
|
||||
if (!objects.empty()) {
|
||||
OnHit(objects);
|
||||
}
|
||||
room->RemoveObjectLater(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,29 @@ class Bullet : public Entity
|
||||
Vector2D born_pos;
|
||||
Vector2D born_dir;
|
||||
float fly_distance = 0.0f;
|
||||
#ifdef RAY_DETECTION
|
||||
float target_distance = 0.0f;
|
||||
Vector2D target_point;
|
||||
#endif
|
||||
|
||||
Bullet();
|
||||
virtual ~Bullet() override;
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(int delta_time) override;
|
||||
void RecalcSelfCollider();
|
||||
#ifdef RAY_DETECTION
|
||||
void RayDetection();
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
void OnHit(std::set<Entity*>& objects);
|
||||
void ProcBomb();
|
||||
bool IsBomb();
|
||||
#ifdef RAY_DETECTION
|
||||
void RayDetectionUpdate();
|
||||
#endif
|
||||
void FrameDetectionUpdate();
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user