Trabajando en integrar el objeto asset y mejorar los objetos player y map
This commit is contained in:
@@ -67,9 +67,7 @@ void Director::initGame()
|
|||||||
game.counter = 0;
|
game.counter = 0;
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
resource.texture[TEXTURE_PLAYER].texture = new LTexture();
|
player = new Player(renderer, asset);
|
||||||
loadTextureFromFile(resource.texture[TEXTURE_PLAYER].texture, resource.texture[TEXTURE_PLAYER].file, renderer);
|
|
||||||
player = new Player(renderer, resource.texture[TEXTURE_PLAYER].texture);
|
|
||||||
|
|
||||||
// Map
|
// Map
|
||||||
resource.texture[TEXTURE_ACTORS].texture = new LTexture();
|
resource.texture[TEXTURE_ACTORS].texture = new LTexture();
|
||||||
@@ -231,11 +229,11 @@ void Director::deleteObjects()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Crea el indice de ficheros de recursos
|
// Crea el indice de ficheros de recursos
|
||||||
void Director::setFileList()
|
bool Director::setFileList()
|
||||||
{
|
{
|
||||||
// Ficheros binarios
|
// Ficheros binarios
|
||||||
asset->add("/data/volcano.map", data);
|
asset->add("/data/volcano.map", data);
|
||||||
asset->add("/data/config.bin".data);
|
asset->add("/data/config.bin", data);
|
||||||
|
|
||||||
// Texturas
|
// Texturas
|
||||||
asset->add("/media/gfx/actors.png", bitmap);
|
asset->add("/media/gfx/actors.png", bitmap);
|
||||||
@@ -249,106 +247,20 @@ void Director::setFileList()
|
|||||||
asset->add("/media/gfx/tiles_volcano.png", bitmap);
|
asset->add("/media/gfx/tiles_volcano.png", bitmap);
|
||||||
|
|
||||||
// Sonidos
|
// Sonidos
|
||||||
resource.sound[SOUND_COIN].file = path + "/" + "../media/sound/sound_player_coin.wav";
|
asset->add("/media/sound/sound_player_coin.wav", sound);
|
||||||
resource.sound[SOUND_DEATH].file = path + "/" + "../media/sound/sound_player_death.wav";
|
asset->add("/media/sound/sound_player_death.wav", sound);
|
||||||
resource.sound[SOUND_DROP_ENEMY].file = path + "/" + "../media/sound/sound_drop_enemy.wav";
|
asset->add("/media/sound/sound_drop_enemy.wav", sound);
|
||||||
resource.sound[SOUND_DROP_SPLAT].file = path + "/" + "../media/sound/sound_drop_splat.wav";
|
asset->add("/media/sound/sound_drop_splat.wav", sound);
|
||||||
resource.sound[SOUND_JUMP].file = path + "/" + "../media/sound/sound_player_jump.wav";
|
asset->add("/media/sound/sound_player_jump.wav", sound);
|
||||||
resource.sound[SOUND_MENU_LOGO].file = path + "/" + "../media/sound/sound_menu_logo.wav";
|
asset->add("/media/sound/sound_menu_logo.wav", sound);
|
||||||
resource.sound[SOUND_MENU_START].file = path + "/" + "../media/sound/sound_menu_start.wav";
|
asset->add("/media/sound/sound_menu_start.wav", sound);
|
||||||
for (Uint8 i = 0; i < TOTAL_SOUND; i++)
|
|
||||||
resource.sound[i].sound = nullptr;
|
|
||||||
|
|
||||||
// Musicas
|
// Musicas
|
||||||
resource.music[MUSIC_MENU].file = path + "/" + "../media/music/music_menu.ogg";
|
asset->add("/media/music/music_menu.ogg", music);
|
||||||
resource.music[MUSIC_SURFACE].file = path + "/" + "../media/music/music_surface.ogg";
|
asset->add("/media/music/music_surface.ogg", music);
|
||||||
resource.music[MUSIC_VOLCANO].file = path + "/" + "../media/music/music_volcano.ogg";
|
asset->add("/media/music/music_volcano.ogg", music);
|
||||||
for (Uint8 i = 0; i < TOTAL_TEXTURE; i++)
|
|
||||||
resource.music[i].music = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba que todos los ficheros de recursos existen
|
return asset->check();
|
||||||
bool Director::checkResourceList()
|
|
||||||
{
|
|
||||||
bool success = true;
|
|
||||||
std::string p;
|
|
||||||
std::string filename;
|
|
||||||
SDL_RWops *file;
|
|
||||||
|
|
||||||
// Comprueba los ficheros de musica
|
|
||||||
printf("\n>> MUSIC FILES\n");
|
|
||||||
for (Uint8 i = 0; i < TOTAL_MUSIC; i++)
|
|
||||||
{
|
|
||||||
p = resource.music[i].file.c_str();
|
|
||||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
|
||||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
|
||||||
if (file != NULL)
|
|
||||||
{
|
|
||||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success = false;
|
|
||||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
|
||||||
}
|
|
||||||
SDL_RWclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los ficheros de sonidos
|
|
||||||
printf("\n>> SOUND FILES\n");
|
|
||||||
for (Uint8 i = 0; i < TOTAL_SOUND; i++)
|
|
||||||
{
|
|
||||||
p = resource.sound[i].file.c_str();
|
|
||||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
|
||||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
|
||||||
if (file != NULL)
|
|
||||||
{
|
|
||||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success = false;
|
|
||||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
|
||||||
}
|
|
||||||
SDL_RWclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba los ficheros con texturas
|
|
||||||
printf("\n>> TEXTURE FILES\n");
|
|
||||||
for (Uint8 i = 0; i < TOTAL_TEXTURE; i++)
|
|
||||||
{
|
|
||||||
p = resource.texture[i].file.c_str();
|
|
||||||
filename = p.substr(p.find_last_of("\\/") + 1);
|
|
||||||
file = SDL_RWFromFile(p.c_str(), "r+b");
|
|
||||||
if (file != NULL)
|
|
||||||
{
|
|
||||||
printf("Checking file %-20s [OK]\n", filename.c_str());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success = false;
|
|
||||||
printf("Checking file %-20s [ERROR]\n", filename.c_str());
|
|
||||||
}
|
|
||||||
SDL_RWclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resultado
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
printf("\n** All files OK.\n\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("\n** File is missing. Exiting.\n\n");
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa la variable con los ficheros de recursos
|
|
||||||
bool Director::initResourceList()
|
|
||||||
{
|
|
||||||
setResourceList();
|
|
||||||
return checkResourceList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga los recursos necesarios
|
// Carga los recursos necesarios
|
||||||
@@ -680,8 +592,8 @@ void Director::run()
|
|||||||
{
|
{
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
|
|
||||||
// Comprueba si existen todos los ficheros de recursos
|
// Asigna y comprueba si existen todos los ficheros de recursos
|
||||||
if (!initResourceList())
|
if (!setFileList())
|
||||||
{
|
{
|
||||||
quit = true;
|
quit = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,38 +42,6 @@ private:
|
|||||||
Uint32 counter; // Contador para el juego
|
Uint32 counter; // Contador para el juego
|
||||||
};
|
};
|
||||||
|
|
||||||
// Recursos
|
|
||||||
struct _resourceFile
|
|
||||||
{
|
|
||||||
std::string file;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _resourceSound
|
|
||||||
{
|
|
||||||
std::string file;
|
|
||||||
JA_Sound sound;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _resourceMusic
|
|
||||||
{
|
|
||||||
std::string file;
|
|
||||||
JA_Music music;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _resourceTexture
|
|
||||||
{
|
|
||||||
std::string file;
|
|
||||||
LTexture *texture;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _resource
|
|
||||||
{
|
|
||||||
_resourceFile file[TOTAL_FILE];
|
|
||||||
_resourceSound sound[TOTAL_SOUND];
|
|
||||||
_resourceMusic music[TOTAL_MUSIC];
|
|
||||||
_resourceTexture texture[TOTAL_TEXTURE];
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL_Window *window; // La ventana de la aplicación
|
SDL_Window *window; // La ventana de la aplicación
|
||||||
SDL_Renderer *renderer; // El renderizador donde se dibuja todo
|
SDL_Renderer *renderer; // El renderizador donde se dibuja todo
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Event *eventHandler; // Manejador de eventos
|
||||||
@@ -82,8 +50,6 @@ private:
|
|||||||
SDL_Haptic *controllerHaptic; // Manejador para la vibración del mando
|
SDL_Haptic *controllerHaptic; // Manejador para la vibración del mando
|
||||||
|
|
||||||
_game game; // Contiene las variables de la sección de juego
|
_game game; // Contiene las variables de la sección de juego
|
||||||
//_menu menu; // Variable con los objetos menu
|
|
||||||
_resource resource; // Contiene todos los objetos y variables asociados a recursos
|
|
||||||
_options options; // Contiene todas las opciones del programa
|
_options options; // Contiene todas las opciones del programa
|
||||||
_text text; // Variable con los objetos texto
|
_text text; // Variable con los objetos texto
|
||||||
bool gameControllerFound; // Indica si se ha encontrado algun mando conectado
|
bool gameControllerFound; // Indica si se ha encontrado algun mando conectado
|
||||||
@@ -129,13 +95,7 @@ private:
|
|||||||
void setPath(std::string _path);
|
void setPath(std::string _path);
|
||||||
|
|
||||||
// Crea el indice de ficheros de recursos
|
// Crea el indice de ficheros de recursos
|
||||||
void setFileList();
|
bool setFileList();
|
||||||
|
|
||||||
// Comprueba que todos los ficheros de recursos existen
|
|
||||||
bool checkResourceList();
|
|
||||||
|
|
||||||
// Inicializa la variable con los ficheros de recursos
|
|
||||||
bool initResourceList();
|
|
||||||
|
|
||||||
// Carga los recursos necesarios
|
// Carga los recursos necesarios
|
||||||
bool loadMedia(Uint8 section);
|
bool loadMedia(Uint8 section);
|
||||||
|
|||||||
@@ -2,20 +2,34 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(SDL_Renderer *renderer, LTexture *texture)
|
Player::Player(SDL_Renderer *renderer, Asset *asset)
|
||||||
{
|
{
|
||||||
init(renderer, texture);
|
texture = new LTexture();
|
||||||
|
loadTextureFromFile(texture, asset->get("player.png"), renderer);
|
||||||
|
|
||||||
|
sprite = new AnimatedSprite();
|
||||||
|
sprite->setTexture(texture);
|
||||||
|
sprite->setRenderer(renderer);
|
||||||
|
sprite->setSpriteClip(rect);
|
||||||
|
|
||||||
|
this->asset = asset;
|
||||||
|
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
{
|
{
|
||||||
|
texture->unload();
|
||||||
|
delete texture;
|
||||||
|
texture = nullptr;
|
||||||
|
|
||||||
delete sprite;
|
delete sprite;
|
||||||
sprite = nullptr;
|
sprite = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa todas las variables
|
// Inicializa todas las variables
|
||||||
void Player::init(SDL_Renderer *renderer, LTexture *texture)
|
void Player::init()
|
||||||
{
|
{
|
||||||
rect = {0, 0, 16, 24};
|
rect = {0, 0, 16, 24};
|
||||||
|
|
||||||
@@ -36,11 +50,6 @@ void Player::init(SDL_Renderer *renderer, LTexture *texture)
|
|||||||
speed_x = 0;
|
speed_x = 0;
|
||||||
speed_y = 0;
|
speed_y = 0;
|
||||||
|
|
||||||
sprite = new AnimatedSprite();
|
|
||||||
sprite->setTexture(texture);
|
|
||||||
sprite->setRenderer(renderer);
|
|
||||||
sprite->setSpriteClip(rect);
|
|
||||||
|
|
||||||
sound_coin = 0;
|
sound_coin = 0;
|
||||||
sound_death = 0;
|
sound_death = 0;
|
||||||
sound_jump = 0;
|
sound_jump = 0;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
#include "asset.h"
|
||||||
#include "jail_audio.h"
|
#include "jail_audio.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@@ -9,25 +10,6 @@
|
|||||||
// The player
|
// The player
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Player(SDL_Renderer *renderer, LTexture *texture);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Player();
|
|
||||||
|
|
||||||
// Inicializa todas las variables
|
|
||||||
void init(SDL_Renderer *renderer, LTexture *texture);
|
|
||||||
|
|
||||||
// Resetea ciertas variables
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
// Actualiza todas las variables
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Dibuja el objeto
|
|
||||||
void render();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool can_jump; // Si puede saltar
|
bool can_jump; // Si puede saltar
|
||||||
bool enabled; // Si está habilitado
|
bool enabled; // Si está habilitado
|
||||||
@@ -48,10 +30,31 @@ private:
|
|||||||
JA_Sound sound_jump; // Sonido al saltar
|
JA_Sound sound_jump; // Sonido al saltar
|
||||||
SDL_Rect rect; // Rectangulo con la posición del jugador
|
SDL_Rect rect; // Rectangulo con la posición del jugador
|
||||||
AnimatedSprite *sprite; // Sprite con los graficos y animaciones
|
AnimatedSprite *sprite; // Sprite con los graficos y animaciones
|
||||||
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
|
LTexture *texture; // Objeto con los gráficos del jugador
|
||||||
Uint8 active_animation; // Animación activa
|
Uint8 active_animation; // Animación activa
|
||||||
Uint8 direction; // Sentido del desplazamiento
|
Uint8 direction; // Sentido del desplazamiento
|
||||||
Uint8 lifes; // Cantidad de vidas
|
Uint8 lifes; // Cantidad de vidas
|
||||||
Uint8 respawn_direction; // Dirección para revivir
|
Uint8 respawn_direction; // Dirección para revivir
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
Player(SDL_Renderer *renderer, Asset *asset);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Player();
|
||||||
|
|
||||||
|
// Inicializa todas las variables
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Resetea ciertas variables
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
// Actualiza todas las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja el objeto
|
||||||
|
void render();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user