Empezando a trabajar con los logros

This commit is contained in:
2022-12-29 09:09:36 +01:00
parent 8959b7bcce
commit a2f1efd2a6
9 changed files with 107 additions and 21 deletions

View File

@@ -2,7 +2,7 @@ executable = jaildoctors_dilemma
source = source/*.cpp source/common/*.cpp
appName = JailDoctor's Dilemma
releaseFolder = jdd_release
version = v1.07
version = v1.08
# Release names
windowsRelease = $(executable)-$(version)-win32-x64.zip

View File

@@ -1,4 +1,4 @@
# JailDoctor's Dilemma (v1.07)
# JailDoctor's Dilemma (v1.08)
JailDoc es un Jailer. A los Jailers les gusta empezar proyectos. A nadie le gusta terminarlos. Los Jailers viven en la Jail. A la Jail va uno a empezar proyectos. A la Jail va uno a enseñar sus proyectos. A la Jail va uno a aprender como empezar nuevos proyectos. A la Jail va uno a ayudar a sus compañeros a que empiecen nuevos proyectos.

View File

@@ -23,11 +23,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.7</string>
<string>1.0.8</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.7</string>
<string>1.0.8</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSMinimumSystemVersion</key>

View File

@@ -1,13 +1,64 @@
#include "cheevos.h"
// Constructor
Cheevos::Cheevos(options_t *options)
Cheevos::Cheevos(Screen *screen, options_t *options)
{
// Copia la dirección de los objetos
this->options = options;
this->screen = screen;
// Inicializa los logros
init();
}
// Destructor
Cheevos::~Cheevos()
{
cheevos.clear();
}
// Inicializa los logros
void Cheevos::init()
{
cheevos_t c;
c.completed = false;
c.id = 1;
c.caption = "SALTA";
cheevos.push_back(c);
c.id = 2;
c.caption = "OBTEN 3 ITEMS";
cheevos.push_back(c);
}
// Busca un logro por id y devuelve el indice
int Cheevos::findCheevo(int id)
{
for (int i = 0; i < (int)cheevos.size(); ++i)
{
if (cheevos[i].id == id)
{
return i;
}
}
return -1;
}
// Desbloquea un logro
void Cheevos::unlockCheevo(int id)
{
const int index = findCheevo(id);
if (index == -1)
{
return;
}
if (!cheevos[index].completed)
{
cheevos[index].completed = true;
screen->showNotification(cheevos[index].caption);
}
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/screen.h"
#include "common/utils.h"
#include <string>
#include <vector>
@@ -7,21 +8,38 @@
#ifndef CHEEVOS_H
#define CHEEVOS_H
struct cheevos_t
{
int id; // Identificador del logro
std::string caption; // Texto que describe el logro
bool completed; // Indica si se ha obtenido el logro
};
class Cheevos
{
private:
// Punteros y objetos
options_t *options;
Screen *screen; // Objeto encargado de dibujar en pantalla
options_t *options; // Puntero a las opciones del juego
// Variables
std::vector<cheevos_t> cheevos; // Listado de logros
// Inicializa los logros
void init();
// Busca un logro por id y devuelve el indice
int findCheevo(int id);
public:
// Constructor
Cheevos(options_t *options);
Cheevos(Screen *screen, options_t *options);
// Destructor
~Cheevos();
// Desbloquea un logro
void unlockCheevo(int id);
};
#endif

View File

@@ -383,9 +383,9 @@ void Screen::renderNotifications()
return;
}
//SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
notify->render();
//SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
}
// Establece el tamaño de las notificaciones

View File

@@ -19,7 +19,7 @@ Director::Director(int argc, char *argv[])
section->subsection = SUBSECTION_LOGO_TO_INTRO;
#ifdef DEBUG
section->name = SECTION_PROG_LOGO;
section->name = SECTION_PROG_GAME;
#endif
// Crea e inicializa las opciones del programa

View File

@@ -4,13 +4,6 @@
// Constructor
Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug)
{
// Inicia algunas variables
board.iniClock = SDL_GetTicks();
currentRoom = "03.room";
const int x = 25;
const int y = 13;
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
// Copia los punteros
this->resource = resource;
this->renderer = renderer;
@@ -21,14 +14,22 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
this->options = options;
this->section = section;
// Inicia algunas variables
board.iniClock = SDL_GetTicks();
#ifdef DEBUG
currentRoom = "01.room";
const int x1 = 25;
const int y1 = 13;
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
currentRoom = "03.room";
const int x = 25;
const int y = 13;
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
#else
currentRoom = "03.room";
const int x = 25;
const int y = 13;
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
#endif
// Crea los objetos
cheevos = new Cheevos(screen, options);
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
itemTracker = new ItemTracker();
roomTracker = new RoomTracker();
@@ -89,6 +90,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
Game::~Game()
{
// Libera la memoria de los objetos
delete cheevos;
delete scoreboard;
delete itemTracker;
delete roomTracker;
@@ -257,6 +259,7 @@ void Game::update()
checkGameOver();
checkEndGame();
checkRestoringJail();
checkSomeCheevos();
scoreboard->update();
input->update();
@@ -672,4 +675,13 @@ void Game::fillRoomNameTexture()
// Deja el renderizador por defecto
SDL_SetRenderTarget(renderer, nullptr);
}
// Comprueba algunos logros
void Game::checkSomeCheevos()
{
if (board.items == 1)
{
cheevos->unlockCheevo(2);
}
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <SDL2/SDL.h>
#include "cheevos.h"
#include "common/animatedsprite.h"
#include "common/asset.h"
#include "common/debug.h"
@@ -37,6 +38,7 @@ private:
Input *input; // Objeto pata gestionar la entrada
Text *text; // Objeto para los textos del juego
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
Cheevos *cheevos; // Objeto encargado de gestionar los logros del juego
Resource *resource; // Objeto con los recursos
Debug *debug; // Objeto para gestionar la información de debug
options_t *options; // Puntero a las opciones del juego
@@ -138,6 +140,9 @@ private:
// Pone el nombre de la habitación en la textura
void fillRoomNameTexture();
// Comprueba algunos logros
void checkSomeCheevos();
public:
// Constructor
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, section_t *section, Debug *debug);