diff --git a/source/actor.cpp b/source/actor.cpp index c36606a..ac68920 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -720,6 +720,7 @@ namespace actor if ( (act->push & PUSH_KILL) && (act->flags & FLAG_HERO) ) { const int lives = hero::getLives()-1; hero::setLives(lives); + stats::loseLive(); // [TODO] If lives == 0 anar a la pantalla de game-over o cat's life actor_t *act = actor::find("HERO"); act = actor::replaceWithTemplate(act, "EXPLOSION"); @@ -1342,6 +1343,7 @@ namespace actor bool boosters_collected[100]; vec3_t first_pos = {0,0,0}; int first_orient = 0; + bool dead = false; void init(const bool complete) { @@ -1350,9 +1352,11 @@ namespace actor actor::setDirty(hero, true); boost_jumps = boost_steps = boost_god = 0; + dead = false; if (complete) { + stats::reset(); lives = 8; skills = SKILL_NONE; parts = PART_NONE; @@ -1374,6 +1378,16 @@ namespace actor lives = value; } + void die() + { + dead = true; + } + + bool isDead() + { + return dead; + } + const int getBoosterFromString(char *booster) { static const char *boostset_name[4] = {"RUN", "GOD", "JUMP", "LIVE"}; @@ -1510,6 +1524,7 @@ namespace actor { const int value = getPartFromString(part); parts |= value; + if (value!=0) stats::collectPart(); return value!=0; } @@ -1546,4 +1561,32 @@ namespace actor } } + + namespace stats + { + int partsCollected = 0; + bool roomVisited[MAX_ROOMS]; + int livesLost = 0; + + void reset() + { + partsCollected = livesLost = 0; + for (int i=0; ipos.zpos.z++; actor::setDirty(selected); room::editor::modify(); } } - bool loop() + int loop() { + if (actor::hero::isDead()) return GAME_DEAD; + if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { if (console::isEnabled()) console::toggle(); else - return false; + return GAME_MENU; } if (input::keyPressed(SDL_SCANCODE_TAB) || input::keyPressed(SDL_SCANCODE_GRAVE) ) console::toggle(); @@ -369,7 +371,7 @@ namespace modules { console::draw(); draw::render(); - return true; + return GAME_NONE; } @@ -752,7 +754,7 @@ namespace modules }; draw::render(); - return true; + return GAME_NONE; } } diff --git a/source/m_game.h b/source/m_game.h index c21408c..ac12af0 100644 --- a/source/m_game.h +++ b/source/m_game.h @@ -4,7 +4,11 @@ namespace modules { namespace game { + #define GAME_NONE -1 + #define GAME_MENU 0 + #define GAME_DEAD 1 + void init(); - bool loop(); + int loop(); } } diff --git a/source/m_gameover.cpp b/source/m_gameover.cpp new file mode 100644 index 0000000..dd01b21 --- /dev/null +++ b/source/m_gameover.cpp @@ -0,0 +1,56 @@ +#include "m_gameover.h" +#include "jgame.h" +#include "jinput.h" +#include "jdraw.h" +#include "actor.h" +#include "room.h" +#include "config.h" +#include + +namespace modules +{ + namespace gameover + { + actor::actor_t *heroi = nullptr; + int selected_option = GAMEOVER_CONTINUAR; + + void init() + { + if (heroi == nullptr) heroi = actor::create("HERO", {16,32,8}, {6,6,12}, "test.gif", {0,32,20,32}, {-6,38}); + heroi->flags = FLAG_ANIMATED; + } + + int loop() + { + if (input::keyPressed(SDL_SCANCODE_SPACE)) { + return false; + } + + draw::cls(2); + draw::color(1); + draw::swapcol(1, WHITE); + actor::update(heroi, false); + actor::drawAt(heroi, 150, 160); + + draw::print2("THE POOL", 16, 3, TEAL, FONT_ZOOM_VERTICAL); + + draw::print2("GAME OVER", 15, 7, YELLOW, FONT_ZOOM_VERTICAL); + + draw::print2(actor::stats::getNumPartsCollected(), 2, 11, 12, GREEN, FONT_ZOOM_NONE); + draw::print2("PARTS TROBADES", 14, 12, GREEN, FONT_ZOOM_NONE); + + draw::print2(actor::stats::getRoomsVisited(), 2, 8, 14, GREEN, FONT_ZOOM_NONE); + draw::print2("HABITACIONS VISITADES", 11, 14, GREEN, FONT_ZOOM_NONE); + + draw::print2(actor::stats::getLivesLost(), 2, 11, 16, GREEN, FONT_ZOOM_NONE); + draw::print2("VIDES PERDUDES", 14, 16, GREEN, FONT_ZOOM_NONE); + + + draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); + + draw::render(); + return true; + } + } +} + \ No newline at end of file diff --git a/source/m_gameover.h b/source/m_gameover.h new file mode 100644 index 0000000..6dc945c --- /dev/null +++ b/source/m_gameover.h @@ -0,0 +1,13 @@ +#pragma once + +namespace modules +{ + namespace gameover + { + #define GAMEOVER_CONTINUAR 0 + #define GAMEOVER_EIXIR 1 + + void init(); + int loop(); + } +} diff --git a/source/main.cpp b/source/main.cpp index d4bb320..0c66a8f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -12,6 +12,7 @@ #include "m_menu.h" #include "m_logo.h" #include "m_ingame.h" +#include "m_gameover.h" #include "m_menu_tecles.h" #include "m_menu_audio.h" @@ -19,8 +20,9 @@ #define M_MENU 1 #define M_GAME 2 #define M_INGAME 3 -#define M_MENU_TECLES 4 -#define M_MENU_AUDIO 5 +#define M_GAMEOVER 4 +#define M_MENU_TECLES 5 +#define M_MENU_AUDIO 6 int current_module = M_LOGO; int zoom = 3; @@ -113,11 +115,16 @@ bool game::loop() } break; case M_GAME: - if (!modules::game::loop()) { - if (editor::isDevMode()) { - return false; - } else { - modules::ingame::init(); current_module = M_INGAME; + option = modules::game::loop(); + if (option!=GAME_NONE) { + if (option==GAME_MENU) { + if (editor::isDevMode()) { + return false; + } else { + modules::ingame::init(); current_module = M_INGAME; + } + } else if (option==GAME_DEAD) { + modules::gameover::init(); current_module = M_GAMEOVER; } } break; @@ -128,6 +135,11 @@ bool game::loop() if (option == INGAME_CONTINUAR) { current_module = M_GAME; } } break; + case M_GAMEOVER: + if (!modules::gameover::loop()) { + modules::menu::init(); current_module = M_MENU; + } + break; case M_MENU_TECLES: if (modules::menu_tecles::loop() == MENU_TECLES_TORNAR) { modules::menu::init(); current_module = M_MENU; diff --git a/source/room.cpp b/source/room.cpp index dffb265..20241d8 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -258,6 +258,7 @@ namespace room } current_room = room; + actor::stats::visitRoom(room); refresh(); actor::select(actor::find(selected_actor_name)); @@ -283,8 +284,12 @@ namespace room if (num_color_cycles==0) { actor::actor_t * hero = actor::find("HERO"); if (!hero) { - actor::hero::init(false); - load(current_room); + if (actor::hero::getLives()==0) { + actor::hero::die(); + } else { + actor::hero::init(false); + load(current_room); + } } } }