forked from jaildesigner-jailgames/jaildoctors_dilemma
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c48dce8634 | |||
| a0de547370 | |||
| 5af554fecd | |||
| ea92241d6e | |||
| 60ea12f51d | |||
| 36c7063b3e | |||
| c6a1f4aab0 | |||
| eed3f9d7d1 | |||
| 02e6929f5f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
.vscode
|
.vscode
|
||||||
*config.txt
|
*config.txt
|
||||||
|
*stats.txt
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
thumbs.db
|
thumbs.db
|
||||||
*.exe
|
*.exe
|
||||||
|
|||||||
11
Makefile
11
Makefile
@@ -2,7 +2,7 @@ executable = jaildoctors_dilemma
|
|||||||
source = source/*.cpp source/common/*.cpp
|
source = source/*.cpp source/common/*.cpp
|
||||||
appName = JailDoctor's Dilemma
|
appName = JailDoctor's Dilemma
|
||||||
releaseFolder = jdd_release
|
releaseFolder = jdd_release
|
||||||
version = v1.01
|
version = v1.03
|
||||||
|
|
||||||
# Release names
|
# Release names
|
||||||
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
||||||
@@ -43,7 +43,7 @@ windows_release:
|
|||||||
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
|
||||||
|
|
||||||
# Create ZIP
|
# Create ZIP
|
||||||
powershell if (Test-Path $(executable)_win_$(version).zip) {Remove-Item $(windowsRelease)}
|
powershell if (Test-Path $(windowsRelease)) {Remove-Item $(windowsRelease)}
|
||||||
powershell Compress-Archive -Path "$(releaseFolder)"/* -DestinationPath $(windowsRelease)
|
powershell Compress-Archive -Path "$(releaseFolder)"/* -DestinationPath $(windowsRelease)
|
||||||
|
|
||||||
# Remove folder
|
# Remove folder
|
||||||
@@ -55,10 +55,13 @@ macos:
|
|||||||
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o $(executable)_macos
|
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o $(executable)_macos
|
||||||
|
|
||||||
macos_release:
|
macos_release:
|
||||||
# Remove data
|
# Remove data and possible data
|
||||||
rm -rdf data/config
|
rm -rdf data/config
|
||||||
rm -rdf "$(releaseFolder)"
|
rm -rdf "$(releaseFolder)"
|
||||||
rm -rdf Frameworks
|
rm -rdf Frameworks
|
||||||
|
rm -f tmp.dmg
|
||||||
|
rm -f "$(macosIntelRelease)"
|
||||||
|
rm -f "$(macosAppleSiliconRelease)"
|
||||||
|
|
||||||
# Create folders
|
# Create folders
|
||||||
mkdir -p data/config
|
mkdir -p data/config
|
||||||
@@ -84,7 +87,6 @@ macos_release:
|
|||||||
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
|
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
|
||||||
|
|
||||||
# Build INTEL DMG
|
# Build INTEL DMG
|
||||||
rm -f "$(macosIntelRelease)"
|
|
||||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||||
hdiutil convert tmp.dmg -format UDZO -o "$(macosIntelRelease)"
|
hdiutil convert tmp.dmg -format UDZO -o "$(macosIntelRelease)"
|
||||||
rm -f tmp.dmg
|
rm -f tmp.dmg
|
||||||
@@ -93,7 +95,6 @@ macos_release:
|
|||||||
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 arm64-apple-macos11
|
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 arm64-apple-macos11
|
||||||
|
|
||||||
# Build APPLE SILICON DMG
|
# Build APPLE SILICON DMG
|
||||||
rm -f "$(macosAppleSiliconRelease)"
|
|
||||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||||
hdiutil convert tmp.dmg -format UDZO -o "$(macosAppleSiliconRelease)"
|
hdiutil convert tmp.dmg -format UDZO -o "$(macosAppleSiliconRelease)"
|
||||||
rm -f tmp.dmg
|
rm -f tmp.dmg
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ bool Asset::check()
|
|||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
std::cout << "\n** Checking files." << std::endl;
|
std::cout << "\n** Checking files" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Executable path is: " << executablePath << std::endl;
|
||||||
|
std::cout << "Sample filepath: " << fileList.back().file << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba la lista de ficheros clasificandolos por tipo
|
// Comprueba la lista de ficheros clasificandolos por tipo
|
||||||
|
|||||||
@@ -14,67 +14,6 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
rooms.push_back("31.room");
|
rooms.push_back("31.room");
|
||||||
rooms.push_back("44.room");
|
rooms.push_back("44.room");
|
||||||
|
|
||||||
// rooms.push_back("01.room");
|
|
||||||
// rooms.push_back("02.room");
|
|
||||||
// rooms.push_back("03.room");
|
|
||||||
// rooms.push_back("04.room");
|
|
||||||
// rooms.push_back("05.room");
|
|
||||||
// rooms.push_back("06.room");
|
|
||||||
// rooms.push_back("07.room");
|
|
||||||
// rooms.push_back("08.room");
|
|
||||||
// rooms.push_back("09.room");
|
|
||||||
// rooms.push_back("10.room");
|
|
||||||
// rooms.push_back("11.room");
|
|
||||||
// rooms.push_back("12.room");
|
|
||||||
// rooms.push_back("13.room");
|
|
||||||
// rooms.push_back("14.room");
|
|
||||||
// rooms.push_back("15.room");
|
|
||||||
// rooms.push_back("16.room");
|
|
||||||
// rooms.push_back("17.room");
|
|
||||||
// rooms.push_back("18.room");
|
|
||||||
// rooms.push_back("19.room");
|
|
||||||
// rooms.push_back("20.room");
|
|
||||||
// rooms.push_back("21.room");
|
|
||||||
// rooms.push_back("22.room");
|
|
||||||
// rooms.push_back("23.room");
|
|
||||||
// rooms.push_back("24.room");
|
|
||||||
// rooms.push_back("25.room");
|
|
||||||
// rooms.push_back("26.room");
|
|
||||||
// rooms.push_back("27.room");
|
|
||||||
// rooms.push_back("28.room");
|
|
||||||
// rooms.push_back("29.room");
|
|
||||||
// rooms.push_back("30.room");
|
|
||||||
// rooms.push_back("31.room");
|
|
||||||
// rooms.push_back("32.room");
|
|
||||||
// rooms.push_back("33.room");
|
|
||||||
// rooms.push_back("34.room");
|
|
||||||
// rooms.push_back("35.room");
|
|
||||||
// rooms.push_back("36.room");
|
|
||||||
// rooms.push_back("37.room");
|
|
||||||
// rooms.push_back("38.room");
|
|
||||||
// rooms.push_back("39.room");
|
|
||||||
// rooms.push_back("40.room");
|
|
||||||
// rooms.push_back("41.room");
|
|
||||||
// rooms.push_back("42.room");
|
|
||||||
// rooms.push_back("43.room");
|
|
||||||
// rooms.push_back("44.room");
|
|
||||||
// rooms.push_back("45.room");
|
|
||||||
// rooms.push_back("46.room");
|
|
||||||
// rooms.push_back("47.room");
|
|
||||||
// rooms.push_back("48.room");
|
|
||||||
// rooms.push_back("49.room");
|
|
||||||
// rooms.push_back("50.room");
|
|
||||||
// rooms.push_back("51.room");
|
|
||||||
// rooms.push_back("52.room");
|
|
||||||
// rooms.push_back("53.room");
|
|
||||||
// rooms.push_back("54.room");
|
|
||||||
// rooms.push_back("55.room");
|
|
||||||
// rooms.push_back("56.room");
|
|
||||||
// rooms.push_back("57.room");
|
|
||||||
// rooms.push_back("58.room");
|
|
||||||
// rooms.push_back("59.room");
|
|
||||||
// rooms.push_back("60.room");
|
|
||||||
|
|
||||||
roomIndex = 0;
|
roomIndex = 0;
|
||||||
currentRoom = rooms.at(roomIndex);
|
currentRoom = rooms.at(roomIndex);
|
||||||
|
|
||||||
|
|||||||
@@ -1039,6 +1039,7 @@ bool Director::setFileList()
|
|||||||
// Configuración
|
// Configuración
|
||||||
asset->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);
|
asset->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);
|
||||||
asset->add(prefix + "/data/config/config.txt", t_data, false);
|
asset->add(prefix + "/data/config/config.txt", t_data, false);
|
||||||
|
asset->add(prefix + "/data/config/stats.txt", t_data, false);
|
||||||
|
|
||||||
// Habitaciones
|
// Habitaciones
|
||||||
asset->add(prefix + "/data/room/01.room", t_room);
|
asset->add(prefix + "/data/room/01.room", t_room);
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
this->options = options;
|
this->options = options;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
currentRoom = "14.room";
|
currentRoom = "48.room";
|
||||||
const int x1 = 1;
|
const int x1 = 18;
|
||||||
const int y1 = 13;
|
const int y1 = 13;
|
||||||
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||||
#endif
|
#endif
|
||||||
@@ -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);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
||||||
deathSound = JA_LoadSound(asset->get("death.wav").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
|
// Inicializa el resto de variables
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
@@ -70,6 +72,7 @@ Game::~Game()
|
|||||||
delete player;
|
delete player;
|
||||||
delete eventHandler;
|
delete eventHandler;
|
||||||
delete text;
|
delete text;
|
||||||
|
delete stats;
|
||||||
|
|
||||||
JA_DeleteMusic(music);
|
JA_DeleteMusic(music);
|
||||||
JA_DeleteSound(deathSound);
|
JA_DeleteSound(deathSound);
|
||||||
@@ -207,8 +210,11 @@ void Game::update()
|
|||||||
// Comprueba los eventos de la cola
|
// Comprueba los eventos de la cola
|
||||||
checkEventHandler();
|
checkEventHandler();
|
||||||
|
|
||||||
// Actualiza los objetos
|
#ifdef DEBUG
|
||||||
debug->clear();
|
debug->clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Actualiza los objetos
|
||||||
room->update();
|
room->update();
|
||||||
player->update();
|
player->update();
|
||||||
checkPlayerOnBorder();
|
checkPlayerOnBorder();
|
||||||
@@ -220,9 +226,11 @@ void Game::update()
|
|||||||
scoreboard->update();
|
scoreboard->update();
|
||||||
input->update();
|
input->update();
|
||||||
|
|
||||||
updateDebugInfo();
|
|
||||||
updateBlackScreen();
|
updateBlackScreen();
|
||||||
screen->updateFX();
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
updateDebugInfo();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,14 +249,16 @@ void Game::render()
|
|||||||
scoreboard->render();
|
scoreboard->render();
|
||||||
renderBlackScreen();
|
renderBlackScreen();
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
// Debug info
|
// Debug info
|
||||||
renderDebugInfo();
|
renderDebugInfo();
|
||||||
// screen->renderFX();
|
#endif
|
||||||
|
|
||||||
// Actualiza la pantalla
|
// Actualiza la pantalla
|
||||||
screen->blit();
|
screen->blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
// Pasa la información de debug
|
// Pasa la información de debug
|
||||||
void Game::updateDebugInfo()
|
void Game::updateDebugInfo()
|
||||||
{
|
{
|
||||||
@@ -285,6 +295,7 @@ void Game::renderDebugInfo()
|
|||||||
debug->setPos({1, 18 * 8});
|
debug->setPos({1, 18 * 8});
|
||||||
debug->render();
|
debug->render();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Escribe el nombre de la pantalla
|
// Escribe el nombre de la pantalla
|
||||||
void Game::renderRoomName()
|
void Game::renderRoomName()
|
||||||
@@ -328,6 +339,9 @@ bool Game::changeRoom(std::string file)
|
|||||||
// Pasa la nueva habitación al jugador
|
// Pasa la nueva habitación al jugador
|
||||||
player->setRoom(room);
|
player->setRoom(room);
|
||||||
|
|
||||||
|
// Actualiza las estadisticas
|
||||||
|
stats->addVisit(room->getName());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,6 +412,9 @@ void Game::killPlayer()
|
|||||||
board.lives--;
|
board.lives--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza las estadisticas
|
||||||
|
stats->addDeath(room->getName());
|
||||||
|
|
||||||
// Destruye la habitacion y el jugador
|
// Destruye la habitacion y el jugador
|
||||||
delete room;
|
delete room;
|
||||||
delete this->player;
|
delete this->player;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "room_tracker.h"
|
#include "room_tracker.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "scoreboard.h"
|
#include "scoreboard.h"
|
||||||
|
#include "stats.h"
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
@@ -39,6 +40,7 @@ private:
|
|||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource; // Objeto con los recursos
|
||||||
Debug *debug; // Objeto para gestionar la información de debug
|
Debug *debug; // Objeto para gestionar la información de debug
|
||||||
options_t *options; // Puntero a las opciones del juego
|
options_t *options; // Puntero a las opciones del juego
|
||||||
|
Stats *stats; // Objeto encargado de gestionar las estadísticas
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
JA_Music music; // Musica que suena durante el juego
|
JA_Music music; // Musica que suena durante el juego
|
||||||
@@ -63,11 +65,13 @@ private:
|
|||||||
// Comprueba los eventos de la cola
|
// Comprueba los eventos de la cola
|
||||||
void checkEventHandler();
|
void checkEventHandler();
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
// Pone la información de debug en pantalla
|
// Pone la información de debug en pantalla
|
||||||
void updateDebugInfo();
|
void updateDebugInfo();
|
||||||
|
|
||||||
// Pone la información de debug en pantalla
|
// Pone la información de debug en pantalla
|
||||||
void renderDebugInfo();
|
void renderDebugInfo();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Escribe el nombre de la pantalla
|
// Escribe el nombre de la pantalla
|
||||||
void renderRoomName();
|
void renderRoomName();
|
||||||
|
|||||||
@@ -93,9 +93,15 @@ Player::Player(player_t player)
|
|||||||
fallSound.push_back(JA_LoadSound(asset->get("jump23.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset->get("jump23.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump24.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset->get("jump24.wav").c_str()));
|
||||||
|
|
||||||
r = {0, 0, 0, 0};
|
|
||||||
jumpCounter = 0;
|
jumpCounter = 0;
|
||||||
fallCounter = 0;
|
fallCounter = 0;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
rx = {0, 0, 0, 0};
|
||||||
|
ry = {0, 0, 0, 0};
|
||||||
|
debugColor = {0, 255, 0};
|
||||||
|
debugPoint = {0, 0};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -114,6 +120,8 @@ void Player::render()
|
|||||||
{
|
{
|
||||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
||||||
sprite->render();
|
sprite->render();
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
if (debug->getEnabled())
|
if (debug->getEnabled())
|
||||||
{
|
{
|
||||||
// Pinta los underfeet
|
// Pinta los underfeet
|
||||||
@@ -122,14 +130,28 @@ void Player::render()
|
|||||||
SDL_RenderDrawPoint(renderer, underFeet[1].x, underFeet[1].y);
|
SDL_RenderDrawPoint(renderer, underFeet[1].x, underFeet[1].y);
|
||||||
|
|
||||||
// Pinta rectangulo del jugador
|
// Pinta rectangulo del jugador
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 192);
|
SDL_SetRenderDrawColor(renderer, debugColor.r, debugColor.g, debugColor.b, 192);
|
||||||
SDL_Rect rect = getRect();
|
SDL_Rect rect = getRect();
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
|
||||||
|
SDL_RenderDrawRect(renderer, &rect);
|
||||||
|
|
||||||
// Pinta el rectangulo de movimiento
|
// Pinta el rectangulo de movimiento
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||||
SDL_RenderFillRect(renderer, &r);
|
if (vx != 0.0f)
|
||||||
|
{
|
||||||
|
SDL_RenderFillRect(renderer, &rx);
|
||||||
}
|
}
|
||||||
|
if (vy != 0.0f)
|
||||||
|
{
|
||||||
|
SDL_RenderFillRect(renderer, &ry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pinta el punto de debug
|
||||||
|
SDL_SetRenderDrawColor(renderer, rand() % 256, rand() % 256, rand() % 256, 255);
|
||||||
|
SDL_RenderDrawPoint(renderer, debugPoint.x, debugPoint.y);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
@@ -231,21 +253,25 @@ void Player::checkBorders()
|
|||||||
border = BORDER_LEFT;
|
border = BORDER_LEFT;
|
||||||
onBorder = true;
|
onBorder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (x > PLAY_AREA_RIGHT - w)
|
else if (x > PLAY_AREA_RIGHT - w)
|
||||||
{
|
{
|
||||||
border = BORDER_RIGHT;
|
border = BORDER_RIGHT;
|
||||||
onBorder = true;
|
onBorder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (y < PLAY_AREA_TOP)
|
else if (y < PLAY_AREA_TOP)
|
||||||
{
|
{
|
||||||
border = BORDER_TOP;
|
border = BORDER_TOP;
|
||||||
onBorder = true;
|
onBorder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (y > PLAY_AREA_BOTTOM - h)
|
else if (y > PLAY_AREA_BOTTOM - h)
|
||||||
{
|
{
|
||||||
border = BORDER_BOTTOM;
|
border = BORDER_BOTTOM;
|
||||||
onBorder = true;
|
onBorder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
onBorder = false;
|
onBorder = false;
|
||||||
@@ -273,7 +299,7 @@ void Player::checkState()
|
|||||||
vy = 0.0f;
|
vy = 0.0f;
|
||||||
jumpCounter = 0;
|
jumpCounter = 0;
|
||||||
fallCounter = 0;
|
fallCounter = 0;
|
||||||
if (!isOnFloor() && !isOnAutoSurface())
|
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope())
|
||||||
{
|
{
|
||||||
setState(s_falling);
|
setState(s_falling);
|
||||||
vx = 0.0f;
|
vx = 0.0f;
|
||||||
@@ -353,6 +379,10 @@ void Player::move()
|
|||||||
applyGravity(); // Aplica gravedad al jugador
|
applyGravity(); // Aplica gravedad al jugador
|
||||||
checkState(); // Comprueba el estado del jugador
|
checkState(); // Comprueba el estado del jugador
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
debugColor = {0, 255, 0};
|
||||||
|
#endif
|
||||||
|
|
||||||
// Se mueve hacia la izquierda
|
// Se mueve hacia la izquierda
|
||||||
if (vx < 0.0f)
|
if (vx < 0.0f)
|
||||||
{
|
{
|
||||||
@@ -363,7 +393,9 @@ void Player::move()
|
|||||||
proj.h = h;
|
proj.h = h;
|
||||||
proj.w = ceil(abs(vx)); // Para evitar que tenga un ancho de 0 pixels
|
proj.w = ceil(abs(vx)); // Para evitar que tenga un ancho de 0 pixels
|
||||||
|
|
||||||
r = proj;
|
#ifdef DEBUG
|
||||||
|
rx = proj;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies
|
// Comprueba la colisión con las superficies
|
||||||
const int pos = room->checkRightSurfaces(&proj);
|
const int pos = room->checkRightSurfaces(&proj);
|
||||||
@@ -406,7 +438,9 @@ void Player::move()
|
|||||||
proj.h = h;
|
proj.h = h;
|
||||||
proj.w = ceil(vx); // Para evitar que tenga un ancho de 0 pixels
|
proj.w = ceil(vx); // Para evitar que tenga un ancho de 0 pixels
|
||||||
|
|
||||||
r = proj;
|
#ifdef DEBUG
|
||||||
|
rx = proj;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión
|
// Comprueba la colisión
|
||||||
const int pos = room->checkLeftSurfaces(&proj);
|
const int pos = room->checkLeftSurfaces(&proj);
|
||||||
@@ -465,7 +499,9 @@ void Player::move()
|
|||||||
proj.h = ceil(abs(vy)); // Para evitar que tenga una altura de 0 pixels
|
proj.h = ceil(abs(vy)); // Para evitar que tenga una altura de 0 pixels
|
||||||
proj.w = w;
|
proj.w = w;
|
||||||
|
|
||||||
r = proj;
|
#ifdef DEBUG
|
||||||
|
ry = proj;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión
|
// Comprueba la colisión
|
||||||
const int pos = room->checkBottomSurfaces(&proj);
|
const int pos = room->checkBottomSurfaces(&proj);
|
||||||
@@ -492,7 +528,9 @@ void Player::move()
|
|||||||
proj.h = ceil(vy); // Para evitar que tenga una altura de 0 pixels
|
proj.h = ceil(vy); // Para evitar que tenga una altura de 0 pixels
|
||||||
proj.w = w;
|
proj.w = w;
|
||||||
|
|
||||||
r = proj;
|
#ifdef DEBUG
|
||||||
|
ry = proj;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies normales y las automáticas
|
// Comprueba la colisión con las superficies normales y las automáticas
|
||||||
const int pos = std::max(room->checkTopSurfaces(&proj), room->checkAutoSurfaces(&proj));
|
const int pos = std::max(room->checkTopSurfaces(&proj), room->checkAutoSurfaces(&proj));
|
||||||
@@ -516,11 +554,18 @@ void Player::move()
|
|||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
y = p - h;
|
y = p - h;
|
||||||
setState(s_standing);
|
setState(s_standing);
|
||||||
|
#ifdef DEBUG
|
||||||
|
debugColor = {255, 255, 0};
|
||||||
|
debugPoint = {(int)x + (w / 2), p};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // No está saltando y no hay colisón con una rampa
|
{ // No está saltando y no hay colisón con una rampa
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
y += vy;
|
y += vy;
|
||||||
|
#ifdef DEBUG
|
||||||
|
debugColor = {255, 0, 0};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -535,7 +580,10 @@ void Player::move()
|
|||||||
sprite->setPosX(x);
|
sprite->setPosX(x);
|
||||||
sprite->setPosY(y);
|
sprite->setPosY(y);
|
||||||
|
|
||||||
debug->add("RECT: " + std::to_string(r.x) + "," + std::to_string(r.y) + "," + std::to_string(r.w) + "," + std::to_string(r.h));
|
#ifdef DEBUG
|
||||||
|
debug->add("RECT_X: " + std::to_string(rx.x) + "," + std::to_string(rx.y) + "," + std::to_string(rx.w) + "," + std::to_string(rx.h));
|
||||||
|
debug->add("RECT_Y: " + std::to_string(ry.x) + "," + std::to_string(ry.y) + "," + std::to_string(ry.w) + "," + std::to_string(ry.h));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece la animación del jugador
|
// Establece la animación del jugador
|
||||||
@@ -571,7 +619,10 @@ void Player::playJumpSound()
|
|||||||
{
|
{
|
||||||
JA_PlaySound(jumpSound[jumpCounter / 4]);
|
JA_PlaySound(jumpSound[jumpCounter / 4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
debug->add("JUMP: " + std::to_string(jumpCounter / 4));
|
debug->add("JUMP: " + std::to_string(jumpCounter / 4));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcula y reproduce el sonido de caer
|
// Calcula y reproduce el sonido de caer
|
||||||
@@ -581,7 +632,10 @@ void Player::playFallSound()
|
|||||||
{
|
{
|
||||||
JA_PlaySound(fallSound[std::min((fallCounter / 4), (int)fallSound.size() - 1)]);
|
JA_PlaySound(fallSound[std::min((fallCounter / 4), (int)fallSound.size() - 1)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
debug->add("FALL: " + std::to_string(fallCounter / 4));
|
debug->add("FALL: " + std::to_string(fallCounter / 4));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||||
@@ -604,6 +658,7 @@ bool Player::isOnFloor()
|
|||||||
onSlopeL = room->checkLeftSlopes(&underFeet[0]);
|
onSlopeL = room->checkLeftSlopes(&underFeet[0]);
|
||||||
onSlopeR = room->checkRightSlopes(&underFeet[1]);
|
onSlopeR = room->checkRightSlopes(&underFeet[1]);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
if (onFloor)
|
if (onFloor)
|
||||||
{
|
{
|
||||||
debug->add("ON_FLOOR");
|
debug->add("ON_FLOOR");
|
||||||
@@ -618,6 +673,7 @@ bool Player::isOnFloor()
|
|||||||
{
|
{
|
||||||
debug->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y));
|
debug->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return onFloor || onSlopeL || onSlopeR;
|
return onFloor || onSlopeL || onSlopeR;
|
||||||
}
|
}
|
||||||
@@ -635,10 +691,12 @@ bool Player::isOnAutoSurface()
|
|||||||
onAutoSurface |= room->checkAutoSurfaces(&f);
|
onAutoSurface |= room->checkAutoSurfaces(&f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
if (onAutoSurface)
|
if (onAutoSurface)
|
||||||
{
|
{
|
||||||
debug->add("ON_AUTO_SURFACE");
|
debug->add("ON_AUTO_SURFACE");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return onAutoSurface;
|
return onAutoSurface;
|
||||||
}
|
}
|
||||||
@@ -659,10 +717,12 @@ bool Player::isOnDownSlope()
|
|||||||
onSlope |= room->checkLeftSlopes(&underFeet[0]);
|
onSlope |= room->checkLeftSlopes(&underFeet[0]);
|
||||||
onSlope |= room->checkRightSlopes(&underFeet[1]);
|
onSlope |= room->checkRightSlopes(&underFeet[1]);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
if (onSlope)
|
if (onSlope)
|
||||||
{
|
{
|
||||||
debug->add("ON_DOWN_SLOPE");
|
debug->add("ON_DOWN_SLOPE");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return onSlope;
|
return onSlope;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,13 @@ public:
|
|||||||
int fallCounter; // Cuenta el tiempo de caida
|
int fallCounter; // Cuenta el tiempo de caida
|
||||||
bool alive; // Indica si el jugador esta vivo o no
|
bool alive; // Indica si el jugador esta vivo o no
|
||||||
int maxFallHeight; // Altura maxima permitida de caída.
|
int maxFallHeight; // Altura maxima permitida de caída.
|
||||||
SDL_Rect r;
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug
|
||||||
|
SDL_Rect ry; // Rectangulo de desplazamiento para el modo debug
|
||||||
|
color_t debugColor; // Color del recuadro de debug del jugador
|
||||||
|
SDL_Point debugPoint; // Punto para debug
|
||||||
|
#endif
|
||||||
|
|
||||||
// Comprueba las entradas y modifica variables
|
// Comprueba las entradas y modifica variables
|
||||||
void checkInput();
|
void checkInput();
|
||||||
|
|||||||
@@ -554,6 +554,7 @@ void Room::fillMapTexture()
|
|||||||
clip.y = (tileMap.at(index) / tileSetWidth) * tileSize;
|
clip.y = (tileMap.at(index) / tileSetWidth) * tileSize;
|
||||||
texture->render(renderer, x * tileSize, y * tileSize, &clip);
|
texture->render(renderer, x * tileSize, y * tileSize, &clip);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
// ****
|
// ****
|
||||||
if (debug->getEnabled())
|
if (debug->getEnabled())
|
||||||
{
|
{
|
||||||
@@ -565,10 +566,12 @@ void Room::fillMapTexture()
|
|||||||
SDL_RenderFillRect(renderer, &clip);
|
SDL_RenderFillRect(renderer, &clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ****
|
// ****
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
// ****
|
// ****
|
||||||
if (debug->getEnabled())
|
if (debug->getEnabled())
|
||||||
{
|
{
|
||||||
@@ -649,6 +652,7 @@ void Room::fillMapTexture()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ****
|
// ****
|
||||||
|
#endif
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
}
|
}
|
||||||
@@ -659,11 +663,15 @@ void Room::renderMap()
|
|||||||
// Dibuja la textura con el mapa en pantalla
|
// Dibuja la textura con el mapa en pantalla
|
||||||
SDL_RenderCopy(renderer, mapTexture, nullptr, nullptr);
|
SDL_RenderCopy(renderer, mapTexture, nullptr, nullptr);
|
||||||
|
|
||||||
// Dibuja los tiles animados
|
// Dibuja los tiles animados
|
||||||
|
#ifdef DEBUG
|
||||||
if (!debug->getEnabled())
|
if (!debug->getEnabled())
|
||||||
{
|
{
|
||||||
renderAnimatedTiles();
|
renderAnimatedTiles();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
renderAnimatedTiles();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja los enemigos en pantalla
|
// Dibuja los enemigos en pantalla
|
||||||
@@ -882,22 +890,30 @@ int Room::getSlopeHeight(SDL_Point p, tile_e slope)
|
|||||||
{
|
{
|
||||||
// Calcula la base del tile
|
// Calcula la base del tile
|
||||||
int base = ((p.y / tileSize) * tileSize) + tileSize;
|
int base = ((p.y / tileSize) * tileSize) + tileSize;
|
||||||
|
#ifdef DEBUG
|
||||||
debug->add("BASE = " + std::to_string(base));
|
debug->add("BASE = " + std::to_string(base));
|
||||||
|
#endif
|
||||||
|
|
||||||
// Calcula cuanto se ha entrado en el tile horizontalmente
|
// Calcula cuanto se ha entrado en el tile horizontalmente
|
||||||
const int pos = (p.x % tileSize); // Esto da un valor entre 0 y 7
|
const int pos = (p.x % tileSize); // Esto da un valor entre 0 y 7
|
||||||
|
#ifdef DEBUG
|
||||||
debug->add("POS = " + std::to_string(pos));
|
debug->add("POS = " + std::to_string(pos));
|
||||||
|
#endif
|
||||||
|
|
||||||
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
|
// Se resta a la base la cantidad de pixeles pos en funcion de la rampa
|
||||||
if (slope == t_slope_r)
|
if (slope == t_slope_r)
|
||||||
{
|
{
|
||||||
base -= pos + 1;
|
base -= pos + 1;
|
||||||
|
#ifdef DEBUG
|
||||||
debug->add("BASE_R = " + std::to_string(base));
|
debug->add("BASE_R = " + std::to_string(base));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
base -= (tileSize - pos);
|
base -= (tileSize - pos);
|
||||||
|
#ifdef DEBUG
|
||||||
debug->add("BASE_L = " + std::to_string(base));
|
debug->add("BASE_L = " + std::to_string(base));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
|
|||||||
147
source/stats.cpp
Normal file
147
source/stats.cpp
Normal 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
47
source/stats.h
Normal 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
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user