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
const std::string WINDOW_TITLE = "Volcano 2016";
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 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_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;
// 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()
{
// Textures
@@ -244,11 +267,195 @@ void CreateActor(Tactor &a, Uint8 kind, Uint8 id, Sint16 dstx, Sint16 dsty, Sint
void setExecutablePath(std::string path)
{
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()
{
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);
SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b");
@@ -1233,7 +1440,7 @@ void MoveActors()
break;
case KIND_DROP_SPLAT:
//if (actor[i].timer > 0) then
// if (actor[i].timer > 0) then
if (actor[i].frame < 23)
// Si encara te temps, pintem la animaci<63>
{
@@ -1259,13 +1466,13 @@ void MoveActors()
break;
case KIND_KEY:
//actor[i].frame = (actor[i].frame + 1) % 32;
//actor[i].src_rect.x = (actor[i].frame / 32) * actor[i].dst_rect.w;
// actor[i].frame = (actor[i].frame + 1) % 32;
// actor[i].src_rect.x = (actor[i].frame / 32) * actor[i].dst_rect.w;
break;
case KIND_LOCK:
//actor[i].frame = (actor[i].frame + 1) % 32;
//actor[i].src_rect.x = (actor[i].frame / 32) * actor[i].dst_rect.w;
// actor[i].frame = (actor[i].frame + 1) % 32;
// actor[i].src_rect.x = (actor[i].frame / 32) * actor[i].dst_rect.w;
break;
}
}
@@ -1374,7 +1581,7 @@ void ApplyGravity()
player.speed_y = player.speed_y + _GRAVITY;
// La velocitat no pot ser mai superior a la altura d'un tile del mapa, per a que no els atravesse
//player.speed_y = std::max(std::min(player.speed_y, MAX_SPEED_Y), -(MAX_SPEED_Y));
// player.speed_y = std::max(std::min(player.speed_y, MAX_SPEED_Y), -(MAX_SPEED_Y));
player.speed_y = std::min(player.speed_y, int(MAX_SPEED_Y));
// Calculem la nova posici<63>
@@ -1497,12 +1704,12 @@ void DrawHud()
hud.num_dst_rect.x = 37;
DrawSprite(hud.sprite, hud.num_src_rect, hud.num_dst_rect);
//tile_under_right_foot
// tile_under_right_foot
hud.num_src_rect.x = (ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h) / MAP_TILE_HEIGHT)) * hud.num_src_rect.w;
hud.num_dst_rect.x = 41;
DrawSprite(hud.sprite, hud.num_src_rect, hud.num_dst_rect);
//i_am_on_background
// i_am_on_background
Uint8 tile_on_left_foot = ReadMapTile((player.dst_rect.x + 3) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT);
Uint8 tile_on_right_foot = ReadMapTile((player.dst_rect.x + player.dst_rect.w - 4) / MAP_TILE_WIDTH, (player.dst_rect.y + player.dst_rect.h - 1) / MAP_TILE_HEIGHT);
bool i_am_on_background = ((tile_on_left_foot == TILE_BACKGROUND) && (tile_on_right_foot == TILE_BACKGROUND));
@@ -1787,20 +1994,24 @@ void EndProgram()
int main(int argc, char *args[])
{
setExecutablePath(args[0]);
fullscreen = false;
// Inicializa SDL
printf("Init SDL..\n");
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);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_RenderSetLogicalSize(renderer, 320, 240);
// Inicia las variables con las rutas de los ficheros
printf("Init paths..\n");
setExecutablePath(args[0]);
// Inicializa el audio
//Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048);
JA_Init(22050, AUDIO_S16SYS, 2);
allocatePointers();
// Inicializa el programa
IniProgram();
@@ -2143,7 +2354,7 @@ int main(int argc, char *args[])
SDL_RenderClear(renderer);
// Pintem el fondo del menu
//DrawSprite(menu.sprite, menu.src_rect_fondo, menu.dst_rect_fondo);
// DrawSprite(menu.sprite, menu.src_rect_fondo, menu.dst_rect_fondo);
// Pintem el logo DESPLEGA
menu.dst_rect_logo_zoom.w = menu.dst_rect_logo.w;
@@ -2180,7 +2391,7 @@ int main(int argc, char *args[])
SDL_RenderClear(renderer);
// Pintem el fondo del menu
//DrawSprite(menu.sprite, menu.src_rect_fondo, menu.dst_rect_fondo);
// DrawSprite(menu.sprite, menu.src_rect_fondo, menu.dst_rect_fondo);
// Pintem el logo
DrawSprite(menu.sprite, menu.src_rect_logo, menu.dst_rect_logo);
@@ -2194,11 +2405,11 @@ int main(int argc, char *args[])
if (menu.timer == 0)
{
//prog.section = SECTION_GAME;
//menu.enabled = false;
//game.enabled = true;
//menu.section = MENU_SECTION_ANIMATION;
//menu.timer = 100;
// prog.section = SECTION_GAME;
// menu.enabled = false;
// game.enabled = true;
// menu.section = MENU_SECTION_ANIMATION;
// menu.timer = 100;
}
}
@@ -2340,7 +2551,7 @@ int main(int argc, char *args[])
CLOSE_MUSIC(game.music);
CLOSE_MUSIC(menu.music);
//Mix_CloseAudio();
// Mix_CloseAudio();
EndProgram();