#include "game/entities/item.hpp" #include "core/rendering/surface_sprite.hpp" // Para SSprite #include "core/resources/resource_cache.hpp" // Para Resource // Constructor Item::Item(const Data& item) : sprite_(std::make_shared(Resource::Cache::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE, ITEM_SIZE)), time_accumulator_(static_cast(item.counter) * COLOR_CHANGE_INTERVAL) { // Inicia variables sprite_->setClip((item.tile % 10) * ITEM_SIZE, (item.tile / 10) * ITEM_SIZE, ITEM_SIZE, ITEM_SIZE); collider_ = sprite_->getRect(); // Inicializa los colores color_.push_back(item.color1); color_.push_back(item.color1); color_.push_back(item.color2); color_.push_back(item.color2); } // Actualiza las variables del objeto void Item::update(float delta_time) { if (is_paused_) { return; } time_accumulator_ += delta_time; } // Pinta el objeto en pantalla void Item::render() const { // Calcula el índice de color basado en el tiempo acumulado const int INDEX = static_cast(time_accumulator_ / COLOR_CHANGE_INTERVAL) % static_cast(color_.size()); sprite_->render(1, color_.at(INDEX)); } // Obtiene su ubicación auto Item::getPos() -> SDL_FPoint { const SDL_FPoint P = {sprite_->getX(), sprite_->getY()}; return P; } // Asigna los colores del objeto void Item::setColors(Uint8 col1, Uint8 col2) { // Reinicializa el vector de colores color_.clear(); // Añade el primer color color_.push_back(col1); color_.push_back(col1); // Añade el segundo color color_.push_back(col2); color_.push_back(col2); }