Movida la carga de recursos al objeto director
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ scripts
|
||||
*.opk
|
||||
*.DS_Store
|
||||
jaildoctor*
|
||||
*plist*
|
||||
@@ -22,12 +22,9 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
this->debug = debug;
|
||||
this->options = options;
|
||||
|
||||
// Carga los recursos
|
||||
loadResources();
|
||||
|
||||
// Crea los objetos
|
||||
itemTracker = new ItemTracker();
|
||||
scoreboard = new ScoreBoard(renderer, asset, options, &board);
|
||||
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
|
||||
room = new Room(asset->get(currentRoom), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
@@ -51,8 +48,6 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
Demo::~Demo()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
resource->freeTextures();
|
||||
//delete resource;
|
||||
delete itemTracker;
|
||||
delete scoreboard;
|
||||
delete room;
|
||||
@@ -229,67 +224,3 @@ void Demo::checkRoomChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los recursos
|
||||
void Demo::loadResources()
|
||||
{
|
||||
std::vector<std::string> textureList;
|
||||
|
||||
// Jugador
|
||||
textureList.push_back("player.png");
|
||||
|
||||
// Tilesets
|
||||
textureList.push_back("standard.png");
|
||||
textureList.push_back("standard_zxarne.png");
|
||||
|
||||
// Enemigos
|
||||
textureList.push_back("paco.png");
|
||||
textureList.push_back("chip.png");
|
||||
textureList.push_back("wave.png");
|
||||
textureList.push_back("wave_v.png");
|
||||
textureList.push_back("sigmasua.png");
|
||||
textureList.push_back("diskette.png");
|
||||
textureList.push_back("bird.png");
|
||||
textureList.push_back("bin.png");
|
||||
textureList.push_back("qvoid.png");
|
||||
textureList.push_back("batman.png");
|
||||
textureList.push_back("tuno.png");
|
||||
textureList.push_back("matatunos.png");
|
||||
textureList.push_back("abad.png");
|
||||
textureList.push_back("jailbattle_human.png");
|
||||
textureList.push_back("jailbattle_alien.png");
|
||||
textureList.push_back("jailer.png");
|
||||
textureList.push_back("jailer2.png");
|
||||
textureList.push_back("jailer3.png");
|
||||
textureList.push_back("printer.png");
|
||||
textureList.push_back("code.png");
|
||||
textureList.push_back("demon.png");
|
||||
textureList.push_back("dimallas.png");
|
||||
textureList.push_back("dimallas_v.png");
|
||||
textureList.push_back("heavy.png");
|
||||
textureList.push_back("spider.png");
|
||||
textureList.push_back("macaronni_ted.png");
|
||||
textureList.push_back("mummy.png");
|
||||
textureList.push_back("sam.png");
|
||||
textureList.push_back("amstrad_character_set.png");
|
||||
textureList.push_back("breakout.png");
|
||||
textureList.push_back("lamp.png");
|
||||
textureList.push_back("bry.png");
|
||||
textureList.push_back("tv.png");
|
||||
textureList.push_back("tv_panel.png");
|
||||
textureList.push_back("arounders_door.png");
|
||||
textureList.push_back("arounders_machine.png");
|
||||
textureList.push_back("arounder_walk.png");
|
||||
textureList.push_back("arounder_stop.png");
|
||||
textureList.push_back("arounder_fly.png");
|
||||
textureList.push_back("bat.png");
|
||||
|
||||
// Items
|
||||
textureList.push_back("items.png");
|
||||
|
||||
// Texto
|
||||
textureList.push_back("smb2.png");
|
||||
textureList.push_back("debug.png");
|
||||
|
||||
resource->loadTextures(textureList);
|
||||
}
|
||||
@@ -66,9 +66,6 @@ private:
|
||||
// Comprueba si se ha de cambiar de habitación
|
||||
void checkRoomChange();
|
||||
|
||||
// Carga los recursos
|
||||
void loadResources();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Debug *debug);
|
||||
|
||||
@@ -177,6 +177,73 @@ bool Director::saveConfig()
|
||||
return success;
|
||||
}
|
||||
|
||||
// Carga los recursos
|
||||
void Director::loadResources(section_t section)
|
||||
{
|
||||
if (section.name == SECTION_PROG_GAME || section.name == SECTION_PROG_DEMO)
|
||||
{
|
||||
std::vector<std::string> textureList;
|
||||
|
||||
// Jugador
|
||||
textureList.push_back("player.png");
|
||||
|
||||
// Tilesets
|
||||
textureList.push_back("standard.png");
|
||||
textureList.push_back("standard_zxarne.png");
|
||||
|
||||
// Enemigos
|
||||
textureList.push_back("paco.png");
|
||||
textureList.push_back("chip.png");
|
||||
textureList.push_back("wave.png");
|
||||
textureList.push_back("wave_v.png");
|
||||
textureList.push_back("sigmasua.png");
|
||||
textureList.push_back("diskette.png");
|
||||
textureList.push_back("bird.png");
|
||||
textureList.push_back("bin.png");
|
||||
textureList.push_back("qvoid.png");
|
||||
textureList.push_back("batman.png");
|
||||
textureList.push_back("tuno.png");
|
||||
textureList.push_back("matatunos.png");
|
||||
textureList.push_back("abad.png");
|
||||
textureList.push_back("jailbattle_human.png");
|
||||
textureList.push_back("jailbattle_alien.png");
|
||||
textureList.push_back("jailer.png");
|
||||
textureList.push_back("jailer2.png");
|
||||
textureList.push_back("jailer3.png");
|
||||
textureList.push_back("printer.png");
|
||||
textureList.push_back("code.png");
|
||||
textureList.push_back("demon.png");
|
||||
textureList.push_back("dimallas.png");
|
||||
textureList.push_back("dimallas_v.png");
|
||||
textureList.push_back("heavy.png");
|
||||
textureList.push_back("spider.png");
|
||||
textureList.push_back("macaronni_ted.png");
|
||||
textureList.push_back("mummy.png");
|
||||
textureList.push_back("sam.png");
|
||||
textureList.push_back("amstrad_character_set.png");
|
||||
textureList.push_back("breakout.png");
|
||||
textureList.push_back("lamp.png");
|
||||
textureList.push_back("bry.png");
|
||||
textureList.push_back("tv.png");
|
||||
textureList.push_back("tv_panel.png");
|
||||
textureList.push_back("arounders_door.png");
|
||||
textureList.push_back("arounders_machine.png");
|
||||
textureList.push_back("arounder_walk.png");
|
||||
textureList.push_back("arounder_stop.png");
|
||||
textureList.push_back("arounder_fly.png");
|
||||
textureList.push_back("bat.png");
|
||||
|
||||
// Items
|
||||
textureList.push_back("items.png");
|
||||
|
||||
// Texto
|
||||
textureList.push_back("smb2.png");
|
||||
textureList.push_back("debug.png");
|
||||
|
||||
resource->loadTextures(textureList);
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool Director::setOptions(options_t *options, std::string var, std::string value)
|
||||
{
|
||||
@@ -708,18 +775,22 @@ void Director::runCredits()
|
||||
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
|
||||
void Director::runDemo()
|
||||
{
|
||||
loadResources(section);
|
||||
demo = new Demo(renderer, screen, resource, asset, options, debug);
|
||||
setSection(demo->run());
|
||||
delete demo;
|
||||
resource->freeTextures();
|
||||
}
|
||||
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
void Director::runGame()
|
||||
{
|
||||
JA_StopMusic();
|
||||
loadResources(section);
|
||||
game = new Game(renderer, screen, resource, asset, options, input, debug);
|
||||
setSection(game->run());
|
||||
delete game;
|
||||
resource->freeTextures();
|
||||
}
|
||||
|
||||
void Director::run()
|
||||
|
||||
@@ -27,6 +27,8 @@ private:
|
||||
SDL_Window *window; // La ventana donde dibujamos
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Input *input; // Objeto Input para gestionar las entradas
|
||||
Game *game; // Objeto para gestionar la sección del juego
|
||||
Logo *logo; // Objeto para gestionar la sección del logo del programa
|
||||
@@ -34,8 +36,6 @@ private:
|
||||
Intro *intro; // Objeto para gestionar la introducción del juego
|
||||
Credits *credits; // Objeto para gestionar los creditos del juego
|
||||
Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
||||
Debug *debug; // Objeto para getsionar la información de debug
|
||||
|
||||
// Variables
|
||||
@@ -50,6 +50,9 @@ private:
|
||||
// Guarda el fichero de configuración
|
||||
bool saveConfig();
|
||||
|
||||
// Carga los recursos
|
||||
void loadResources(section_t section);
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setOptions(options_t *options, std::string var, std::string value);
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ Enemy::Enemy(enemy_t enemy)
|
||||
renderer = enemy.renderer;
|
||||
|
||||
// Crea objetos
|
||||
//texture = new Texture(renderer, asset->get(enemy.tileset));
|
||||
texture = resource->getTexture(enemy.tileset);
|
||||
sprite = new AnimatedSprite(texture, renderer, asset->get(enemy.animation));
|
||||
|
||||
@@ -47,7 +46,6 @@ Enemy::Enemy(enemy_t enemy)
|
||||
// Destructor
|
||||
Enemy::~Enemy()
|
||||
{
|
||||
//delete texture;
|
||||
delete sprite;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
// ****
|
||||
|
||||
// Crea los objetos
|
||||
loadResources();
|
||||
scoreboard = new ScoreBoard(renderer, asset, options, &board);
|
||||
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
|
||||
itemTracker = new ItemTracker();
|
||||
roomTracker = new RoomTracker();
|
||||
room = new Room(asset->get(currentRoom), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
|
||||
@@ -61,9 +60,6 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
Game::~Game()
|
||||
{
|
||||
// Libera la memoria de los objetos
|
||||
resource->freeTextures();
|
||||
//delete resource;
|
||||
|
||||
delete scoreboard;
|
||||
delete itemTracker;
|
||||
delete roomTracker;
|
||||
@@ -459,67 +455,3 @@ void Game::renderBlackScreen()
|
||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los recursos
|
||||
void Game::loadResources()
|
||||
{
|
||||
std::vector<std::string> textureList;
|
||||
|
||||
// Jugador
|
||||
textureList.push_back("player.png");
|
||||
|
||||
// Tilesets
|
||||
textureList.push_back("standard.png");
|
||||
textureList.push_back("standard_zxarne.png");
|
||||
|
||||
// Enemigos
|
||||
textureList.push_back("paco.png");
|
||||
textureList.push_back("chip.png");
|
||||
textureList.push_back("wave.png");
|
||||
textureList.push_back("wave_v.png");
|
||||
textureList.push_back("sigmasua.png");
|
||||
textureList.push_back("diskette.png");
|
||||
textureList.push_back("bird.png");
|
||||
textureList.push_back("bin.png");
|
||||
textureList.push_back("qvoid.png");
|
||||
textureList.push_back("batman.png");
|
||||
textureList.push_back("tuno.png");
|
||||
textureList.push_back("matatunos.png");
|
||||
textureList.push_back("abad.png");
|
||||
textureList.push_back("jailbattle_human.png");
|
||||
textureList.push_back("jailbattle_alien.png");
|
||||
textureList.push_back("jailer.png");
|
||||
textureList.push_back("jailer2.png");
|
||||
textureList.push_back("jailer3.png");
|
||||
textureList.push_back("printer.png");
|
||||
textureList.push_back("code.png");
|
||||
textureList.push_back("demon.png");
|
||||
textureList.push_back("dimallas.png");
|
||||
textureList.push_back("dimallas_v.png");
|
||||
textureList.push_back("heavy.png");
|
||||
textureList.push_back("spider.png");
|
||||
textureList.push_back("macaronni_ted.png");
|
||||
textureList.push_back("mummy.png");
|
||||
textureList.push_back("sam.png");
|
||||
textureList.push_back("amstrad_character_set.png");
|
||||
textureList.push_back("breakout.png");
|
||||
textureList.push_back("lamp.png");
|
||||
textureList.push_back("bry.png");
|
||||
textureList.push_back("tv.png");
|
||||
textureList.push_back("tv_panel.png");
|
||||
textureList.push_back("arounders_door.png");
|
||||
textureList.push_back("arounders_machine.png");
|
||||
textureList.push_back("arounder_walk.png");
|
||||
textureList.push_back("arounder_stop.png");
|
||||
textureList.push_back("arounder_fly.png");
|
||||
textureList.push_back("bat.png");
|
||||
|
||||
// Items
|
||||
textureList.push_back("items.png");
|
||||
|
||||
// Texto
|
||||
textureList.push_back("smb2.png");
|
||||
textureList.push_back("debug.png");
|
||||
|
||||
resource->loadTextures(textureList);
|
||||
}
|
||||
@@ -109,9 +109,6 @@ private:
|
||||
// Dibuja la pantalla negra
|
||||
void renderBlackScreen();
|
||||
|
||||
// Carga los recursos
|
||||
void loadResources();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);
|
||||
|
||||
@@ -13,7 +13,6 @@ Item::Item(item_t item)
|
||||
renderer = item.renderer;
|
||||
|
||||
// Crea objetos
|
||||
//texture = new Texture(renderer, asset->get(item.tileset));
|
||||
texture = resource->getTexture(item.tileset);
|
||||
sprite = new Sprite(item.x, item.y, itemSize, itemSize, texture, renderer);
|
||||
|
||||
@@ -36,7 +35,6 @@ Item::Item(item_t item)
|
||||
// Destructor
|
||||
Item::~Item()
|
||||
{
|
||||
//delete texture;
|
||||
delete sprite;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,18 @@
|
||||
#include <sstream>
|
||||
|
||||
// Constructor
|
||||
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, options_t *options, board_t *board)
|
||||
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset, options_t *options, board_t *board)
|
||||
{
|
||||
// Obten punteros a objetos
|
||||
this->resource = resource;
|
||||
this->asset = asset;
|
||||
this->renderer = renderer;
|
||||
this->board = board;
|
||||
this->options = options;
|
||||
|
||||
// Reserva memoria para los objetos
|
||||
playerTexture = new Texture(renderer, asset->get("player.png"));
|
||||
itemTexture = new Texture(renderer, asset->get("items.png"));
|
||||
playerTexture = resource->getTexture("player.png");
|
||||
itemTexture = resource->getTexture("items.png");
|
||||
sprite = new AnimatedSprite(playerTexture, renderer, asset->get("player.ani"));
|
||||
sprite->setCurrentAnimation("walk_menu");
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
@@ -36,8 +37,6 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, options_t *options,
|
||||
// Destructor
|
||||
ScoreBoard::~ScoreBoard()
|
||||
{
|
||||
delete playerTexture;
|
||||
delete itemTexture;
|
||||
delete sprite;
|
||||
delete text;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include "common/animatedsprite.h"
|
||||
#include "common/asset.h"
|
||||
#include "common/resource.h"
|
||||
#include "common/text.h"
|
||||
#include "common/utils.h"
|
||||
#include "const.h"
|
||||
@@ -36,6 +37,7 @@ private:
|
||||
Texture *playerTexture; // Textura con los graficos para las vidas
|
||||
AnimatedSprite *sprite; // Sprite para mostrar las vidas en el marcador
|
||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||
Resource *resource; // Objeto con los recursos
|
||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||
Text *text; // Objeto para escribir texto
|
||||
Texture *itemTexture; // Textura con los graficos para las vidas
|
||||
@@ -56,7 +58,7 @@ private:
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
ScoreBoard(SDL_Renderer *renderer, Asset *asset, options_t *options, board_t *board);
|
||||
ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset, options_t *options, board_t *board);
|
||||
|
||||
// Destructor
|
||||
~ScoreBoard();
|
||||
|
||||
Reference in New Issue
Block a user