feat(entities): derivar collision_radius del shape + scale/collision_factor al YAML
This commit is contained in:
1 parent
da8eab330d
commit
866a057704
12 files changed
+149
-104
No files matched your search
@@ -26,18 +26,22 @@ Ship::Ship(Rendering::Renderer* renderer, PlayerConfig config, const char* shape
|
||||
config_(std::move(config)) {
|
||||
brightness_ = Defaults::Brightness::NAU;
|
||||
|
||||
body_.setMass(config_.physics.mass);
|
||||
body_.radius = config_.physics.collision_radius;
|
||||
body_.restitution = config_.physics.restitution;
|
||||
body_.linear_damping = config_.physics.linear_damping;
|
||||
body_.angular_damping = config_.physics.angular_damping;
|
||||
|
||||
// El shape pot venir del YAML o ser overridden (ex: P2 amb "ship2.shp").
|
||||
const std::string SHAPE_PATH = (shape_override != nullptr) ? shape_override : config_.shape.path;
|
||||
shape_ = Graphics::ShapeLoader::load(SHAPE_PATH);
|
||||
if (!shape_ || !shape_->isValid()) {
|
||||
std::cerr << "[Ship] Error: no se ha podido cargar " << SHAPE_PATH << '\n';
|
||||
}
|
||||
|
||||
// Radi de col·lisió derivat del cercle circumscrit de la shape * scale * collision_factor.
|
||||
const float BOUNDING = (shape_ != nullptr) ? shape_->getBoundingRadius() : 0.0F;
|
||||
collision_radius_ = BOUNDING * config_.shape.scale * config_.shape.collision_factor;
|
||||
|
||||
body_.setMass(config_.physics.mass);
|
||||
body_.radius = collision_radius_;
|
||||
body_.restitution = config_.physics.restitution;
|
||||
body_.linear_damping = config_.physics.linear_damping;
|
||||
body_.angular_damping = config_.physics.angular_damping;
|
||||
}
|
||||
|
||||
void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) {
|
||||
@@ -144,10 +148,11 @@ void Ship::draw() const {
|
||||
return;
|
||||
}
|
||||
|
||||
// Efecto visual de empuje: escala proporcional a la velocidad.
|
||||
// Efecte visual d'empenta (modulador sobre l'escala base del YAML).
|
||||
const float SPEED = getSpeed();
|
||||
const float VISUAL_PUSH = SPEED / config_.visual_thrust.push_divisor;
|
||||
const float SCALE = 1.0F + (VISUAL_PUSH / config_.visual_thrust.scale_divisor);
|
||||
const float THRUST_MODULATOR = 1.0F + (VISUAL_PUSH / config_.visual_thrust.scale_divisor);
|
||||
const float SCALE = config_.shape.scale * THRUST_MODULATOR;
|
||||
|
||||
// Parpelleig daurat mentre està ferida: alterna color normal ↔ color hurt.
|
||||
SDL_Color color = config_.colors.normal;
|
||||
|
||||
Reference in new issue
Block a user