From 8c8449fb16519e2d6c56f859480fbf70edc84cde Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 25 Jul 2024 10:16:57 +0200 Subject: [PATCH] - [NEW] Cat's Life --- data/templates.txt | 12 ++++++++++++ source/actor.cpp | 15 ++++++++++++++- source/actor.h | 2 ++ source/m_catslife.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ source/m_catslife.h | 10 ++++++++++ source/m_gameover.cpp | 3 +-- source/m_gameover.h | 5 +---- source/main.cpp | 23 +++++++++++++++++++--- source/room.cpp | 2 ++ source/room.h | 1 + 10 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 source/m_catslife.cpp create mode 100644 source/m_catslife.h diff --git a/data/templates.txt b/data/templates.txt index e42e576..2bcb5ab 100644 --- a/data/templates.txt +++ b/data/templates.txt @@ -209,3 +209,15 @@ actor{ flags: ANIMATED movement: CW } + +actor{ + name: GAT-NEGRE + bmp: gat.gif + bmp-rect: 0 0 24 26 + bmp-offset: 0 32 + pos: 32 32 0 + size: 8 8 8 + anim-wait: 2 + flags: ANIMATED + movement: CW +} diff --git a/source/actor.cpp b/source/actor.cpp index ac68920..232b71d 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -24,7 +24,7 @@ namespace actor static bool room_changed = false; int brilli_brilli=0; draw::surface *brilli; - + int current_tag = 0; void resetTag() @@ -1567,10 +1567,12 @@ namespace actor int partsCollected = 0; bool roomVisited[MAX_ROOMS]; int livesLost = 0; + int catsLifeOdds = 5; void reset() { partsCollected = livesLost = 0; + catsLifeOdds = 5; for (int i=0; i + +namespace modules +{ + namespace catslife + { + actor::actor_t *gat = nullptr; + + void init() + { + if (gat == nullptr) gat = actor::createFromTemplate("GAT-NEGRE"); + } + + bool loop() + { + if (input::keyPressed(SDL_SCANCODE_SPACE)) { + return false; + } + + draw::cls(2); + draw::color(1); + draw::swapcol(1, WHITE); + actor::update(gat, false); + actor::drawAt(gat, 150, 130); + + draw::print2("THE POOL", 16, 3, TEAL, FONT_ZOOM_VERTICAL); + + draw::print2("CAT'S LIFE", 15, 9, YELLOW, FONT_ZOOM_VERTICAL); + + 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_catslife.h b/source/m_catslife.h new file mode 100644 index 0000000..6898741 --- /dev/null +++ b/source/m_catslife.h @@ -0,0 +1,10 @@ +#pragma once + +namespace modules +{ + namespace catslife + { + void init(); + bool loop(); + } +} diff --git a/source/m_gameover.cpp b/source/m_gameover.cpp index dd01b21..875f09a 100644 --- a/source/m_gameover.cpp +++ b/source/m_gameover.cpp @@ -12,7 +12,6 @@ namespace modules namespace gameover { actor::actor_t *heroi = nullptr; - int selected_option = GAMEOVER_CONTINUAR; void init() { @@ -20,7 +19,7 @@ namespace modules heroi->flags = FLAG_ANIMATED; } - int loop() + bool loop() { if (input::keyPressed(SDL_SCANCODE_SPACE)) { return false; diff --git a/source/m_gameover.h b/source/m_gameover.h index 6dc945c..8914985 100644 --- a/source/m_gameover.h +++ b/source/m_gameover.h @@ -4,10 +4,7 @@ namespace modules { namespace gameover { - #define GAMEOVER_CONTINUAR 0 - #define GAMEOVER_EIXIR 1 - void init(); - int loop(); + bool loop(); } } diff --git a/source/main.cpp b/source/main.cpp index 0c66a8f..58d4383 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -8,11 +8,15 @@ #include "config.h" #include +#include "actor.h" +#include "room.h" + #include "m_game.h" #include "m_menu.h" #include "m_logo.h" #include "m_ingame.h" #include "m_gameover.h" +#include "m_catslife.h" #include "m_menu_tecles.h" #include "m_menu_audio.h" @@ -21,8 +25,9 @@ #define M_GAME 2 #define M_INGAME 3 #define M_GAMEOVER 4 -#define M_MENU_TECLES 5 -#define M_MENU_AUDIO 6 +#define M_CATSLIFE 5 +#define M_MENU_TECLES 6 +#define M_MENU_AUDIO 7 int current_module = M_LOGO; int zoom = 3; @@ -124,7 +129,11 @@ bool game::loop() modules::ingame::init(); current_module = M_INGAME; } } else if (option==GAME_DEAD) { - modules::gameover::init(); current_module = M_GAMEOVER; + if (actor::stats::catsLife()) { + modules::catslife::init(); current_module = M_CATSLIFE; + } else { + modules::gameover::init(); current_module = M_GAMEOVER; + } } } break; @@ -140,6 +149,14 @@ bool game::loop() modules::menu::init(); current_module = M_MENU; } break; + case M_CATSLIFE: + if (!modules::catslife::loop()) { + actor::hero::init(false); + actor::hero::setLives(1); + room::reload(); + current_module = M_GAME; + } + 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 20241d8..1857db7 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -121,6 +121,8 @@ namespace room } //void load(int x, int y, int8_t xp, int8_t xn, int8_t yp, int8_t yn, uint8_t col, uint8_t floor, uint8_t walls, uint8_t door, uint8_t walldoor) + void reload() { load(current_room); } + void load(int room, const int door) { if (room > MAX_ROOMS || room < 0) { diff --git a/source/room.h b/source/room.h index c247a50..7a51ea1 100644 --- a/source/room.h +++ b/source/room.h @@ -21,6 +21,7 @@ namespace room { void init(); void load(int room, const int door=-1); + void reload(); //void load(int x, int y, int8_t xp, int8_t xn, int8_t yp, int8_t yn, uint8_t col, uint8_t floor, uint8_t walls, uint8_t door, uint8_t doorwall); void update(); void draw();