Compare commits

...

10 Commits
v1.02 ... v1.04

14 changed files with 268 additions and 142 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
.vscode
*config.txt
*stats.txt
*.DS_Store
thumbs.db
*.exe

View File

@@ -2,7 +2,7 @@ executable = jaildoctors_dilemma
source = source/*.cpp source/common/*.cpp
appName = JailDoctor's Dilemma
releaseFolder = jdd_release
version = v1.02
version = v1.04
# Release names
windowsRelease = $(executable)-$(version)-win32-x64.zip
@@ -12,8 +12,6 @@ linuxRelease = $(executable)-$(version)-linux.tar.gz
windows:
@echo off
powershell if (Test-Path data\config) {Remove-Item data\config -Recurse -Force}
powershell if (-not (Test-Path data\config)) {New-Item data\config -ItemType Directory}
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o $(executable).exe
strip -s -R .comment -R .gnu.version $(executable).exe --strip-unneeded
@@ -21,11 +19,9 @@ windows_release:
@echo off
# Remove data
powershell if (Test-Path data\config) {Remove-Item data\config -Recurse -Force}
powershell if (Test-Path $(releaseFolder)) {Remove-Item $(releaseFolder) -Recurse -Force}
# Create folders
powershell if (-not (Test-Path data\config)) {New-Item data\config -ItemType Directory}
powershell if (-not (Test-Path $(releaseFolder))) {New-Item $(releaseFolder) -ItemType Directory}
# Copy data
@@ -37,6 +33,10 @@ windows_release:
# Remove data
powershell if (Test-Path "$(releaseFolder)\data\room\map.world") {Remove-Item "$(releaseFolder)\data\room\map.world" -Recurse -Force}
powershell if (Test-Path "$(releaseFolder)\data\room\standard.tsx") {Remove-Item "$(releaseFolder)\data\room\standard.tsx" -Recurse -Force}
powershell if (Test-Path "$(releaseFolder)\data\config") {Remove-Item "$(releaseFolder)\data\config" -Recurse -Force}
# Create data
powershell if (-not (Test-Path "$(releaseFolder)\data\config")) {New-Item "$(releaseFolder)\data\config" -ItemType Directory}
# Build
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
@@ -50,13 +50,10 @@ windows_release:
powershell if (Test-Path $(releaseFolder)) {Remove-Item $(releaseFolder) -Recurse -Force}
macos:
rm -rdf data/config
mkdir -p data/config
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o $(executable)_macos
macos_release:
# Remove data and possible data
rm -rdf data/config
rm -rdf "$(releaseFolder)"
rm -rdf Frameworks
rm -f tmp.dmg
@@ -64,7 +61,6 @@ macos_release:
rm -f "$(macosAppleSiliconRelease)"
# Create folders
mkdir -p data/config
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Frameworks"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/MacOS"
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Resources"
@@ -78,10 +74,16 @@ macos_release:
# Delete data
rm -f "$(releaseFolder)/$(appName).app/Contents/Resources/data/room/map.world"
rm -f "$(releaseFolder)/$(appName).app/Contents/Resources/data/room/standard.tsx"
rm -rdf "$(releaseFolder)/$(appName).app/Contents/Resources/data/config"
# Create folders
mkdir -p "$(releaseFolder)/$(appName).app/Contents/Resources/data/config"
# Copy files
cp release/*.icns "$(releaseFolder)/$(appName).app/Contents/Resources"
cp release/Info.plist "$(releaseFolder)/$(appName).app/Contents"
cp LICENSE "$(releaseFolder)"
cp README.md "$(releaseFolder)"
# Build INTEL
clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
@@ -104,18 +106,14 @@ macos_release:
rm -rdf "$(releaseFolder)"
linux:
rm -rdf data/config
mkdir -p data/config
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o $(executable)_linux
strip -s -R .comment -R .gnu.version $(executable)_linux --strip-unneeded
linux_release:
# Remove data
rm -rdf data/config
rm -rdf $(releaseFolder)
# Create folders
mkdir -p data/config
mkdir -p $(releaseFolder)
# Copy data
@@ -126,6 +124,10 @@ linux_release:
# Delete data
rm -f "$(releaseFolder)/data/room/map.world"
rm -f "$(releaseFolder)/data/room/standard.tsx"
rm -rdf "$(releaseFolder)/data/config"
# Create folders
mkdir -p "$(releaseFolder)/data/config"
# Build
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o $(releaseFolder)/$(executable)

View File

@@ -48,9 +48,9 @@ animation=tuno.ani
width=16
height=16
x=28
y=8
y=6
vx=0
vy=0.4
vy=-0.4
x1=28
y1=2
x2=28

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.jaildoctors_dilemma_debug</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -86,6 +86,8 @@ struct options_t
palette_e palette; // Paleta de colores a usar en el juego
bool console; // Indica si ha de mostrar información por la consola de texto
cheat_t cheat; // Contiene trucos y ventajas para el juego
int rooms; // Cantidad de habitaciones visitadas
int items; // Cantidad de items obtenidos
};
// Calcula el cuadrado de la distancia entre dos puntos

View File

@@ -91,6 +91,8 @@ void Director::iniOptions()
options->cheat.invincible = false;
options->cheat.jailEnabled = false;
options->cheat.altSkin = false;
options->rooms = 0;
options->items = 0;
}
// Comprueba los parametros del programa
@@ -1039,6 +1041,7 @@ bool Director::setFileList()
// Configuración
asset->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);
asset->add(prefix + "/data/config/config.txt", t_data, false);
asset->add(prefix + "/data/config/stats.txt", t_data, false);
// Habitaciones
asset->add(prefix + "/data/room/01.room", t_room);

View File

@@ -40,6 +40,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
music = JA_LoadMusic(asset->get("game.ogg").c_str());
deathSound = JA_LoadSound(asset->get("death.wav").c_str());
stats = new Stats(asset->get("stats.txt"));
stats->addVisit(room->getName());
// Inicializa el resto de variables
ticks = 0;
@@ -70,6 +72,7 @@ Game::~Game()
delete player;
delete eventHandler;
delete text;
delete stats;
JA_DeleteMusic(music);
JA_DeleteSound(deathSound);
@@ -89,6 +92,11 @@ void Game::checkEventHandler()
break;
}
if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
{
reLoadTextures();
}
if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
{
switch (eventHandler->key.keysym.scancode)
@@ -210,7 +218,7 @@ void Game::update()
#ifdef DEBUG
debug->clear();
#endif
// Actualiza los objetos
room->update();
player->update();
@@ -329,8 +337,13 @@ bool Game::changeRoom(std::string file)
setScoreBoardColor();
if (roomTracker->addRoom(file))
{ // Incrementa el contador de habitaciones visitadas
{
// Incrementa el contador de habitaciones visitadas
board.rooms++;
options->rooms = board.rooms;
// Actualiza las estadisticas
stats->addVisit(room->getName());
}
// Pasa la nueva habitación al jugador
@@ -406,6 +419,9 @@ void Game::killPlayer()
board.lives--;
}
// Actualiza las estadisticas
stats->addDeath(room->getName());
// Destruye la habitacion y el jugador
delete room;
delete this->player;

View File

@@ -17,6 +17,7 @@
#include "room_tracker.h"
#include "room.h"
#include "scoreboard.h"
#include "stats.h"
#ifndef GAME_H
#define GAME_H
@@ -39,6 +40,7 @@ private:
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
Stats *stats; // Objeto encargado de gestionar las estadísticas
// Variables
JA_Music music; // Musica que suena durante el juego

View File

@@ -28,9 +28,9 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
iniFade = 310;
fadeLenght = 20;
playerSprite->setPosX(GAMECANVAS_CENTER_X + 10);
playerSprite->setPosY(GAMECANVAS_CENTER_Y + 10);
playerSprite->setPosY(GAMECANVAS_CENTER_Y - 10);
tvSprite->setPosX(GAMECANVAS_CENTER_X - tvSprite->getAnimationClip(0, 0).w - 10);
tvSprite->setPosY(GAMECANVAS_CENTER_Y + 10);
tvSprite->setPosY(GAMECANVAS_CENTER_Y - 10);
// Inicializa el vector de colores
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
@@ -86,12 +86,17 @@ void GameOver::render()
screen->clean();
// Escribe el texto de GAME OVER
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - 20, "G A M E O V E R", 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - 40, "G A M E O V E R", 1, color);
// Dibuja los sprites
renderSprites();
// text->write(0, 0, std::to_string(counter));
// Escribe el texto con las habitaciones y los items
const std::string itemsTxt = std::to_string(options->items / 100) + std::to_string((options->items % 100) / 10) + std::to_string(options->items % 10);
const std::string roomsTxt = std::to_string(options->rooms / 100) + std::to_string((options->rooms % 100) / 10) + std::to_string(options->rooms % 10);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 40, "ITEMS: " + itemsTxt, 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y + 55, "ROOMS: " + roomsTxt, 1, color);
// Vuelca el contenido del renderizador en pantalla
screen->blit();
@@ -180,7 +185,7 @@ void GameOver::updateColor()
if (counter < half)
{
//const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
// const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
const float step = std::min(counter, fadeLenght) / (float)fadeLenght;
const int index = (colors.size() - 1) - int((colors.size() - 1) * step);
color = colors.at(index);

View File

@@ -824,6 +824,7 @@ bool Room::itemCollision(SDL_Rect &rect)
items.erase(items.begin() + i);
JA_PlaySound(itemSound);
*itemsPicked = *itemsPicked + 1;
options->items = *itemsPicked;
return true;
}
}

147
source/stats.cpp Normal file
View File

@@ -0,0 +1,147 @@
#include "stats.h"
#include <iostream>
#include <fstream>
#include <sstream>
// Constructor
Stats::Stats(std::string file)
{
filePath = file;
list.clear();
loadFromFile();
}
// Destructor
Stats::~Stats()
{
saveToFile();
list.clear();
}
// Añade una muerte a las estadisticas
void Stats::addDeath(std::string name)
{
// Primero busca si ya hay una entrada con ese nombre
const int index = findByName(name);
if (index != -1)
{
list.at(index).died++;
}
// En caso contrario crea la entrada
else
{
stats_t item;
item.name = name;
item.visited = 0;
item.died = 1;
list.push_back(item);
}
}
// Añade una visita a las estadisticas
void Stats::addVisit(std::string name)
{
// Primero busca si ya hay una entrada con ese nombre
const int index = findByName(name);
if (index != -1)
{
list.at(index).visited++;
}
// En caso contrario crea la entrada
else
{
stats_t item;
item.name = name;
item.visited = 1;
item.died = 0;
list.push_back(item);
}
}
// Busca una entrada en la lista por nombre
int Stats::findByName(std::string name)
{
int i = 0;
for (auto l : list)
{
if (l.name == name)
{
return i;
}
i++;
}
return -1;
}
// Carga las estadisticas desde un fichero
bool Stats::loadFromFile()
{
// Indicador de éxito en la carga
bool success = true;
// Variables para manejar el fichero
std::string line;
std::ifstream file(filePath);
// Si el fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
while (std::getline(file, line))
{
// Comprueba que la linea no sea un comentario
if (line.substr(0, 1) != "#")
{
stats_t stat;
std::stringstream ss(line);
std::string tmp;
// Obtiene el nombre
getline(ss, tmp, ';');
stat.name = tmp;
// Obtiene las visitas
getline(ss, tmp, ';');
stat.visited = std::stoi(tmp);
// Obtiene las muertes
getline(ss, tmp, ';');
stat.died = std::stoi(tmp);
list.push_back(stat);
}
}
// Cierra el fichero
file.close();
}
// El fichero no existe
else
{ // Crea el fichero con los valores por defecto
saveToFile();
}
return success;
}
// Guarda las estadisticas en un fichero
void Stats::saveToFile()
{
// Crea y abre el fichero de texto
std::ofstream file(filePath);
// Escribe en el fichero
file << "# NOMBRE DE LA HABITACION;VISITAS;MUERTES" << std::endl;
for (auto item : list)
{
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
}
// Cierra el fichero
file.close();
}

47
source/stats.h Normal file
View File

@@ -0,0 +1,47 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/utils.h"
#include <string>
#include <vector>
#ifndef STATS_H
#define STATS_H
struct stats_t
{
std::string name; // Nombre de la habitación donde se encuentra el objeto
int visited; // Cuenta las veces que se ha visitado una habitación
int died; // Cuenta las veces que se ha muerto en una habitación
};
class Stats
{
private:
// Variables
std::vector<stats_t> list; // Lista con las estadisticas por habitación
std::string filePath; // Fichero con las estadísticas
// Busca una entrada en la lista por nombre
int findByName(std::string name);
// Carga las estadisticas desde un fichero
bool loadFromFile();
// Guarda las estadisticas en un fichero
void saveToFile();
public:
// Constructor
Stats(std::string file);
// Destructor
~Stats();
// Añade una muerte a las estadisticas
void addDeath(std::string name);
// Añade una visita a las estadisticas
void addVisit(std::string name);
};
#endif

View File

@@ -1,74 +0,0 @@
#include "test.h"
// Constructor
Test::Test(SDL_Renderer *renderer, Screen *screen, Asset *asset, Debug *debug)
{
// Copia la dirección de los objetos
this->renderer = renderer;
this->screen = screen;
this->asset = asset;
this->debug = debug;
// Inicializa variables
for (int i = 0; i < 4; ++i)
{
point_t p;
p.x = rand() % 256;
p.y = rand() % 192;
p.vx = (float)((rand() % 10) + 1) / 10.0f;
p.vy = (float)((rand() % 10) + 1) / 10.0f;
rand() % 2 == 0 ? p.dx = -1 : p.dx = 1;
rand() % 2 == 0 ? p.dy = -1 : p.dy = 1;
p.vx *= p.dx;
p.vy *= p.dy;
points.push_back(p);
}
}
// Actualiza las variables
void Test::update()
{
for (int i = 0; i < (int)points.size(); ++i)
{
points[i].x += points[i].vx;
points[i].y += points[i].vy;
if (points[i].x > 255)
{
points[i].x = 255;
points[i].vx = -(float)((rand() % 10) + 1) / 10.0f;
}
else if (points[i].x < 0)
{
points[i].x = 0;
points[i].vx = (float)((rand() % 10) + 1) / 10.0f;
}
if (points[i].y > 191)
{
points[i].y = 191;
points[i].vy = -(float)((rand() % 10) + 1) / 10.0f;
}
else if (points[i].y < 0)
{
points[i].y = 0;
points[i].vy = (float)((rand() % 10) + 1) / 10.0f;
}
std::string text = "P" + std::to_string(i) + ": x=" + std::to_string(points[i].x).substr(0,3) + " y=" + std::to_string(points[i].y).substr(0,3) + " vx=" + std::to_string(points[i].vx).substr(0,3) + " vy=" + std::to_string(points[i].vy).substr(0,3);
debug->add(text);
}
}
// Dibuja en pantalla
void Test::render()
{
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
line_t l1 = {(int)points[0].x, (int)points[0].y, (int)points[1].x, (int)points[1].y};
line_t l2 = {(int)points[2].x, (int)points[2].y, (int)points[3].x, (int)points[3].y};
SDL_RenderDrawLine(renderer, l1.x1, l1.y1, l1.x2, l1.y2);
SDL_RenderDrawLine(renderer, l2.x1, l2.y1, l2.x2, l2.y2);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_Point p = checkCollision(l1, l2);
SDL_RenderDrawPoint(renderer, p.x, p.y);
}

View File

@@ -1,46 +0,0 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/asset.h"
#include "common/debug.h"
#include "common/screen.h"
#include "common/text.h"
#include "common/utils.h"
#include "const.h"
#include <string>
#include <vector>
#ifndef TEST_H
#define TEST_H
struct point_t
{
float x, y;
float vx, vy;
int dx, dy;
};
class Test
{
private:
// Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla
Asset *asset; // Objeto con los ficheros de recursos
Debug *debug;
// Variables
std::vector<point_t> points;
public:
// Constructor
Test(SDL_Renderer *renderer, Screen *screen, Asset *asset, Debug *debug);
// Actualiza las variables
void update();
// Dibuja en pantalla
void render();
};
#endif