delta-time: game_logo.cpp
delta-time: smart_sprite.cpp
This commit is contained in:
@@ -45,6 +45,7 @@ void GameLogo::init() {
|
||||
arcade_edition_status_ = Status::DISABLED;
|
||||
shake_.init(1, 2, 8, XP);
|
||||
zoom_ = 3.0F * ZOOM_FACTOR;
|
||||
post_finished_time_accumulator_ = 0.0f;
|
||||
|
||||
// Inicializa el bitmap de 'Coffee'
|
||||
coffee_sprite_->setPosX(XP);
|
||||
@@ -112,13 +113,20 @@ void GameLogo::render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
// Actualiza la lógica de la clase (frame-based)
|
||||
void GameLogo::update() {
|
||||
updateCoffeeCrisis();
|
||||
updateArcadeEdition();
|
||||
updatePostFinishedCounter();
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase (time-based)
|
||||
void GameLogo::update(float deltaTime) {
|
||||
updateCoffeeCrisis(deltaTime);
|
||||
updateArcadeEdition(deltaTime);
|
||||
updatePostFinishedCounter(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::updateCoffeeCrisis() {
|
||||
switch (coffee_crisis_status_) {
|
||||
case Status::MOVING:
|
||||
@@ -135,6 +143,22 @@ void GameLogo::updateCoffeeCrisis() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updateCoffeeCrisis(float deltaTime) {
|
||||
switch (coffee_crisis_status_) {
|
||||
case Status::MOVING:
|
||||
handleCoffeeCrisisMoving(deltaTime);
|
||||
break;
|
||||
case Status::SHAKING:
|
||||
handleCoffeeCrisisShaking(deltaTime);
|
||||
break;
|
||||
case Status::FINISHED:
|
||||
handleCoffeeCrisisFinished(deltaTime);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updateArcadeEdition() {
|
||||
switch (arcade_edition_status_) {
|
||||
case Status::MOVING:
|
||||
@@ -148,6 +172,19 @@ void GameLogo::updateArcadeEdition() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updateArcadeEdition(float deltaTime) {
|
||||
switch (arcade_edition_status_) {
|
||||
case Status::MOVING:
|
||||
handleArcadeEditionMoving(deltaTime);
|
||||
break;
|
||||
case Status::SHAKING:
|
||||
handleArcadeEditionShaking(deltaTime);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisMoving() {
|
||||
coffee_sprite_->update();
|
||||
crisis_sprite_->update();
|
||||
@@ -158,6 +195,16 @@ void GameLogo::handleCoffeeCrisisMoving() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisMoving(float deltaTime) {
|
||||
coffee_sprite_->update(deltaTime);
|
||||
crisis_sprite_->update(deltaTime);
|
||||
|
||||
if (coffee_sprite_->hasFinished() && crisis_sprite_->hasFinished()) {
|
||||
coffee_crisis_status_ = Status::SHAKING;
|
||||
playTitleEffects();
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisShaking() {
|
||||
if (shake_.remaining > 0) {
|
||||
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get());
|
||||
@@ -168,10 +215,24 @@ void GameLogo::handleCoffeeCrisisShaking() {
|
||||
updateDustSprites();
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisShaking(float deltaTime) {
|
||||
if (shake_.remaining > 0) {
|
||||
processShakeEffect(coffee_sprite_.get(), crisis_sprite_.get(), deltaTime);
|
||||
} else {
|
||||
finishCoffeeCrisisShaking();
|
||||
}
|
||||
|
||||
updateDustSprites(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisFinished() {
|
||||
updateDustSprites();
|
||||
}
|
||||
|
||||
void GameLogo::handleCoffeeCrisisFinished(float deltaTime) {
|
||||
updateDustSprites(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionMoving() {
|
||||
zoom_ -= 0.1F * ZOOM_FACTOR;
|
||||
arcade_edition_sprite_->setZoom(zoom_);
|
||||
@@ -181,6 +242,16 @@ void GameLogo::handleArcadeEditionMoving() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionMoving(float deltaTime) {
|
||||
// Convertir 0.1F * ZOOM_FACTOR por frame a por segundo (asumiendo 60fps)
|
||||
zoom_ -= (0.1F * ZOOM_FACTOR * 60.0F) * deltaTime;
|
||||
arcade_edition_sprite_->setZoom(zoom_);
|
||||
|
||||
if (zoom_ <= 1.0F) {
|
||||
finishArcadeEditionMoving();
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionShaking() {
|
||||
if (shake_.remaining > 0) {
|
||||
processArcadeEditionShake();
|
||||
@@ -190,6 +261,15 @@ void GameLogo::handleArcadeEditionShaking() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::handleArcadeEditionShaking(float deltaTime) {
|
||||
if (shake_.remaining > 0) {
|
||||
processArcadeEditionShake(deltaTime);
|
||||
} else {
|
||||
arcade_edition_sprite_->setX(shake_.origin);
|
||||
arcade_edition_status_ = Status::FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite) {
|
||||
if (shake_.counter > 0) {
|
||||
shake_.counter--;
|
||||
@@ -204,6 +284,23 @@ void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* seco
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime) {
|
||||
// Convertir delay (frames) a tiempo: delay frames = delay/60 segundos a 60fps
|
||||
float delayTime = static_cast<float>(shake_.delay) / 60.0f;
|
||||
|
||||
shake_.time_accumulator += deltaTime;
|
||||
|
||||
if (shake_.time_accumulator >= delayTime) {
|
||||
shake_.time_accumulator -= delayTime;
|
||||
const auto DISPLACEMENT = calculateShakeDisplacement();
|
||||
primary_sprite->setPosX(shake_.origin + DISPLACEMENT);
|
||||
if (secondary_sprite != nullptr) {
|
||||
secondary_sprite->setPosX(shake_.origin + DISPLACEMENT + 15);
|
||||
}
|
||||
shake_.remaining--;
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::processArcadeEditionShake() {
|
||||
if (shake_.counter > 0) {
|
||||
shake_.counter--;
|
||||
@@ -215,6 +312,20 @@ void GameLogo::processArcadeEditionShake() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::processArcadeEditionShake(float deltaTime) {
|
||||
// Convertir delay (frames) a tiempo: delay frames = delay/60 segundos a 60fps
|
||||
float delayTime = static_cast<float>(shake_.delay) / 60.0f;
|
||||
|
||||
shake_.time_accumulator += deltaTime;
|
||||
|
||||
if (shake_.time_accumulator >= delayTime) {
|
||||
shake_.time_accumulator -= delayTime;
|
||||
const auto DISPLACEMENT = calculateShakeDisplacement();
|
||||
arcade_edition_sprite_->setX(shake_.origin + DISPLACEMENT);
|
||||
shake_.remaining--;
|
||||
}
|
||||
}
|
||||
|
||||
auto GameLogo::calculateShakeDisplacement() const -> int {
|
||||
return shake_.remaining % 2 == 0 ? shake_.desp * (-1) : shake_.desp;
|
||||
}
|
||||
@@ -245,6 +356,11 @@ void GameLogo::updateDustSprites() {
|
||||
dust_left_sprite_->update();
|
||||
}
|
||||
|
||||
void GameLogo::updateDustSprites(float deltaTime) {
|
||||
dust_right_sprite_->update(deltaTime);
|
||||
dust_left_sprite_->update(deltaTime);
|
||||
}
|
||||
|
||||
void GameLogo::updatePostFinishedCounter() {
|
||||
if (coffee_crisis_status_ == Status::FINISHED &&
|
||||
arcade_edition_status_ == Status::FINISHED &&
|
||||
@@ -253,6 +369,23 @@ void GameLogo::updatePostFinishedCounter() {
|
||||
}
|
||||
}
|
||||
|
||||
void GameLogo::updatePostFinishedCounter(float deltaTime) {
|
||||
if (coffee_crisis_status_ == Status::FINISHED &&
|
||||
arcade_edition_status_ == Status::FINISHED &&
|
||||
post_finished_counter_ > 0) {
|
||||
|
||||
// Convertir 1 frame a tiempo: 1 frame = 1/60 segundos a 60fps
|
||||
float frameTime = 1.0f / 60.0f;
|
||||
|
||||
post_finished_time_accumulator_ += deltaTime;
|
||||
|
||||
if (post_finished_time_accumulator_ >= frameTime) {
|
||||
post_finished_time_accumulator_ -= frameTime;
|
||||
--post_finished_counter_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Activa la clase
|
||||
void GameLogo::enable() {
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user