feat(entities): migrar bullet a data/entities/bullet/bullet.yaml
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "core/physics/collision.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
#include "game/entities/bullet_config.hpp"
|
||||
#include "game/entities/enemy_config.hpp"
|
||||
|
||||
namespace Systems::Collision {
|
||||
@@ -80,7 +81,7 @@ namespace Systems::Collision {
|
||||
0.0F, // sense velocity angular heretada
|
||||
0.0F, // sense rotació visual heretada
|
||||
Defaults::Sound::HIT,
|
||||
Defaults::Palette::BULLET,
|
||||
bullet.getConfig().colors.normal,
|
||||
Defaults::Physics::Debris::TEMPS_VIDA,
|
||||
Defaults::Physics::Debris::ACCELERACIO,
|
||||
1); // sense duplicat de segments
|
||||
@@ -96,7 +97,7 @@ namespace Systems::Collision {
|
||||
continue;
|
||||
}
|
||||
for (auto& enemy : ctx.enemies) {
|
||||
if (!Physics::checkCollisionSwept(bullet.getPrevPosition(), bullet.getCenter(), Defaults::Entities::BULLET_RADIUS, enemy, AMPLIFIER)) {
|
||||
if (!Physics::checkCollisionSwept(bullet.getPrevPosition(), bullet.getCenter(), bullet.getCollisionRadius(), enemy, AMPLIFIER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -105,7 +106,7 @@ namespace Systems::Collision {
|
||||
// (m·v) multiplicat pel factor de transferència. Direcció = vector
|
||||
// velocity de la bala (cap a on viatjava).
|
||||
const Vec2 IMPULSE = bullet.getBody().velocity *
|
||||
(bullet.getBody().mass * Defaults::Physics::Bullet::IMPACT_MOMENTUM_FACTOR);
|
||||
(bullet.getBody().mass * bullet.getConfig().physics.impact_momentum_factor);
|
||||
enemy.applyImpulse(IMPULSE);
|
||||
|
||||
const uint8_t SHOOTER = bullet.getOwnerId();
|
||||
@@ -244,7 +245,7 @@ namespace Systems::Collision {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Physics::checkCollisionSwept(bullet.getPrevPosition(), bullet.getCenter(), Defaults::Entities::BULLET_RADIUS, ctx.ships[player_id], AMPLIFIER)) {
|
||||
if (!Physics::checkCollisionSwept(bullet.getPrevPosition(), bullet.getCenter(), bullet.getCollisionRadius(), ctx.ships[player_id], AMPLIFIER)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -253,7 +254,7 @@ namespace Systems::Collision {
|
||||
// de la bala a la nau ABANS de on_player_hit perquè tocado()
|
||||
// captura la velocitat per als debris (si no, queden quiets).
|
||||
const Vec2 BULLET_IMPULSE = bullet.getBody().velocity *
|
||||
(bullet.getBody().mass * Defaults::Physics::Bullet::IMPACT_MOMENTUM_FACTOR);
|
||||
(bullet.getBody().mass * bullet.getConfig().physics.impact_momentum_factor);
|
||||
ctx.ships[player_id].getBody().applyImpulse(BULLET_IMPULSE);
|
||||
ctx.on_player_hit(player_id);
|
||||
ctx.lives_per_player[BULLET_OWNER]++;
|
||||
@@ -280,12 +281,12 @@ namespace Systems::Collision {
|
||||
float min_y;
|
||||
float max_y;
|
||||
Constants::getPlayAreaBounds(min_x, max_x, min_y, max_y);
|
||||
constexpr float R = Defaults::Entities::BULLET_RADIUS;
|
||||
|
||||
for (auto& bullet : bullets) {
|
||||
if (!bullet.isActive()) {
|
||||
continue;
|
||||
}
|
||||
const float R = bullet.getCollisionRadius();
|
||||
const Vec2& pos = bullet.getCenter();
|
||||
if (pos.x < min_x + R || pos.x > max_x - R ||
|
||||
pos.y < min_y + R || pos.y > max_y - R) {
|
||||
|
||||
Reference in New Issue
Block a user