demo.cpp a fer la mar

This commit is contained in:
2025-03-02 10:41:38 +01:00
parent 82f0992116
commit cdf0b0a694
6 changed files with 158 additions and 344 deletions

View File

@@ -1,37 +1,38 @@
#include "game.h"
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include <vector> // for vector
#include "asset.h" // for Asset
#include "cheevos.h" // for Cheevos
#include "debug.h" // for Debug
#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, GAMECANVAS_...
#include "global_events.h" // for check
#include "global_inputs.h" // for check
#include "input.h" // for Input, InputAction, REPEAT_FALSE
#include "item_tracker.h" // for ItemTracker
#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu...
#include "notifier.h" // for Notifier, NotificationText
#include "options.h" // for Options, options, Cheat, OptionsVideo
#include "resource.h" // for ResourceRoom, Resource
#include "room.h" // for Room, RoomData
#include "room_tracker.h" // for RoomTracker
#include "scoreboard.h" // for ScoreboardData, Scoreboard
#include "screen.h" // for Screen
#include "stats.h" // for Stats
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
#include "utils.h" // for Color, stringToColor, colorAreEqual
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
#include <SDL2/SDL_error.h> // for SDL_GetError
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_...
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include <vector> // for vector
#include "asset.h" // for Asset
#include "cheevos.h" // for Cheevos
#include "debug.h" // for Debug
#include "defines.h" // for BLOCK, PLAY_AREA_HEIGHT, GAMECANVAS_...
#include "global_events.h" // for check
#include "global_inputs.h" // for check
#include "input.h" // for Input, InputAction, REPEAT_FALSE
#include "item_tracker.h" // for ItemTracker
#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu...
#include "notifier.h" // for Notifier, NotificationText
#include "options.h" // for Options, options, Cheat, OptionsVideo
#include "resource.h" // for ResourceRoom, Resource
#include "room.h" // for Room, RoomData
#include "room_tracker.h" // for RoomTracker
#include "scoreboard.h" // for ScoreboardData, Scoreboard
#include "screen.h" // for Screen
#include "stats.h" // for Stats
#include "text.h" // for Text, TEXT_CENTER, TEXT_COLOR
#include "utils.h" // for Color, stringToColor, colorAreEqual
// Constructor
Game::Game()
Game::Game(GameMode mode)
: board_(std::make_shared<ScoreboardData>(0, 9, 0, true, Color(0, 0, 0), SDL_GetTicks(), options.cheats.jail_is_open == Cheat::CheatState::ENABLED)),
scoreboard_(std::make_shared<Scoreboard>(board_)),
room_tracker_(std::make_shared<RoomTracker>()),
stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))),
mode_(mode),
#ifdef DEBUG
current_room_("03.room"),
spawn_point_(PlayerSpawn(25 * BLOCK, 13 * BLOCK, 0, 0, 0, PlayerState::STANDING, SDL_FLIP_HORIZONTAL))
@@ -46,6 +47,7 @@ Game::Game()
// Crea objetos e inicializa variables
ItemTracker::init();
DEMO_init();
room_ = std::make_shared<Room>(current_room_, board_);
initPlayer(spawn_point_, room_);
initStats();
@@ -57,7 +59,7 @@ Game::Game()
Cheevos::get()->enable(!options.cheats.enabled()); // Deshabilita los logros si hay trucos activados
Cheevos::get()->clearUnobtainableState();
options.section.section = Section::GAME;
options.section.section = (mode_ == GameMode::GAME) ? Section::GAME : Section::DEMO;
options.section.subsection = Subsection::NONE;
}
@@ -108,7 +110,7 @@ void Game::run()
JA_PauseMusic();
}
while (options.section.section == Section::GAME)
while (options.section.section == Section::GAME || options.section.section == Section::DEMO)
{
update();
checkEvents();
@@ -136,15 +138,19 @@ void Game::update()
// Actualiza los objetos
room_->update();
player_->update();
checkPlayerOnBorder();
checkPlayerAndItems();
checkPlayerAndEnemies();
checkIfPlayerIsAlive();
checkGameOver();
checkEndGame();
checkRestoringJail();
checkSomeCheevos();
if (mode_ == GameMode::GAME)
{
player_->update();
checkPlayerOnBorder();
checkPlayerAndItems();
checkPlayerAndEnemies();
checkIfPlayerIsAlive();
checkGameOver();
checkEndGame();
checkRestoringJail();
checkSomeCheevos();
}
DEMO_checkRoomChange();
scoreboard_->update();
updateBlackScreen();
@@ -162,13 +168,15 @@ void Game::render()
{
// Prepara para dibujar el frame
Screen::get()->start();
// test_surface_->render(0, 0, 10, 10, 64, 64);
// Dibuja los elementos del juego en orden
room_->renderMap();
room_->renderEnemies();
room_->renderItems();
player_->render();
if (mode_ == GameMode::GAME)
{
player_->render();
}
renderRoomName();
scoreboard_->render();
renderBlackScreen();
@@ -669,4 +677,38 @@ void Game::createRoomNameTexture()
// Establece el destino de la textura
room_name_rect_ = {0, PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH, text->getCharacterSize() * 2};
}
// DEMO MODE: Inicializa las variables para el modo demo
void Game::DEMO_init()
{
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"});
current_room_ = demo_.rooms.front();
}
}
// DEMO MODE: Comprueba si se ha de cambiar de habitación
void Game::DEMO_checkRoomChange()
{
if (mode_ == GameMode::DEMO)
{
demo_.counter++;
if (demo_.counter == demo_.room_time)
{
demo_.counter = 0;
demo_.room_index++;
if (demo_.room_index == (int)demo_.rooms.size())
{
options.section.section = Section::LOGO;
options.section.subsection = Subsection::LOGO_TO_TITLE;
}
else
{
changeRoom(demo_.rooms[demo_.room_index]);
}
}
}
}