granera con sarna no pica
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "item_manager.hpp"
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "game/defaults.hpp" // Para Defaults::Sound::Files
|
||||
#include "game/entities/item.hpp" // Para Item
|
||||
#include "game/options.hpp" // Para Options
|
||||
#include "item_tracker.hpp" // Para ItemTracker
|
||||
@@ -55,7 +56,7 @@ auto ItemManager::checkCollision(SDL_FRect& rect) -> bool { // NOLINT(readabili
|
||||
items_.erase(items_.begin() + i);
|
||||
|
||||
// Reproduce el sonido de pickup
|
||||
Audio::get()->playSound("item.wav", Audio::Group::GAME);
|
||||
Audio::get()->playSound(Defaults::Sound::Files::ITEM, Audio::Group::GAME);
|
||||
|
||||
// Actualiza el scoreboard y estadísticas
|
||||
data_->items++;
|
||||
|
||||
@@ -115,13 +115,6 @@ void Room::setTile(int index, int tile_value) {
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia color de fondo y redibuja el mapa (para editor)
|
||||
void Room::setBgColor(Uint8 color) {
|
||||
bg_color_ = color;
|
||||
tilemap_renderer_->setBgColor(color);
|
||||
tilemap_renderer_->redrawMap(collision_map_->getCollisionTileMap());
|
||||
}
|
||||
|
||||
// Cambia colores de items en vivo (para editor)
|
||||
void Room::setItemColors(Uint8 color1, Uint8 color2) {
|
||||
item_color1_ = color1;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/defaults.hpp" // Para Defaults::Game::Room
|
||||
#include "game/entities/enemy.hpp" // Para EnemyData
|
||||
#include "game/entities/item.hpp" // Para ItemData
|
||||
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data
|
||||
@@ -31,8 +32,8 @@ class Room {
|
||||
struct Data {
|
||||
std::string number;
|
||||
Uint8 bg_color{0};
|
||||
Uint8 item_color1{12};
|
||||
Uint8 item_color2{6};
|
||||
Uint8 item_color1{Defaults::Game::Room::ITEM_COLOR1};
|
||||
Uint8 item_color2{Defaults::Game::Room::ITEM_COLOR2};
|
||||
std::string upper_room;
|
||||
std::string lower_room;
|
||||
std::string left_room;
|
||||
@@ -61,7 +62,6 @@ class Room {
|
||||
void resetEnemyPositions(const std::vector<Enemy::Data>& enemy_data);
|
||||
auto getEnemyManager() -> EnemyManager* { return enemy_manager_.get(); }
|
||||
auto getItemManager() -> ItemManager* { return item_manager_.get(); }
|
||||
void setBgColor(Uint8 color);
|
||||
void setItemColors(Uint8 color1, Uint8 color2);
|
||||
void setTile(int index, int tile_value);
|
||||
[[nodiscard]] auto getTileSetFile() const -> const std::string& { return tile_set_file_; }
|
||||
@@ -92,8 +92,8 @@ class Room {
|
||||
|
||||
std::string number_;
|
||||
Uint8 bg_color_{0};
|
||||
Uint8 item_color1_{12};
|
||||
Uint8 item_color2_{6};
|
||||
Uint8 item_color1_{Defaults::Game::Room::ITEM_COLOR1};
|
||||
Uint8 item_color2_{Defaults::Game::Room::ITEM_COLOR2};
|
||||
std::string upper_room_;
|
||||
std::string lower_room_;
|
||||
std::string left_room_;
|
||||
|
||||
@@ -236,11 +236,6 @@ auto RoomLoader::parseEnemyData(const fkyaml::node& enemy_node) -> Enemy::Data {
|
||||
parseEnemyBoundaries(enemy_node["boundaries"], enemy);
|
||||
}
|
||||
|
||||
// Color
|
||||
if (enemy_node.contains("color")) {
|
||||
enemy.color = readColorNode(enemy_node["color"]);
|
||||
}
|
||||
|
||||
// Optional fields
|
||||
enemy.flip = enemy_node.contains("flip")
|
||||
? enemy_node["flip"].get_value_or<bool>(false)
|
||||
|
||||
@@ -62,8 +62,7 @@ void TilemapRenderer::setTile(int index, int tile_value) {
|
||||
map_surface_->fillRect(&cell, bg_color_);
|
||||
|
||||
if (tile_value > -1) {
|
||||
const bool IS_ANIMATED = (tile_value >= 18 * tile_set_width_) && (tile_value < 19 * tile_set_width_);
|
||||
if (!IS_ANIMATED) {
|
||||
if (!isAnimatedTile(tile_value)) {
|
||||
SDL_FRect clip = {.x = static_cast<float>((tile_value % tile_set_width_) * TILE_SIZE),
|
||||
.y = static_cast<float>((tile_value / tile_set_width_) * TILE_SIZE),
|
||||
.w = static_cast<float>(TILE_SIZE),
|
||||
@@ -107,11 +106,10 @@ void TilemapRenderer::fillMapTexture(const std::vector<int>& collision_tile_map)
|
||||
for (int y = 0; y < MAP_HEIGHT; ++y) {
|
||||
for (int x = 0; x < MAP_WIDTH; ++x) {
|
||||
const int INDEX = (y * MAP_WIDTH) + x;
|
||||
// Los tiles animados (fila 18 del tileset) no se pintan en la textura estática
|
||||
const bool IS_ANIMATED = (tile_map_[INDEX] >= 18 * tile_set_width_) && (tile_map_[INDEX] < 19 * tile_set_width_);
|
||||
// Los tiles animados no se pintan en la textura estática
|
||||
const bool HAS_TILE = tile_map_[INDEX] > -1;
|
||||
|
||||
if (HAS_TILE && !IS_ANIMATED) {
|
||||
if (HAS_TILE && !isAnimatedTile(tile_map_[INDEX])) {
|
||||
clip.x = (tile_map_[INDEX] % tile_set_width_) * TILE_SIZE;
|
||||
clip.y = (tile_map_[INDEX] / tile_set_width_) * TILE_SIZE;
|
||||
#ifdef _DEBUG
|
||||
@@ -145,8 +143,8 @@ void TilemapRenderer::setAnimatedTiles(const std::vector<int>& collision_tile_ma
|
||||
const int YC = (tile_map_[i] / tile_set_width_) * TILE_SIZE;
|
||||
|
||||
AnimatedTile at;
|
||||
at.sprite = std::make_shared<Sprite>(tileset_surface_, X, Y, 8, 8);
|
||||
at.sprite->setClip(XC, YC, 8, 8);
|
||||
at.sprite = std::make_shared<Sprite>(tileset_surface_, X, Y, TILE_SIZE, TILE_SIZE);
|
||||
at.sprite->setClip(XC, YC, TILE_SIZE, TILE_SIZE);
|
||||
at.x_orig = XC;
|
||||
animated_tiles_.push_back(at);
|
||||
}
|
||||
@@ -176,3 +174,7 @@ void TilemapRenderer::renderAnimatedTiles() {
|
||||
a.sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
auto TilemapRenderer::isAnimatedTile(int tile_value) const -> bool {
|
||||
return (tile_value >= ANIMATED_TILE_ROW * tile_set_width_) && (tile_value < (ANIMATED_TILE_ROW + 1) * tile_set_width_);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ class TilemapRenderer {
|
||||
|
||||
#ifdef _DEBUG
|
||||
void redrawMap(const std::vector<int>& collision_tile_map);
|
||||
void setBgColor(Uint8 color) { bg_color_ = color; }
|
||||
void setTile(int index, int tile_value);
|
||||
#endif
|
||||
|
||||
@@ -46,6 +45,9 @@ class TilemapRenderer {
|
||||
static constexpr int PLAY_AREA_HEIGHT = PlayArea::HEIGHT;
|
||||
static constexpr float CONVEYOR_FRAME_DURATION = 0.05F;
|
||||
static constexpr int COLLISION_ANIMATED = 6; // Valor del tile de conveyor en el collision tilemap
|
||||
static constexpr int ANIMATED_TILE_ROW = 18; // Fila del tileset que contiene los tiles animados
|
||||
|
||||
[[nodiscard]] auto isAnimatedTile(int tile_value) const -> bool;
|
||||
|
||||
std::vector<int> tile_map_;
|
||||
int tile_set_width_;
|
||||
|
||||
Reference in New Issue
Block a user