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;
|
||||
|
||||
// Player
|
||||
resource.texture[TEXTURE_PLAYER].texture = new LTexture();
|
||||
loadTextureFromFile(resource.texture[TEXTURE_PLAYER].texture, resource.texture[TEXTURE_PLAYER].file, renderer);
|
||||
player = new Player(renderer, resource.texture[TEXTURE_PLAYER].texture);
|
||||
player = new Player(renderer, asset);
|
||||
|
||||
// Map
|
||||
resource.texture[TEXTURE_ACTORS].texture = new LTexture();
|
||||
@@ -231,124 +229,38 @@ void Director::deleteObjects()
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros de recursos
|
||||
void Director::setFileList()
|
||||
bool Director::setFileList()
|
||||
{
|
||||
// Ficheros binarios
|
||||
asset->add("/data/volcano.map",data);
|
||||
asset->add("/data/config.bin".data);
|
||||
asset->add("/data/volcano.map", data);
|
||||
asset->add("/data/config.bin", data);
|
||||
|
||||
// Texturas
|
||||
asset->add("/media/gfx/actors.png",bitmap);
|
||||
asset->add("/media/gfx/bkg_surface.png",bitmap);
|
||||
asset->add("/media/gfx/filter.png",bitmap);
|
||||
asset->add("/media/gfx/hud.png",bitmap);
|
||||
asset->add("/media/gfx/menu_animation.png",bitmap);
|
||||
asset->add("/media/gfx/menu.png",bitmap);
|
||||
asset->add("/media/gfx/player.png",bitmap);
|
||||
asset->add("/media/gfx/tiles_surface.png",bitmap);
|
||||
asset->add("/media/gfx/tiles_volcano.png",bitmap);
|
||||
|
||||
asset->add("/media/gfx/actors.png", bitmap);
|
||||
asset->add("/media/gfx/bkg_surface.png", bitmap);
|
||||
asset->add("/media/gfx/filter.png", bitmap);
|
||||
asset->add("/media/gfx/hud.png", bitmap);
|
||||
asset->add("/media/gfx/menu_animation.png", bitmap);
|
||||
asset->add("/media/gfx/menu.png", bitmap);
|
||||
asset->add("/media/gfx/player.png", bitmap);
|
||||
asset->add("/media/gfx/tiles_surface.png", bitmap);
|
||||
asset->add("/media/gfx/tiles_volcano.png", bitmap);
|
||||
|
||||
// Sonidos
|
||||
resource.sound[SOUND_COIN].file = path + "/" + "../media/sound/sound_player_coin.wav";
|
||||
resource.sound[SOUND_DEATH].file = path + "/" + "../media/sound/sound_player_death.wav";
|
||||
resource.sound[SOUND_DROP_ENEMY].file = path + "/" + "../media/sound/sound_drop_enemy.wav";
|
||||
resource.sound[SOUND_DROP_SPLAT].file = path + "/" + "../media/sound/sound_drop_splat.wav";
|
||||
resource.sound[SOUND_JUMP].file = path + "/" + "../media/sound/sound_player_jump.wav";
|
||||
resource.sound[SOUND_MENU_LOGO].file = path + "/" + "../media/sound/sound_menu_logo.wav";
|
||||
resource.sound[SOUND_MENU_START].file = path + "/" + "../media/sound/sound_menu_start.wav";
|
||||
for (Uint8 i = 0; i < TOTAL_SOUND; i++)
|
||||
resource.sound[i].sound = nullptr;
|
||||
asset->add("/media/sound/sound_player_coin.wav", sound);
|
||||
asset->add("/media/sound/sound_player_death.wav", sound);
|
||||
asset->add("/media/sound/sound_drop_enemy.wav", sound);
|
||||
asset->add("/media/sound/sound_drop_splat.wav", sound);
|
||||
asset->add("/media/sound/sound_player_jump.wav", sound);
|
||||
asset->add("/media/sound/sound_menu_logo.wav", sound);
|
||||
asset->add("/media/sound/sound_menu_start.wav", sound);
|
||||
|
||||
// Musicas
|
||||
resource.music[MUSIC_MENU].file = path + "/" + "../media/music/music_menu.ogg";
|
||||
resource.music[MUSIC_SURFACE].file = path + "/" + "../media/music/music_surface.ogg";
|
||||
resource.music[MUSIC_VOLCANO].file = path + "/" + "../media/music/music_volcano.ogg";
|
||||
for (Uint8 i = 0; i < TOTAL_TEXTURE; i++)
|
||||
resource.music[i].music = nullptr;
|
||||
}
|
||||
asset->add("/media/music/music_menu.ogg", music);
|
||||
asset->add("/media/music/music_surface.ogg", music);
|
||||
asset->add("/media/music/music_volcano.ogg", music);
|
||||
|
||||
// Comprueba que todos los ficheros de recursos existen
|
||||
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();
|
||||
return asset->check();
|
||||
}
|
||||
|
||||
// Carga los recursos necesarios
|
||||
@@ -680,8 +592,8 @@ void Director::run()
|
||||
{
|
||||
bool quit = false;
|
||||
|
||||
// Comprueba si existen todos los ficheros de recursos
|
||||
if (!initResourceList())
|
||||
// Asigna y comprueba si existen todos los ficheros de recursos
|
||||
if (!setFileList())
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
|
||||
@@ -42,38 +42,6 @@ private:
|
||||
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_Renderer *renderer; // El renderizador donde se dibuja todo
|
||||
SDL_Event *eventHandler; // Manejador de eventos
|
||||
@@ -81,9 +49,7 @@ private:
|
||||
SDL_Joystick *gameController; // Manejador para el mando 1
|
||||
SDL_Haptic *controllerHaptic; // Manejador para la vibración del mando
|
||||
|
||||
_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
|
||||
_game game; // Contiene las variables de la sección de juego
|
||||
_options options; // Contiene todas las opciones del programa
|
||||
_text text; // Variable con los objetos texto
|
||||
bool gameControllerFound; // Indica si se ha encontrado algun mando conectado
|
||||
@@ -129,13 +95,7 @@ private:
|
||||
void setPath(std::string _path);
|
||||
|
||||
// Crea el indice de ficheros de recursos
|
||||
void setFileList();
|
||||
|
||||
// Comprueba que todos los ficheros de recursos existen
|
||||
bool checkResourceList();
|
||||
|
||||
// Inicializa la variable con los ficheros de recursos
|
||||
bool initResourceList();
|
||||
bool setFileList();
|
||||
|
||||
// Carga los recursos necesarios
|
||||
bool loadMedia(Uint8 section);
|
||||
|
||||
@@ -2,20 +2,34 @@
|
||||
#include "player.h"
|
||||
|
||||
// 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
|
||||
Player::~Player()
|
||||
{
|
||||
texture->unload();
|
||||
delete texture;
|
||||
texture = nullptr;
|
||||
|
||||
delete sprite;
|
||||
sprite = nullptr;
|
||||
}
|
||||
|
||||
// Inicializa todas las variables
|
||||
void Player::init(SDL_Renderer *renderer, LTexture *texture)
|
||||
void Player::init()
|
||||
{
|
||||
rect = {0, 0, 16, 24};
|
||||
|
||||
@@ -36,11 +50,6 @@ void Player::init(SDL_Renderer *renderer, LTexture *texture)
|
||||
speed_x = 0;
|
||||
speed_y = 0;
|
||||
|
||||
sprite = new AnimatedSprite();
|
||||
sprite->setTexture(texture);
|
||||
sprite->setRenderer(renderer);
|
||||
sprite->setSpriteClip(rect);
|
||||
|
||||
sound_coin = 0;
|
||||
sound_death = 0;
|
||||
sound_jump = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "animatedsprite.h"
|
||||
#include "asset.h"
|
||||
#include "jail_audio.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -9,25 +10,6 @@
|
||||
// The 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:
|
||||
bool can_jump; // Si puede saltar
|
||||
bool enabled; // Si está habilitado
|
||||
@@ -48,10 +30,31 @@ private:
|
||||
JA_Sound sound_jump; // Sonido al saltar
|
||||
SDL_Rect rect; // Rectangulo con la posición del jugador
|
||||
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 direction; // Sentido del desplazamiento
|
||||
Uint8 lifes; // Cantidad de vidas
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user