diff --git a/src/EnemyPool.cpp b/src/EnemyPool.cpp index 5f68566..fcd13ad 100644 --- a/src/EnemyPool.cpp +++ b/src/EnemyPool.cpp @@ -45,7 +45,7 @@ void EnemyPool::reset() lastShootTime_ = nc::TimeStamp::now(); } -void EnemyPool::update(float interval) +void EnemyPool::update(float frameTime) { // Bounding box of alive enemies xMin_ = nc::theApplication().width(); @@ -80,12 +80,12 @@ void EnemyPool::update(float interval) { case MOVE_RIGHT: { - enemy.moveX(roundf(interval * horizontalSpeed_)); + enemy.moveX(roundf(frameTime * horizontalSpeed_)); break; } case MOVE_LEFT: { - enemy.moveX(-roundf(interval * horizontalSpeed_)); + enemy.moveX(-roundf(frameTime * horizontalSpeed_)); break; } case MOVE_DOWNRIGHT: diff --git a/src/EnemyPool.h b/src/EnemyPool.h index 5fff5bb..b31c6cf 100644 --- a/src/EnemyPool.h +++ b/src/EnemyPool.h @@ -22,7 +22,7 @@ class EnemyPool void reset(); /// Updates positions, transitions states and calculates the bounding box - void update(float interval); + void update(float frameTime); /*! \note This is the only drawing method that contains logic to use more than a single sprite for pool entities */ void draw(); diff --git a/src/Game.cpp b/src/Game.cpp index b84a7cc..5cb0deb 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -41,7 +41,7 @@ Game::Game() Game::~Game() = default; -void Game::update(float interval) +void Game::update(float frameTime) { switch (state_) { @@ -65,17 +65,17 @@ void Game::update(float interval) screenString_.format("Score: %u - Lives: %u", player_->score(), player_->lives()); screenText_->setString(screenString_); - bombPool_->updateBombs(interval); + bombPool_->updateBombs(frameTime); bombPool_->draw(); - enemyPool_->update(interval); + enemyPool_->update(frameTime); enemyPool_->draw(); - rocketPool_->updateRockets(interval); + rocketPool_->updateRockets(frameTime); rocketPool_->draw(); if (playerMovement_ == PlayerMovement::RIGHT) - player_->move(interval); + player_->move(frameTime); else if (playerMovement_ == PlayerMovement::LEFT) - player_->move(-interval); + player_->move(-frameTime); bool rocketEnemyCollision = CollisionManager::performCollisions(rocketPool_.get(), enemyPool_.get()); bool bombPlayerCollision = CollisionManager::performCollisions(player_.get(), bombPool_.get()); diff --git a/src/Game.h b/src/Game.h index 1f892de..da592af 100644 --- a/src/Game.h +++ b/src/Game.h @@ -47,7 +47,7 @@ class Game Game(); ~Game(); - void update(float interval); + void update(float frameTime); inline void reset() { state_ = GameState::START; } void togglePause(); diff --git a/src/Player.cpp b/src/Player.cpp index dfa23eb..e03ee3b 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -12,9 +12,9 @@ Player::Player(ProjectilePool *rocketPool, nc::Texture *playerTexture) reset(); } -void Player::move(float interval) +void Player::move(float frameTime) { - sprite_.moveX(roundf(interval * Conf::PlayerSpeed)); + sprite_.moveX(roundf(frameTime * Conf::PlayerSpeed)); // Clamping to window horizontal borders if (sprite_.position().x < 0.0f) diff --git a/src/Player.h b/src/Player.h index 6dd91a4..c1189e5 100644 --- a/src/Player.h +++ b/src/Player.h @@ -17,7 +17,7 @@ class Player Player(ProjectilePool *rocketPool, nc::Texture *playerTexture); /// Move the player by an amount specified by the time passed since last frame - void move(float interval); + void move(float frameTime); void shoot(); inline unsigned int lives() const { return lives_; } diff --git a/src/ProjectilePool.cpp b/src/ProjectilePool.cpp index f260874..797a1ca 100644 --- a/src/ProjectilePool.cpp +++ b/src/ProjectilePool.cpp @@ -21,23 +21,23 @@ bool ProjectilePool::shoot(float x, float y) return (projectile != nullptr); } -void ProjectilePool::updateBombs(float interval) +void ProjectilePool::updateBombs(float frameTime) { // Traverse the array backwards to release sprites for (int i = projectiles_.acquiredSize() - 1; i >= 0; i--) { - projectiles_[i].moveY(-roundf(interval * Conf::BombSpeed)); + projectiles_[i].moveY(-roundf(frameTime * Conf::BombSpeed)); if (projectiles_[i].position().y + projectiles_.spriteHeight() * 0.5f < 0.0f) projectiles_.release(i); } } -void ProjectilePool::updateRockets(float interval) +void ProjectilePool::updateRockets(float frameTime) { // Traverse the array backwards to release sprites for (int i = projectiles_.acquiredSize() - 1; i >= 0; i--) { - projectiles_[i].moveY(roundf(interval * Conf::RocketSpeed)); + projectiles_[i].moveY(roundf(frameTime * Conf::RocketSpeed)); if (projectiles_[i].position().y - projectiles_.spriteHeight() * 0.5f > nc::theApplication().height()) projectiles_.release(i); } diff --git a/src/ProjectilePool.h b/src/ProjectilePool.h index df376db..4518f87 100644 --- a/src/ProjectilePool.h +++ b/src/ProjectilePool.h @@ -17,9 +17,9 @@ class ProjectilePool bool shoot(float x, float y); /// Updates positions and returns to the pool a bomb that goes beyond the bottom of the window - void updateBombs(float interval); + void updateBombs(float frameTime); /// Updates positions and returns to the pool a rocket that goes beyond the top of the window - void updateRockets(float interval); + void updateRockets(float frameTime); void draw(); void reset(); diff --git a/src/invaders.cpp b/src/invaders.cpp index c3b58e6..41b669a 100644 --- a/src/invaders.cpp +++ b/src/invaders.cpp @@ -59,8 +59,8 @@ void MyEventHandler::onFrameStart() else if (axisValue < -nc::IInputManager::LeftStickDeadZone) game_->movePlayer(Game::PlayerMovement::LEFT); - const float interval = nc::theApplication().interval(); - game_->update(interval); + const float frameTime = nc::theApplication().frameTime(); + game_->update(frameTime); } #ifdef __ANDROID__