bf83f161b0
Tres tareas de pulido para cerrar la Fase 1 por completo: #pragma once uniforme: - sdl_manager.hpp y game_scene.hpp pasan de #ifndef/#define guards a #pragma once. Los archivos externos (stb_vorbis.h, fkyaml_node.hpp) se mantienen intactos (codigo de terceros). Variables locales y parametros restantes (catalan -> ingles): - fitxer -> file, moviment -> movement, inici -> start - comptador -> counter, escalada -> scaled - missatges -> messages, llista -> list - alçada -> height, amplada -> width, llargada -> length - origen -> origin, distancia -> distance, valor -> value, desti -> target - neteja -> clear, presenta -> present (SDLManager) - total_enemics -> total_enemies, configurar -> configure, iniciar -> start Comentarios catalan -> castellano: - Cabeceras de fichero actualizadas con nombres nuevos (escena_joc.hpp -> game_scene.hpp, etc.) - Palabras tecnicas: trasllacio->traslacion, col-lisio->colision, inicialitzacio->inicializacion, posicio->posicion, rotacio->rotacion, velocitat->velocidad, acceleracio->aceleracion, explosio->explosion, renderitzat->renderizado, calcul->calculo, transicio->transicion, comprovacio->comprobacion, substitucio->sustitucion, utilitzacio->utilizacion, opcio->opcion, configuracio->configuracion, funcio->funcion, distancia, animacio->animacion - Determinantes y conectores: aquest->este, aquesta->esta, amb->con, sense->sin, pero->pero, mai->nunca, nomes->solo, tambe->tambien, sempre->siempre, ja->ya, mateix->mismo, vegada->vez, dintre->dentro, fora->fuera, dreta->derecha, esquerra->izquierda, sortir->salir, sortida->salida, petit->pequeno, gran->grande, nou->nuevo, vell->viejo, molt->mucho, els->los, les->las, totes les->todas las, d'->de, com->como, quan->cuando, mentre->mientras, despres->despues, abans->antes, durant->durante, fins->hasta, encara->aun, llavors->entonces, aixi->asi, perque->porque - Sustantivos: classe->clase, metode->metodo, parametre->parametro, versio->version, entitat->entidad, joc->juego, nivell->nivel, enemic->enemigo, naus->naves, bales->balas, fitxer->archivo, pentagon->pentagono, pun- tuacio->puntuacion, flotant->flotante, titol->titulo, objectiu->objetivo, mostra->muestra, tipus->tipo Strings literales preservados en valenciano segun decision del usuario: el texto del HUD del juego (puntuaciones, mensajes en pantalla, archivo de config) se mantiene en valenciano original. 70 fitxers tocats, +1117 / -1123. Compila i enllaca. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
128 lines
3.7 KiB
C++
128 lines
3.7 KiB
C++
// bullet.cpp - Implementació de projectils de la ship
|
||
// © 1999 Visente i Sergi (versión Pascal)
|
||
// © 2025 Port a C++20 con SDL3
|
||
|
||
#include "game/entities/bullet.hpp"
|
||
|
||
#include <algorithm>
|
||
#include <cmath>
|
||
#include <cstdint>
|
||
#include <iostream>
|
||
|
||
#include "core/audio/audio.hpp"
|
||
#include "core/defaults.hpp"
|
||
#include "core/entities/entity.hpp"
|
||
#include "core/graphics/shape_loader.hpp"
|
||
#include "core/rendering/shape_renderer.hpp"
|
||
#include "core/types.hpp"
|
||
#include "game/constants.hpp"
|
||
|
||
Bullet::Bullet(SDL_Renderer* renderer)
|
||
: Entity(renderer),
|
||
velocity_(0.0F),
|
||
esta_(false),
|
||
owner_id_(0),
|
||
grace_timer_(0.0F) {
|
||
// [NUEVO] Brightness específic per balas
|
||
brightness_ = Defaults::Brightness::BALA;
|
||
|
||
// [NUEVO] Carregar shape compartida desde file
|
||
shape_ = Graphics::ShapeLoader::load("bullet.shp");
|
||
|
||
if (!shape_ || !shape_->isValid()) {
|
||
std::cerr << "[Bullet] Error: no s'ha pogut load bullet.shp" << '\n';
|
||
}
|
||
}
|
||
|
||
void Bullet::init() {
|
||
// Inicialment inactiva
|
||
esta_ = false;
|
||
center_ = {.x = 0.0F, .y = 0.0F};
|
||
angle_ = 0.0F;
|
||
velocity_ = 0.0F;
|
||
grace_timer_ = 0.0F;
|
||
}
|
||
|
||
void Bullet::disparar(const Vec2& position, float angle, uint8_t owner_id) {
|
||
// Activar bullet i posicionar-la a la ship
|
||
// Basat en joc_asteroides.cpp línies 188-200
|
||
|
||
// Activar bullet
|
||
esta_ = true;
|
||
|
||
// Posición inicial = centro de la ship
|
||
center_.x = position.x;
|
||
center_.y = position.y;
|
||
|
||
// Angle = angle de la ship (dispara en la direcció que apunta)
|
||
angle_ = angle;
|
||
|
||
// Almacenar propietario (0=P1, 1=P2)
|
||
owner_id_ = owner_id;
|
||
|
||
// Velocidad alta (el juego Pascal original usava 7 px/frame)
|
||
// 7 px/frame × 20 FPS = 140 px/s
|
||
velocity_ = 140.0F;
|
||
|
||
// Activar grace period (prevents instant self-collision)
|
||
grace_timer_ = Defaults::Game::BULLET_GRACE_PERIOD;
|
||
|
||
// Reproducir sonido de disparo láser
|
||
Audio::get()->playSound(Defaults::Sound::LASER, Audio::Group::GAME);
|
||
}
|
||
|
||
void Bullet::update(float delta_time) {
|
||
if (esta_) {
|
||
// Decrementar grace timer
|
||
if (grace_timer_ > 0.0F) {
|
||
grace_timer_ -= delta_time;
|
||
grace_timer_ = std::max(grace_timer_, 0.0F);
|
||
}
|
||
|
||
mou(delta_time);
|
||
}
|
||
}
|
||
|
||
void Bullet::draw() const {
|
||
if (esta_ && shape_) {
|
||
// [NUEVO] Usar render_shape en lloc de rota_pol
|
||
// Les balas roten segons l'angle de trajectòria
|
||
Rendering::render_shape(renderer_, shape_, center_, angle_, 1.0F, 1.0F, brightness_);
|
||
}
|
||
}
|
||
|
||
void Bullet::mou(float delta_time) {
|
||
// Moviment rectilini de la bullet
|
||
// Basat en el codi Pascal original: procedure mou_bales
|
||
// Copiat EXACTAMENT de joc_asteroides.cpp línies 396-419
|
||
|
||
// Calcular nueva posición (movement polar time-based)
|
||
// velocity ya está en px/s (140 px/s), solo necesario multiplicar per delta_time
|
||
float velocitat_efectiva = velocity_ * delta_time;
|
||
|
||
// Calcular desplaçament (angle-PI/2 perquè angle=0 apunta amunt)
|
||
float dy = velocitat_efectiva * std::sin(angle_ - (Constants::PI / 2.0F));
|
||
float dx = velocitat_efectiva * std::cos(angle_ - (Constants::PI / 2.0F));
|
||
|
||
// Acumulació directa con precisió subpíxel
|
||
center_.y += dy;
|
||
center_.x += dx;
|
||
|
||
// Desactivar si surt de la zona de juego (no rebota como los ORNIs)
|
||
// CORRECCIÓ: Usar límits segurs con radi de la bullet
|
||
float min_x;
|
||
float max_x;
|
||
float min_y;
|
||
float max_y;
|
||
Constants::obtenir_limits_zona_segurs(Defaults::Entities::BULLET_RADIUS,
|
||
min_x,
|
||
max_x,
|
||
min_y,
|
||
max_y);
|
||
|
||
if (center_.x < min_x || center_.x > max_x ||
|
||
center_.y < min_y || center_.y > max_y) {
|
||
esta_ = false;
|
||
}
|
||
}
|