Ya se puede ejecutar desde cualquier directorio

This commit is contained in:
2022-08-08 12:55:50 +02:00
parent 49e0d887f4
commit 18bc53a580
3 changed files with 231 additions and 57 deletions

View File

@@ -8,28 +8,6 @@
// Textos // Textos
const std::string WINDOW_TITLE = "Volcano 2016"; const std::string WINDOW_TITLE = "Volcano 2016";
const std::string BUILD = " (v0.5)"; const std::string BUILD = " (v0.5)";
const std::string FILE_MAP_VOLCANO = "../data/volcano.map.bak1";
const std::string FILE_TILES_VOLCANO = "../media/gfx/tiles_volcano.png";
const std::string FILE_TILES_SURFACE = "../media/gfx/tiles_surface.png";
const std::string FILE_BKG_SURFACE = "../media/gfx/bkg_surface.png";
const std::string FILE_MENU = "../media/gfx/menu.png";
const std::string FILE_MENU_ANIMATION = "../media/gfx/menu_animation.png";
const std::string FILE_ACTORS = "../media/gfx/actors.png";
const std::string FILE_PLAYER = "../media/gfx/player.png";
const std::string FILE_HUD = "../media/gfx/hud.png";
const std::string FILE_FILTER = "../media/gfx/filter.png";
const std::string FILE_SOUND_JUMP = "../media/sound/sound_player_jump.wav";
const std::string FILE_SOUND_DEATH = "../media/sound/sound_player_death.wav";
const std::string FILE_SOUND_COIN = "../media/sound/sound_player_coin.wav";
const std::string FILE_SOUND_MENU_LOGO = "../media/sound/sound_menu_logo.wav";
const std::string FILE_SOUND_MENU_START = "../media/sound/sound_menu_start.wav";
const std::string FILE_SOUND_DROP_ENEMY = "../media/sound/sound_drop_enemy.wav";
const std::string FILE_SOUND_DROP_SPLAT = "../media/sound/sound_drop_splat.wav";
const std::string FILE_MUSIC_SURFACE = "../media/music/music_surface.ogg";
const std::string FILE_MUSIC_VOLCANO = "../media/music/music_volcano.ogg";
const std::string FILE_MUSIC_MENU = "../media/music/music_menu.ogg";
const Uint8 GAME_SPEED = 24; //16 = normal-rapido, 24 = normal. Cuanto mas pequeño, más rápido const Uint8 GAME_SPEED = 24; //16 = normal-rapido, 24 = normal. Cuanto mas pequeño, más rápido
const Uint8 UP = 0; const Uint8 UP = 0;

View File

@@ -1,16 +1 @@
#ifdef _WIN64
#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\include\SDL2\SDL.h"
#endif
#ifdef _WIN32
#include "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\include\SDL2\SDL.h"
#endif
#ifdef __APPLE__
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
#endif
#ifdef __linux__
#include "/usr/include/SDL2/SDL.h"
#endif

View File

