time-based: migrada escena Intro (dual-API a MovingSprite/SmartSprite/Writer, constants a 60Hz)
This commit is contained in:
@@ -38,6 +38,18 @@ void SmartSprite::update() {
|
||||
}
|
||||
}
|
||||
|
||||
// Time-based: la velocitat i acceleració són en px/s i px/s^2; el temps de
|
||||
// permanència després d'arribar al destí ve donat per setRemainingTime().
|
||||
void SmartSprite::update(float dt_s) {
|
||||
if (enabled_) {
|
||||
// NOLINTNEXTLINE(bugprone-parent-virtual-call): vegeu update() per al motiu del salt
|
||||
MovingSprite::update(dt_s);
|
||||
|
||||
checkMove();
|
||||
checkFinishedTimeBased(dt_s);
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void SmartSprite::render() {
|
||||
if (enabled_) {
|
||||
@@ -56,6 +68,15 @@ void SmartSprite::setEnabledCounter(int value) {
|
||||
enabled_counter_ = value;
|
||||
}
|
||||
|
||||
// Time-based: temps de visibilitat post-arribada
|
||||
void SmartSprite::setRemainingTime(float seconds) {
|
||||
remaining_time_s_ = seconds;
|
||||
}
|
||||
|
||||
auto SmartSprite::getRemainingTime() const -> float {
|
||||
return remaining_time_s_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void SmartSprite::setDestX(int x) {
|
||||
dest_x_ = x;
|
||||
@@ -143,6 +164,19 @@ void SmartSprite::checkFinished() {
|
||||
}
|
||||
}
|
||||
|
||||
// Time-based: decrementa el temps restant cada crida si està al destí
|
||||
void SmartSprite::checkFinishedTimeBased(float dt_s) {
|
||||
on_destination_ = getPosX() == dest_x_ && getPosY() == dest_y_;
|
||||
|
||||
if (on_destination_) {
|
||||
if (remaining_time_s_ <= 0.0F) {
|
||||
finished_ = true;
|
||||
} else {
|
||||
remaining_time_s_ -= dt_s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
auto SmartSprite::isOnDestination() const -> bool {
|
||||
return on_destination_;
|
||||
|
||||
Reference in New Issue
Block a user