treballant en sistema de portes i claus
This commit is contained in:
32
source/game/entities/key.cpp
Normal file
32
source/game/entities/key.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "game/entities/key.hpp"
|
||||
|
||||
#include "core/rendering/sprite/animated_sprite.hpp" // Para AnimatedSprite
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||
|
||||
// Constructor: carga la animación, posiciona el sprite y crea el collider
|
||||
Key::Key(const Data& data)
|
||||
: sprite_(std::make_shared<AnimatedSprite>(Resource::Cache::get()->getAnimationData(data.animation_path))),
|
||||
id_(data.id) {
|
||||
sprite_->setPosX(data.x);
|
||||
sprite_->setPosY(data.y);
|
||||
sprite_->setCurrentAnimation("default");
|
||||
collider_ = sprite_->getRect();
|
||||
}
|
||||
|
||||
// Pinta la llave en pantalla
|
||||
void Key::render() {
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
// Avanza la animación de la llave
|
||||
void Key::update(float delta_time) {
|
||||
if (is_paused_) {
|
||||
return;
|
||||
}
|
||||
sprite_->animate(delta_time);
|
||||
}
|
||||
|
||||
// Posición actual (para registrar pickup en KeyTracker)
|
||||
auto Key::getPos() const -> SDL_FPoint {
|
||||
return SDL_FPoint{.x = sprite_->getX(), .y = sprite_->getY()};
|
||||
}
|
||||
Reference in New Issue
Block a user