forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya carga las imagenes del juego y la demo desde la cache de rescursos
This commit is contained in:
150
source/game.cpp
150
source/game.cpp
@@ -1,7 +1,7 @@
|
||||
#include "game.h"
|
||||
|
||||
// Constructor
|
||||
Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, Input *input, Debug *debug)
|
||||
Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug)
|
||||
{
|
||||
// Inicia algunas variables
|
||||
board.iniClock = SDL_GetTicks();
|
||||
@@ -9,6 +9,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *opti
|
||||
spawnPoint = {15, 96, 0, 0, 0, s_standing, SDL_FLIP_NONE};
|
||||
|
||||
// Copia los punteros
|
||||
this->resource = resource;
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->screen = screen;
|
||||
@@ -24,15 +25,13 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *opti
|
||||
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
// ****
|
||||
|
||||
// Crea la cache de recursos
|
||||
cacheResources();
|
||||
|
||||
// Crea los objetos
|
||||
loadResources();
|
||||
scoreboard = new ScoreBoard(renderer, asset, options, &board);
|
||||
itemTracker = new ItemTracker();
|
||||
roomTracker = new RoomTracker();
|
||||
room = new Room(asset->get(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, debug);
|
||||
player = new Player(spawnPoint, asset->get("player.png"), asset->get("player.ani"), renderer, asset, options, input, room, debug);
|
||||
room = new Room(asset->get(currentRoom), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
|
||||
player = new Player(spawnPoint, "player.png", asset->get("player.ani"), renderer, resource, asset, options, input, room, debug);
|
||||
eventHandler = new SDL_Event();
|
||||
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
|
||||
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
||||
@@ -61,10 +60,10 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *opti
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
// Libera los recursos
|
||||
freeCache();
|
||||
|
||||
// Libera la memoria de los objetos
|
||||
resource->freeTextures();
|
||||
//delete resource;
|
||||
|
||||
delete scoreboard;
|
||||
delete itemTracker;
|
||||
delete roomTracker;
|
||||
@@ -305,7 +304,7 @@ bool Game::changeRoom(std::string file)
|
||||
room = nullptr;
|
||||
|
||||
// Crea un objeto habitación nuevo a partir del fichero
|
||||
room = new Room(asset->get(file), renderer, screen, asset, options, itemTracker, &board.items, debug);
|
||||
room = new Room(asset->get(file), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
|
||||
|
||||
// Actualiza el marcador
|
||||
const color_t c = room->getBorderColor(); // Pone el color del marcador
|
||||
@@ -394,8 +393,8 @@ void Game::killPlayer()
|
||||
setBlackScreen();
|
||||
|
||||
// Crea la nueva habitación y el nuevo jugador
|
||||
room = new Room(asset->get(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, debug);
|
||||
player = new Player(spawnPoint, asset->get("player.png"), asset->get("player.ani"), renderer, asset, options, input, room, debug);
|
||||
room = new Room(asset->get(currentRoom), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
|
||||
player = new Player(spawnPoint, "player.png", asset->get("player.ani"), renderer, resource, asset, options, input, room, debug);
|
||||
|
||||
room->pause();
|
||||
player->pause();
|
||||
@@ -461,85 +460,66 @@ void Game::renderBlackScreen()
|
||||
}
|
||||
}
|
||||
|
||||
// Carga todos los recursos necesarios
|
||||
void Game::cacheResources()
|
||||
// Carga los recursos
|
||||
void Game::loadResources()
|
||||
{
|
||||
// Carga las texturas
|
||||
std::vector<std::string> textureList;
|
||||
|
||||
|
||||
// Jugador
|
||||
textureList.push_back("player.png");
|
||||
textureList.push_back("player.png");
|
||||
|
||||
// Tilesets
|
||||
textureList.push_back("standard.png");
|
||||
textureList.push_back("standard_zxarne.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");
|
||||
// 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");
|
||||
// Items
|
||||
textureList.push_back("items.png");
|
||||
|
||||
// Texto
|
||||
textureList.push_back("smb2.png");
|
||||
textureList.push_back("debug.png");
|
||||
// Texto
|
||||
textureList.push_back("smb2.png");
|
||||
textureList.push_back("debug.png");
|
||||
|
||||
for (auto list : textureList)
|
||||
{
|
||||
texture_t t;
|
||||
t.name = list;
|
||||
t.texture = new Texture(renderer, asset->get(t.name));
|
||||
textures.push_back(t);
|
||||
}
|
||||
}
|
||||
|
||||
// Libera los recursos
|
||||
void Game::freeCache()
|
||||
{
|
||||
// Libera las texturas
|
||||
for (auto texture : textures)
|
||||
{
|
||||
texture.texture->unload();
|
||||
delete texture.texture;
|
||||
}
|
||||
textures.clear();
|
||||
resource->loadTextures(textureList);
|
||||
}
|
||||
Reference in New Issue
Block a user