- [NEW] Pantalla de game over
- [NEW] Stats
This commit is contained in:
@@ -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; i<MAX_ROOMS; ++i) roomVisited[i] = false;
|
||||
}
|
||||
|
||||
void collectPart() { partsCollected++; }
|
||||
void visitRoom(int room) {roomVisited[room] = true; }
|
||||
void loseLive() { livesLost++; }
|
||||
|
||||
int getNumPartsCollected() { return partsCollected; }
|
||||
int getRoomsVisited()
|
||||
{
|
||||
int roomsVisited = 0;
|
||||
for (int i=0; i<MAX_ROOMS; ++i) if (roomVisited[i]) roomsVisited++;
|
||||
return roomsVisited;
|
||||
}
|
||||
|
||||
int getLivesLost() { return livesLost; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -178,11 +178,13 @@ namespace actor
|
||||
|
||||
namespace hero
|
||||
{
|
||||
|
||||
void init(const bool complete=true);
|
||||
int getLives();
|
||||
void setLives(int value);
|
||||
|
||||
void die();
|
||||
bool isDead();
|
||||
|
||||
bool giveBooster(char *booster);
|
||||
void collectBooster(int booster, int id);
|
||||
bool wasBoosterCollected(int id);
|
||||
@@ -208,4 +210,17 @@ namespace actor
|
||||
void move(int *x, int *y, int *z);
|
||||
void setFirstPos();
|
||||
}
|
||||
|
||||
namespace stats
|
||||
{
|
||||
void reset();
|
||||
|
||||
void collectPart();
|
||||
void visitRoom(int room);
|
||||
void loseLive();
|
||||
|
||||
int getNumPartsCollected();
|
||||
int getRoomsVisited();
|
||||
int getLivesLost();
|
||||
}
|
||||
}
|
||||
@@ -254,14 +254,16 @@ namespace modules
|
||||
if ( input::keyDown(SDL_SCANCODE_PAGEUP) /*&& selected->pos.z<max.z*/ ) { selected->pos.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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
56
source/m_gameover.cpp
Normal file
56
source/m_gameover.cpp
Normal file
@@ -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 <SDL2/SDL.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
source/m_gameover.h
Normal file
13
source/m_gameover.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace modules
|
||||
{
|
||||
namespace gameover
|
||||
{
|
||||
#define GAMEOVER_CONTINUAR 0
|
||||
#define GAMEOVER_EIXIR 1
|
||||
|
||||
void init();
|
||||
int loop();
|
||||
}
|
||||
}
|
||||
@@ -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,12 +115,17 @@ bool game::loop()
|
||||
}
|
||||
break;
|
||||
case M_GAME:
|
||||
if (!modules::game::loop()) {
|
||||
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;
|
||||
case M_INGAME:
|
||||
@@ -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;
|
||||
|
||||
@@ -258,6 +258,7 @@ namespace room
|
||||
}
|
||||
|
||||
current_room = room;
|
||||
actor::stats::visitRoom(room);
|
||||
refresh();
|
||||
|
||||
actor::select(actor::find(selected_actor_name));
|
||||
@@ -283,11 +284,15 @@ namespace room
|
||||
if (num_color_cycles==0) {
|
||||
actor::actor_t * hero = actor::find("HERO");
|
||||
if (!hero) {
|
||||
if (actor::hero::getLives()==0) {
|
||||
actor::hero::die();
|
||||
} else {
|
||||
actor::hero::init(false);
|
||||
load(current_room);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draw::pushSource();
|
||||
draw::swapcol(1, color_schemes[color][0]);
|
||||
|
||||
Reference in New Issue
Block a user