forked from jaildesigner-jailgames/jaildoctors_dilemma
migrat Game, Player i Item a time based
This commit is contained in:
@@ -115,42 +115,39 @@ void Game::run() {
|
||||
|
||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||
void Game::update() {
|
||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||
if (SDL_GetTicks() - ticks_ > GAME_SPEED) {
|
||||
// Actualiza el contador de ticks
|
||||
ticks_ = SDL_GetTicks();
|
||||
// Calcula el delta time
|
||||
const float DELTA_TIME = delta_timer_.tick();
|
||||
|
||||
// Comprueba el teclado
|
||||
checkInput();
|
||||
// Comprueba el teclado
|
||||
checkInput();
|
||||
|
||||
#ifdef _DEBUG
|
||||
Debug::get()->clear();
|
||||
Debug::get()->clear();
|
||||
#endif
|
||||
|
||||
// Actualiza los objetos
|
||||
room_->update();
|
||||
if (mode_ == GameMode::GAME) {
|
||||
player_->update();
|
||||
checkPlayerIsOnBorder();
|
||||
checkPlayerAndItems();
|
||||
checkPlayerAndEnemies();
|
||||
checkIfPlayerIsAlive();
|
||||
checkGameOver();
|
||||
checkEndGame();
|
||||
checkRestoringJail();
|
||||
checkSomeCheevos();
|
||||
}
|
||||
demoCheckRoomChange();
|
||||
scoreboard_->update();
|
||||
keepMusicPlaying();
|
||||
updateBlackScreen();
|
||||
|
||||
Screen::get()->update();
|
||||
|
||||
#ifdef _DEBUG
|
||||
updateDebugInfo();
|
||||
#endif
|
||||
// Actualiza los objetos
|
||||
room_->update(DELTA_TIME);
|
||||
if (mode_ == GameMode::GAME) {
|
||||
player_->update(DELTA_TIME);
|
||||
checkPlayerIsOnBorder();
|
||||
checkPlayerAndItems();
|
||||
checkPlayerAndEnemies();
|
||||
checkIfPlayerIsAlive();
|
||||
checkGameOver();
|
||||
checkEndGame();
|
||||
checkRestoringJail(DELTA_TIME);
|
||||
checkSomeCheevos();
|
||||
}
|
||||
demoCheckRoomChange(DELTA_TIME);
|
||||
scoreboard_->update();
|
||||
keepMusicPlaying();
|
||||
updateBlackScreen(DELTA_TIME);
|
||||
|
||||
Screen::get()->update(DELTA_TIME);
|
||||
|
||||
#ifdef _DEBUG
|
||||
updateDebugInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Pinta los objetos en pantalla
|
||||
@@ -336,7 +333,7 @@ void Game::checkIfPlayerIsAlive() {
|
||||
|
||||
// Comprueba si ha terminado la partida
|
||||
void Game::checkGameOver() {
|
||||
if (board_->lives < 0 && black_screen_counter_ > 17) {
|
||||
if (board_->lives < 0 && black_screen_time_ > GAME_OVER_THRESHOLD) {
|
||||
SceneManager::current = SceneManager::Scene::GAME_OVER;
|
||||
}
|
||||
}
|
||||
@@ -379,12 +376,12 @@ void Game::setBlackScreen() {
|
||||
}
|
||||
|
||||
// Actualiza las variables relativas a la pantalla en negro
|
||||
void Game::updateBlackScreen() {
|
||||
void Game::updateBlackScreen(float delta_time) {
|
||||
if (black_screen_) {
|
||||
black_screen_counter_++;
|
||||
if (black_screen_counter_ > 20) {
|
||||
black_screen_time_ += delta_time;
|
||||
if (black_screen_time_ > BLACK_SCREEN_DURATION) {
|
||||
black_screen_ = false;
|
||||
black_screen_counter_ = 0;
|
||||
black_screen_time_ = 0.0F;
|
||||
|
||||
player_->setPaused(false);
|
||||
room_->setPaused(false);
|
||||
@@ -458,20 +455,19 @@ void Game::togglePause() {
|
||||
}
|
||||
|
||||
// Da vidas al jugador cuando está en la Jail
|
||||
void Game::checkRestoringJail() {
|
||||
void Game::checkRestoringJail(float delta_time) {
|
||||
if (room_->getName() != "THE JAIL" || board_->lives == 9) {
|
||||
jail_restore_time_ = 0.0F; // Reset timer cuando no está en la Jail
|
||||
return;
|
||||
}
|
||||
|
||||
static int counter_ = 0;
|
||||
|
||||
if (!paused_) {
|
||||
counter_++;
|
||||
jail_restore_time_ += delta_time;
|
||||
}
|
||||
|
||||
// Incrementa el numero de vidas
|
||||
if (counter_ == 100) {
|
||||
counter_ = 0;
|
||||
if (jail_restore_time_ >= JAIL_RESTORE_INTERVAL) {
|
||||
jail_restore_time_ -= JAIL_RESTORE_INTERVAL; // Mantiene el excedente para precisión
|
||||
board_->lives++;
|
||||
JA_PlaySound(Resource::get()->getSound("death.wav"));
|
||||
|
||||
@@ -599,17 +595,17 @@ void Game::keepMusicPlaying() {
|
||||
// DEMO MODE: Inicializa las variables para el modo demo
|
||||
void Game::demoInit() {
|
||||
if (mode_ == GameMode::DEMO) {
|
||||
demo_ = DemoData(0, 400, 0, {"04.room", "54.room", "20.room", "09.room", "05.room", "11.room", "31.room", "44.room"});
|
||||
demo_ = DemoData(0.0F, 0, {"04.room", "54.room", "20.room", "09.room", "05.room", "11.room", "31.room", "44.room"});
|
||||
current_room_ = demo_.rooms.front();
|
||||
}
|
||||
}
|
||||
|
||||
// DEMO MODE: Comprueba si se ha de cambiar de habitación
|
||||
void Game::demoCheckRoomChange() {
|
||||
void Game::demoCheckRoomChange(float delta_time) {
|
||||
if (mode_ == GameMode::DEMO) {
|
||||
demo_.counter++;
|
||||
if (demo_.counter == demo_.room_time) {
|
||||
demo_.counter = 0;
|
||||
demo_.time_accumulator += delta_time;
|
||||
if (demo_.time_accumulator >= DEMO_ROOM_DURATION) {
|
||||
demo_.time_accumulator = 0.0F;
|
||||
demo_.room_index++;
|
||||
if (demo_.room_index == (int)demo_.rooms.size()) {
|
||||
SceneManager::current = SceneManager::Scene::LOGO;
|
||||
|
||||
Reference in New Issue
Block a user