[DOC:29/10/2025] la surface ara se pillarà del .ANI

Tots els arxius .ani i .room retocats per a adequarse als canvis.
This commit is contained in:
2025-10-29 14:22:36 +01:00
parent 95dd6b4f70
commit 70d6cbfaf8
134 changed files with 133 additions and 620 deletions

View File

@@ -8,6 +8,7 @@
#include <utility>
#include "core/rendering/surface.hpp" // Para Surface
#include "core/resources/resource.hpp" // Para Resource
#include "utils/utils.hpp" // Para printWithDots
// Carga las animaciones en un vector(Animations) desde un fichero
@@ -31,6 +32,25 @@ auto loadAnimationsFromFile(const std::string& file_path) -> Animations {
return buffer;
}
// Constructor
SurfaceAnimatedSprite::SurfaceAnimatedSprite(const std::string& file_path)
: SurfaceMovingSprite() {
// Carga las animaciones
if (!file_path.empty()) {
Animations v = loadAnimationsFromFile(file_path);
setAnimations(v);
}
}
// Constructor
SurfaceAnimatedSprite::SurfaceAnimatedSprite(const Animations& animations)
: SurfaceMovingSprite() {
if (!animations.empty()) {
setAnimations(animations);
}
}
// Constructor
SurfaceAnimatedSprite::SurfaceAnimatedSprite(std::shared_ptr<Surface> surface, const std::string& file_path)
: SurfaceMovingSprite(std::move(surface)) {
@@ -197,20 +217,26 @@ void SurfaceAnimatedSprite::resetAnimation() {
}
// Helper: Parsea los parámetros de configuración globales (frame_width, frame_height)
auto parseGlobalParameter(const std::string& line, float& frame_width, float& frame_height) -> bool {
auto parseGlobalParameter(const std::string& line, std::shared_ptr<Surface>& surface, float& frame_width, float& frame_height) -> bool {
size_t pos = line.find('=');
if (pos == std::string::npos) {
return false;
}
std::string key = line.substr(0, pos);
int value = std::stoi(line.substr(pos + 1));
if (key == "tileSetFile") {
std::string value = line.substr(pos + 1);
surface = Resource::get()->getSurface(value);
return true;
}
if (key == "frame_width") {
int value = std::stoi(line.substr(pos + 1));
frame_width = value;
return true;
}
if (key == "frame_height") {
int value = std::stoi(line.substr(pos + 1));
frame_height = value;
return true;
}
@@ -295,11 +321,13 @@ void SurfaceAnimatedSprite::setAnimations(const Animations& animations) {
// Parsea el fichero para buscar variables y valores
if (line != "[animation]") {
if (parseGlobalParameter(line, frame_width, frame_height)) {
frames_per_row = surface_->getWidth() / frame_width;
const int W = surface_->getWidth() / frame_width;
const int H = surface_->getHeight() / frame_height;
max_tiles = W * H;
if (parseGlobalParameter(line, surface_, frame_width, frame_height)) {
if (surface_) {
frames_per_row = surface_->getWidth() / frame_width;
const int W = surface_->getWidth() / frame_width;
const int H = surface_->getHeight() / frame_height;
max_tiles = W * H;
}
}
}

View File

@@ -49,6 +49,12 @@ class SurfaceAnimatedSprite : public SurfaceMovingSprite {
public:
// Constructor
// [DOC:29/10/2025] la surface ara se pillarà del .ANI.
// Necesite constructors que no requereixquen la surface al crear el objecte,
// ja que la trau al llegir el arxiu. Aixó afecta a totes les classes base...
SurfaceAnimatedSprite(const std::string& file_path);
SurfaceAnimatedSprite(const Animations& animations);
// [/DOC]
SurfaceAnimatedSprite(std::shared_ptr<Surface> surface, const std::string& file_path);
SurfaceAnimatedSprite(std::shared_ptr<Surface> surface, const Animations& animations);
explicit SurfaceAnimatedSprite(std::shared_ptr<Surface> surface)

View File

@@ -17,6 +17,12 @@ SurfaceMovingSprite::SurfaceMovingSprite(std::shared_ptr<Surface> surface, SDL_F
y_(pos.y),
flip_(SDL_FLIP_NONE) { SurfaceSprite::pos_ = pos; }
SurfaceMovingSprite::SurfaceMovingSprite()
: SurfaceSprite(),
x_(0.0F),
y_(0.0F),
flip_(SDL_FLIP_NONE) { SurfaceSprite::clear(); }
SurfaceMovingSprite::SurfaceMovingSprite(std::shared_ptr<Surface> surface)
: SurfaceSprite(std::move(surface)),
x_(0.0F),

View File

@@ -32,6 +32,7 @@ class SurfaceMovingSprite : public SurfaceSprite {
// Constructor
SurfaceMovingSprite(std::shared_ptr<Surface> surface, SDL_FRect pos, SDL_FlipMode flip);
SurfaceMovingSprite(std::shared_ptr<Surface> surface, SDL_FRect pos);
explicit SurfaceMovingSprite();
explicit SurfaceMovingSprite(std::shared_ptr<Surface> surface);
// Destructor

View File

@@ -15,6 +15,10 @@ SurfaceSprite::SurfaceSprite(std::shared_ptr<Surface> surface, SDL_FRect rect)
pos_(rect),
clip_((SDL_FRect){0, 0, pos_.w, pos_.h}) {}
SurfaceSprite::SurfaceSprite()
: pos_((SDL_FRect){0.0F, 0.0F, 0.0F, 0.0F}),
clip_(pos_) {}
SurfaceSprite::SurfaceSprite(std::shared_ptr<Surface> surface)
: surface_(std::move(std::move(surface))),
pos_((SDL_FRect){0.0F, 0.0F, surface_->getWidth(), surface_->getHeight()}),

View File

@@ -18,6 +18,7 @@ class SurfaceSprite {
// Constructor
SurfaceSprite(std::shared_ptr<Surface>, float x, float y, float w, float h);
SurfaceSprite(std::shared_ptr<Surface>, SDL_FRect rect);
SurfaceSprite();
explicit SurfaceSprite(std::shared_ptr<Surface>);
// Destructor

View File

@@ -10,7 +10,8 @@
// Constructor
Enemy::Enemy(const Data& enemy)
: sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface(enemy.surface_path), Resource::get()->getAnimations(enemy.animation_path))),
// [DOC:29/10/2025] la surface ara se pillarà del .ANI
: sprite_(std::make_shared<SurfaceAnimatedSprite>(/*Resource::get()->getSurface(enemy.surface_path), */Resource::get()->getAnimations(enemy.animation_path))),
color_string_(enemy.color),
x1_(enemy.x1),
x2_(enemy.x2),

View File

@@ -10,7 +10,9 @@ class Enemy {
public:
// --- Estructuras ---
struct Data {
/* [DOC:29/10/2025] la surface ara se pillarà del .ANI
std::string surface_path{}; // Ruta al fichero con la textura
[/DOC] */
std::string animation_path{}; // Ruta al fichero con la animación
/* [DOC:29/10/2025] w i h ja no fan falta, se pilla del .ANI
int w = 0; // Anchura del enemigo

View File

@@ -18,7 +18,7 @@
Player::Player(const Data& player)
: room_(player.room) {
// Inicializa algunas variables
initSprite(player.texture_path, player.animations_path);
initSprite(/*player.texture_path, */player.animations_path);
setColor();
applySpawnValues(player.spawn_data);
placeSprite();
@@ -641,11 +641,11 @@ void Player::applySpawnValues(const SpawnData& spawn) {
}
// Inicializa el sprite del jugador
void Player::initSprite(const std::string& surface_path, const std::string& animations_path) {
auto surface = Resource::get()->getSurface(surface_path);
void Player::initSprite(/*const std::string& surface_path, */const std::string& animations_path) {
//auto surface = Resource::get()->getSurface(surface_path);
auto animations = Resource::get()->getAnimations(animations_path);
sprite_ = std::make_shared<SurfaceAnimatedSprite>(surface, animations);
sprite_ = std::make_shared<SurfaceAnimatedSprite>(/*surface, */animations);
sprite_->setWidth(WIDTH);
sprite_->setHeight(HEIGHT);
sprite_->setCurrentAnimation("walk");

View File

@@ -47,7 +47,7 @@ class Player {
struct Data {
SpawnData spawn_data{};
std::string texture_path{};
//std::string texture_path{};
std::string animations_path{};
std::shared_ptr<Room> room = nullptr;
@@ -57,7 +57,7 @@ class Player {
// Constructor con parámetros
Data(SpawnData spawn_data, std::string texture_path, std::string animations_path, std::shared_ptr<Room> room)
: spawn_data(std::move(spawn_data)),
texture_path(std::move(texture_path)),
//texture_path(std::move(texture_path)),
animations_path(std::move(animations_path)),
room(std::move(room)) {}
};
@@ -147,7 +147,7 @@ class Player {
void initSounds(); // Inicializa los sonidos de salto y caida
void placeSprite() { sprite_->setPos(x_, y_); } // Coloca el sprite en la posición del jugador
void applySpawnValues(const SpawnData& spawn); // Aplica los valores de spawn al jugador
void initSprite(const std::string& surface_path, const std::string& animations_path); // Inicializa el sprite del jugador
void initSprite(/*const std::string& surface_path, */const std::string& animations_path); // Inicializa el sprite del jugador
#ifdef _DEBUG
// --- Variables ---

View File

@@ -861,9 +861,9 @@ auto Room::setEnemy(Enemy::Data* enemy, const std::string& key, const std::strin
bool success = true;
try {
if (key == "tileSetFile") {
/*if (key == "tileSetFile") {
enemy->surface_path = value;
} else if (key == "animation") {
} else */if (key == "animation") {
enemy->animation_path = value;
/* [DOC:29/10/2025] w i h ja no fan falta, se pilla del .ANI
} else if (key == "width") {

View File

@@ -21,9 +21,9 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
constexpr float SURFACE_HEIGHT = 6.0F * TILE_SIZE;
// Reserva memoria para los objetos
auto player_texture = Resource::get()->getSurface(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.gif" : "player.gif");
//auto player_texture = Resource::get()->getSurface(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.gif" : "player.gif");
auto player_animations = Resource::get()->getAnimations(Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.ani" : "player.ani");
player_sprite_ = std::make_shared<SurfaceAnimatedSprite>(player_texture, player_animations);
player_sprite_ = std::make_shared<SurfaceAnimatedSprite>(player_animations);
player_sprite_->setCurrentAnimation("walk_menu");
surface_ = std::make_shared<Surface>(SURFACE_WIDTH, SURFACE_HEIGHT);

View File

@@ -18,7 +18,7 @@
// Constructor
Credits::Credits()
: shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface("shine.gif"), Resource::get()->getAnimations("shine.ani"))) {
: shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("shine.ani"))) {
// Inicializa variables
SceneManager::current = SceneManager::Scene::CREDITS;
SceneManager::options = SceneManager::Options::NONE;

View File

@@ -275,7 +275,7 @@ void Ending2::loadSprites() {
// Carga los sprites
for (const auto& file : sprite_list_) {
sprites_.emplace_back(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface(file + ".gif"), Resource::get()->getAnimations(file + ".ani")));
sprites_.emplace_back(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations(file + ".ani")));
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
}

View File

@@ -20,8 +20,8 @@
// Constructor
GameOver::GameOver()
: player_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface("player_game_over.gif"), Resource::get()->getAnimations("player_game_over.ani"))),
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface("tv.gif"), Resource::get()->getAnimations("tv.ani"))),
: player_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("player_game_over.ani"))),
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("tv.ani"))),
delta_timer_(std::make_shared<DeltaTimer>()) {
SceneManager::current = SceneManager::Scene::GAME_OVER;
SceneManager::options = SceneManager::Options::NONE;