@@ -30,6 +30,29 @@ Uint8 starting_rooms_to_test[4] = {3, 26, 100, 190};
Uint8 starting_room = 0; Uint8 starting_room = 0;
// END DEBUG VARS // END DEBUG VARS
// FILES
std::string FILE_MAP_VOLCANO;
std::string FILE_TILES_VOLCANO;
std::string FILE_TILES_SURFACE;
std::string FILE_BKG_SURFACE;
std::string FILE_MENU;
std::string FILE_MENU_ANIMATION;
std::string FILE_ACTORS;
std::string FILE_PLAYER;
std::string FILE_HUD;
std::string FILE_FILTER;
std::string FILE_SOUND_JUMP;
std::string FILE_SOUND_DEATH;
std::string FILE_SOUND_COIN;
std::string FILE_SOUND_MENU_LOGO;
std::string FILE_SOUND_MENU_START;
std::string FILE_SOUND_DROP_ENEMY;
std::string FILE_SOUND_DROP_SPLAT;
std::string FILE_MUSIC_SURFACE;
std::string FILE_MUSIC_VOLCANO;
std::string FILE_MUSIC_MENU;
// END FILES
void allocatePointers() void allocatePointers()
{ {
// Textures // Textures
@@ -244,11 +267,195 @@ void CreateActor(Tactor &a, Uint8 kind, Uint8 id, Sint16 dstx, Sint16 dsty, Sint
void setExecutablePath(std::string path) void setExecutablePath(std::string path)
{ {
executablePath = path.substr(0, path.find_last_of("\\/")); executablePath = path.substr(0, path.find_last_of("\\/"));
printf("path: %s\n", executablePath.c_str());
std::string p;
SDL_RWops *file;
p = FILE_MAP_VOLCANO = executablePath + "/../data/volcano.map.bak1";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_TILES_VOLCANO = executablePath + "/../media/gfx/tiles_volcano.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_TILES_SURFACE = executablePath + "/../media/gfx/tiles_surface.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_BKG_SURFACE = executablePath + "/../media/gfx/bkg_surface.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_MENU = executablePath + "/../media/gfx/menu.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_MENU_ANIMATION = executablePath + "/../media/gfx/menu_animation.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_ACTORS = executablePath + "/../media/gfx/actors.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_PLAYER = executablePath + "/../media/gfx/player.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_HUD = executablePath + "/../media/gfx/hud.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_FILTER = executablePath + "/../media/gfx/filter.png";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_SOUND_JUMP = executablePath + "/../media/sound/sound_player_jump.wav";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_SOUND_DEATH = executablePath + "/../media/sound/sound_player_death.wav";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_SOUND_COIN = executablePath + "/../media/sound/sound_player_coin.wav";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_SOUND_MENU_LOGO = executablePath + "/../media/sound/sound_menu_logo.wav";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_SOUND_MENU_START = executablePath + "/../media/sound/sound_menu_start.wav";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_SOUND_DROP_ENEMY = executablePath + "/../media/sound/sound_drop_enemy.wav";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_SOUND_DROP_SPLAT = executablePath + "/../media/sound/sound_drop_splat.wav";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_MUSIC_SURFACE = executablePath + "/../media/music/music_surface.ogg";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_MUSIC_VOLCANO = executablePath + "/../media/music/music_volcano.ogg";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
p = FILE_MUSIC_MENU = executablePath + "/../media/music/music_menu.ogg";
printf("%s\n",p.c_str());
file = SDL_RWFromFile(p.c_str(), "r+b");
if (file == NULL)
{
printf("Checking file %-20s [OK]\n", p.c_str());
}
SDL_RWclose(file);
} }
void LoadMap() void LoadMap()
{ {
std::string p = executablePath + "/" + FILE_MAP_VOLCANO.c_str(); std::string p = FILE_MAP_VOLCANO.c_str();
std::string filename = p.substr(p.find_last_of("\\/") + 1); std::string filename = p.substr(p.find_last_of("\\/") + 1);
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b"); SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
@@ -1787,20 +1994,24 @@ void EndProgram()
int main(int argc, char *args[]) int main(int argc, char *args[])
{ {
setExecutablePath(args[0]);
fullscreen = false; fullscreen = false;
// Inicializa SDL // Inicializa SDL
printf("Init SDL..\n");
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_HAPTIC); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_HAPTIC);
window = SDL_CreateWindow((WINDOW_TITLE + BUILD).c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); window = SDL_CreateWindow((WINDOW_TITLE + BUILD).c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_RenderSetLogicalSize(renderer, 320, 240); SDL_RenderSetLogicalSize(renderer, 320, 240);
// Inicia las variables con las rutas de los ficheros
printf("Init paths..\n");
setExecutablePath(args[0]);
// Inicializa el audio // Inicializa el audio
//Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048);
JA_Init(22050, AUDIO_S16SYS, 2); JA_Init(22050, AUDIO_S16SYS, 2);
allocatePointers(); allocatePointers();
// Inicializa el programa // Inicializa el programa
IniProgram(); IniProgram();