Trabajando en la precarga de habitaciones

This commit is contained in:
2022-10-30 13:27:30 +01:00
parent d1c27c4639
commit c11f5d2622
74 changed files with 1028 additions and 754 deletions

View File

@@ -25,7 +25,7 @@ animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath)
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]")
{
t_animation buffer;
animation_t buffer;
buffer.counter = 0;
buffer.currentFrame = 0;
buffer.completed = false;
@@ -361,7 +361,7 @@ animatedSprite_t AnimatedSprite::loadFromFile(std::string filePath)
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]")
{
t_animation buffer;
animation_t buffer;
buffer.counter = 0;
buffer.currentFrame = 0;
buffer.completed = false;
@@ -505,7 +505,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source)
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]")
{
t_animation buffer;
animation_t buffer;
buffer.counter = 0;
buffer.currentFrame = 0;
buffer.completed = false;

View File

@@ -11,7 +11,7 @@
#ifndef ANIMATEDSPRITE_H
#define ANIMATEDSPRITE_H
struct t_animation
struct animation_t
{
std::string name; // Nombre de la animacion
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
@@ -24,7 +24,7 @@ struct t_animation
struct animatedSprite_t
{
std::vector<t_animation> animations; // Vector con las diferentes animaciones
std::vector<animation_t> animations; // Vector con las diferentes animaciones
Texture *texture; // Textura con los graficos para el sprite
};
@@ -35,7 +35,7 @@ class AnimatedSprite : public MovingSprite
{
private:
// Variables
std::vector<t_animation> animation; // Vector con las diferentes animaciones
std::vector<animation_t> animation; // Vector con las diferentes animaciones
int currentAnimation; // Animacion activa
public:

View File

@@ -14,7 +14,7 @@ void Resource::loadTextures(std::vector<std::string> list)
{
for (auto l : list)
{
texture_t t;
res_texture_t t;
t.name = l;
t.texture = new Texture(renderer, asset->get(l));
textures.push_back(t);
@@ -26,7 +26,7 @@ void Resource::loadAnimations(std::vector<std::string> list)
{
for (auto l : list)
{
animation_t as;
res_animation_t as;
as.name = l + ".ani";
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(l + ".png"), asset->get(l + ".ani")));
animations.push_back(as);
@@ -38,13 +38,48 @@ void Resource::loadOffsets(std::vector<std::string> list)
{
for (auto l : list)
{
textOffset_t to;
res_textOffset_t to;
to.name = l;
to.textFile = new textFile_t(LoadTextFile(asset->get(l)));
offsets.push_back(to);
}
}
// Carga los mapas de tiles desde una lista
void Resource::loadTileMaps(std::vector<std::string> list)
{
for (auto l : list)
{
res_tileMap_t tm;
tm.name = l;
tm.tileMap = new std::vector<int>(loadRoomTileFile(asset->get(l)));
tileMaps.push_back(tm);
}
}
// Carga las habitaciones desde una lista
void Resource::loadRooms(std::vector<std::string> list)
{
for (auto l : list)
{
res_room_t r;
r.name = l;
r.room = new room_t(loadRoomFile(asset->get(l)));
r.room->tileMap = getTileMap(r.room->tileMapFile);
for (auto &e:r.room->enemies)
{
e.animation = getAnimation(e.animationString);
}
for (auto &i:r.room->items)
{
i.texture = getTexture(i.tileSetFile);
}
r.room->textureA = getTexture("standard.png");
r.room->textureB = getTexture("standard_zxarne.png");
rooms.push_back(r);
}
}
// Recarga las texturas
void Resource::reLoadTextures()
{
@@ -84,12 +119,34 @@ void Resource::freeOffsets()
offsets.clear();
}
// Libera los mapas de tiles
void Resource::freeTileMaps()
{
for (auto t : tileMaps)
{
delete t.tileMap;
}
tileMaps.clear();
}
// Libera las habitaciones
void Resource::freeRooms()
{
for (auto r : rooms)
{
delete r.room;
}
rooms.clear();
}
// Libera todos los recursos
void Resource::free()
{
freeTextures();
freeAnimations();
freeOffsets();
freeTileMaps();
freeRooms();
}
// Obtiene una textura
@@ -99,12 +156,11 @@ Texture *Resource::getTexture(std::string name)
{
if (texture.name.find(name) != std::string::npos)
{
std::cout << "CACHE: " << name << std::endl;
return texture.texture;
}
}
std::cout << "NOT FOUND: " << name << std::endl;
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
@@ -115,12 +171,11 @@ animatedSprite_t *Resource::getAnimation(std::string name)
{
if (animation.name.find(name) != std::string::npos)
{
std::cout << "CACHE: " << name << std::endl;
return animation.animation;
}
}
std::cout << "NOT FOUND: " << name << std::endl;
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
@@ -131,11 +186,40 @@ textFile_t *Resource::getOffset(std::string name)
{
if (offset.name.find(name) != std::string::npos)
{
std::cout << "CACHE: " << name << std::endl;
return offset.textFile;
}
}
std::cout << "NOT FOUND: " << name << std::endl;
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
// Obtiene un mapa de tiles
std::vector<int> *Resource::getTileMap(std::string name)
{
for (auto tileMap : tileMaps)
{
if (tileMap.name.find(name) != std::string::npos)
{
return tileMap.tileMap;
}
}
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
// Obtiene una habitacion
room_t *Resource::getRoom(std::string name)
{
for (auto room : rooms)
{
if (room.name.find(name) != std::string::npos)
{
return room.room;
}
}
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}

View File

@@ -3,6 +3,7 @@
#include <SDL2/SDL.h>
#include "animatedsprite.h"
#include "asset.h"
#include "../room.h"
#include "text.h"
#include "texture.h"
#include "utils.h"
@@ -12,24 +13,36 @@
#ifndef RESOURCE_H
#define RESOURCE_H
struct texture_t
struct res_texture_t
{
std::string name; // Nombre de la textura
Texture *texture; // La textura
};
struct animation_t
struct res_animation_t
{
std::string name; // Nombre de la textura
animatedSprite_t *animation; // La animación
};
struct textOffset_t
struct res_textOffset_t
{
std::string name; // Nombre del offeset
std::string name; // Nombre del offset
textFile_t *textFile; // Los offsets de la fuente
};
struct res_tileMap_t
{
std::string name; // Nombre del mapa de tiles
std::vector<int> *tileMap; // Vecor con los indices del mapa de tiles
};
struct res_room_t
{
std::string name; // Nombre de la habitación
room_t *room; // Vecor con las habitaciones
};
// Clase Resource. Almacena recursos de disco en memoria
class Resource
{
@@ -40,9 +53,11 @@ private:
options_t *options; // Puntero a las opciones del juego
// Variables
std::vector<texture_t> textures;
std::vector<animation_t> animations;
std::vector<textOffset_t> offsets;
std::vector<res_texture_t> textures;
std::vector<res_animation_t> animations;
std::vector<res_textOffset_t> offsets;
std::vector<res_tileMap_t> tileMaps;
std::vector<res_room_t> rooms;
public:
// Constructor
@@ -57,6 +72,12 @@ public:
// Carga los offsets desde una lista
void loadOffsets(std::vector<std::string> list);
// Carga los mapas de tiles desde una lista
void loadTileMaps(std::vector<std::string> list);
// Carga las habitaciones desde una lista
void loadRooms(std::vector<std::string> list);
// Recarga las texturas
void reLoadTextures();
@@ -69,6 +90,12 @@ public:
// Libera los offsets
void freeOffsets();
// Libera los mapas de tiles
void freeTileMaps();
// Libera las habitaciones
void freeRooms();
// Libera todos los recursos
void free();
@@ -80,6 +107,12 @@ public:
// Obtiene un offset
textFile_t *getOffset(std::string name);
// Obtiene un mapa de tiles
std::vector<int> *getTileMap(std::string name);
// Obtiene una habitacion
room_t *getRoom(std::string name);
};
#endif

View File

@@ -25,7 +25,7 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
// Crea los objetos
itemTracker = new ItemTracker();
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
room = new Room(asset->get(currentRoom), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, debug);
eventHandler = new SDL_Event();
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
@@ -224,7 +224,7 @@ bool Demo::changeRoom(std::string file)
room = nullptr;
// Crea un objeto habitación nuevo a partir del fichero
room = new Room(asset->get(file), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
room = new Room(resource->getRoom(file), renderer, screen, asset, options, itemTracker, &board.items, debug);
// Actualiza el marcador
const color_t c = room->getBorderColor(); // Pone el color del marcador

View File

@@ -9,7 +9,7 @@ Director::Director(std::string path)
section.name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_INTRO;
section.name = SECTION_PROG_LOGO;
section.name = SECTION_PROG_GAME;
// Crea el objeto que controla los ficheros de recursos
asset = new Asset(path.substr(0, path.find_last_of("\\/")));
@@ -360,6 +360,136 @@ void Director::loadResources(section_t section)
offsetsList.push_back("debug.txt");
resource->loadOffsets(offsetsList);
// TileMaps
std::vector<std::string> tileMapList;
tileMapList.push_back("01.tmx");
tileMapList.push_back("02.tmx");
tileMapList.push_back("03.tmx");
tileMapList.push_back("04.tmx");
tileMapList.push_back("05.tmx");
tileMapList.push_back("06.tmx");
tileMapList.push_back("07.tmx");
tileMapList.push_back("08.tmx");
tileMapList.push_back("09.tmx");
tileMapList.push_back("10.tmx");
tileMapList.push_back("11.tmx");
tileMapList.push_back("12.tmx");
tileMapList.push_back("13.tmx");
tileMapList.push_back("14.tmx");
tileMapList.push_back("15.tmx");
tileMapList.push_back("16.tmx");
tileMapList.push_back("17.tmx");
tileMapList.push_back("18.tmx");
tileMapList.push_back("19.tmx");
tileMapList.push_back("20.tmx");
tileMapList.push_back("21.tmx");
tileMapList.push_back("22.tmx");
tileMapList.push_back("23.tmx");
tileMapList.push_back("24.tmx");
tileMapList.push_back("25.tmx");
tileMapList.push_back("26.tmx");
tileMapList.push_back("27.tmx");
tileMapList.push_back("28.tmx");
tileMapList.push_back("29.tmx");
tileMapList.push_back("30.tmx");
tileMapList.push_back("31.tmx");
tileMapList.push_back("32.tmx");
tileMapList.push_back("33.tmx");
tileMapList.push_back("34.tmx");
tileMapList.push_back("35.tmx");
tileMapList.push_back("36.tmx");
tileMapList.push_back("37.tmx");
tileMapList.push_back("38.tmx");
tileMapList.push_back("39.tmx");
tileMapList.push_back("40.tmx");
tileMapList.push_back("41.tmx");
tileMapList.push_back("42.tmx");
tileMapList.push_back("43.tmx");
tileMapList.push_back("44.tmx");
tileMapList.push_back("45.tmx");
tileMapList.push_back("46.tmx");
tileMapList.push_back("47.tmx");
tileMapList.push_back("48.tmx");
tileMapList.push_back("49.tmx");
tileMapList.push_back("50.tmx");
tileMapList.push_back("51.tmx");
tileMapList.push_back("52.tmx");
tileMapList.push_back("53.tmx");
tileMapList.push_back("54.tmx");
tileMapList.push_back("55.tmx");
tileMapList.push_back("56.tmx");
tileMapList.push_back("57.tmx");
tileMapList.push_back("58.tmx");
tileMapList.push_back("59.tmx");
tileMapList.push_back("60.tmx");
resource->loadTileMaps(tileMapList);
// Habitaciones
std::vector<std::string> roomList;
roomList.push_back("01.room");
roomList.push_back("02.room");
roomList.push_back("03.room");
roomList.push_back("04.room");
roomList.push_back("05.room");
roomList.push_back("06.room");
roomList.push_back("07.room");
roomList.push_back("08.room");
roomList.push_back("09.room");
roomList.push_back("10.room");
roomList.push_back("11.room");
roomList.push_back("12.room");
roomList.push_back("13.room");
roomList.push_back("14.room");
roomList.push_back("15.room");
roomList.push_back("16.room");
roomList.push_back("17.room");
roomList.push_back("18.room");
roomList.push_back("19.room");
roomList.push_back("20.room");
roomList.push_back("21.room");
roomList.push_back("22.room");
roomList.push_back("23.room");
roomList.push_back("24.room");
roomList.push_back("25.room");
roomList.push_back("26.room");
roomList.push_back("27.room");
roomList.push_back("28.room");
roomList.push_back("29.room");
roomList.push_back("30.room");
roomList.push_back("31.room");
roomList.push_back("32.room");
roomList.push_back("33.room");
roomList.push_back("34.room");
roomList.push_back("35.room");
roomList.push_back("36.room");
roomList.push_back("37.room");
roomList.push_back("38.room");
roomList.push_back("39.room");
roomList.push_back("40.room");
roomList.push_back("41.room");
roomList.push_back("42.room");
roomList.push_back("43.room");
roomList.push_back("44.room");
roomList.push_back("45.room");
roomList.push_back("46.room");
roomList.push_back("47.room");
roomList.push_back("48.room");
roomList.push_back("49.room");
roomList.push_back("50.room");
roomList.push_back("51.room");
roomList.push_back("52.room");
roomList.push_back("53.room");
roomList.push_back("54.room");
roomList.push_back("55.room");
roomList.push_back("56.room");
roomList.push_back("57.room");
roomList.push_back("58.room");
roomList.push_back("59.room");
roomList.push_back("60.room");
resource->loadRooms(roomList);
}
std::cout << "** RESOURCES LOADED" << std::endl;

View File

@@ -1,19 +1,10 @@
#include "enemy.h"
#include <fstream>
#include <sstream>
// Constructor
Enemy::Enemy(enemy_t enemy)
{
// Obten punteros a objetos
resource = enemy.resource;
asset = enemy.asset;
renderer = enemy.renderer;
// Crea objetos
texture = resource->getTexture(enemy.tileset);
//sprite = new AnimatedSprite(texture, renderer, asset->get(enemy.animation));
sprite = new AnimatedSprite(renderer, resource->getAnimation(enemy.animation));
sprite = new AnimatedSprite(enemy.renderer, enemy.animation);
// Obten el resto de valores
x1 = enemy.x1;
@@ -103,7 +94,7 @@ SDL_Rect &Enemy::getCollider()
// Recarga la textura
void Enemy::reLoadTexture()
{
texture->reLoad();
sprite->getTexture()->reLoad();
}
// Asigna la paleta

View File

@@ -1,8 +1,8 @@
#pragma once
#include <SDL2/SDL.h>
#include "common/animatedsprite.h"
#include "common/asset.h"
#include "common/resource.h"
#include "common/utils.h"
#include <string>
@@ -12,34 +12,28 @@
// Estructura para pasar los datos de un enemigo
struct enemy_t
{
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
std::string tileset; // Fichero con los graficos del enemigo
std::string animation; // Fichero con las animaciones del enemigo
int w; // Anchura del enemigo
int h; // Altura del enemigo
float x; // Posición inicial en el eje X
float y; // Posición inicial en el eje Y
float vx; // Velocidad en el eje X
float vy; // Velocidad en el eje Y
int x1; // Limite izquierdo de la ruta en el eje X
int x2; // Limite derecho de la ruta en el eje X
int y1; // Limite superior de la ruta en el eje Y
int y2; // Limite inferior de la ruta en el eje Y
bool flip; // Indica si el enemigo hace flip al terminar su ruta
std::string color; // Color del enemigo
palette_e palette; // Paleta de colores
SDL_Renderer *renderer; // El renderizador de la ventana
animatedSprite_t *animation; // Puntero a las animaciones del enemigo
std::string animationString; // Ruta al fichero con la animación
int w; // Anchura del enemigo
int h; // Altura del enemigo
float x; // Posición inicial en el eje X
float y; // Posición inicial en el eje Y
float vx; // Velocidad en el eje X
float vy; // Velocidad en el eje Y
int x1; // Limite izquierdo de la ruta en el eje X
int x2; // Limite derecho de la ruta en el eje X
int y1; // Limite superior de la ruta en el eje Y
int y2; // Limite inferior de la ruta en el eje Y
bool flip; // Indica si el enemigo hace flip al terminar su ruta
std::string color; // Color del enemigo
palette_e palette; // Paleta de colores
};
class Enemy
{
private:
// Objetos y punteros
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
Texture *texture; // Textura con los graficos del enemigo
AnimatedSprite *sprite; // Sprite del enemigo
// Variables

View File

@@ -30,7 +30,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
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);
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, debug);
player = new Player(spawnPoint, "player.png", "player.ani", renderer, resource, asset, options, input, room, debug);
eventHandler = new SDL_Event();
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
@@ -301,7 +301,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, resource, asset, options, itemTracker, &board.items, debug);
room = new Room(resource->getRoom(file), renderer, screen, asset, options, itemTracker, &board.items, debug);
// Actualiza el marcador
const color_t c = room->getBorderColor(); // Pone el color del marcador
@@ -390,7 +390,7 @@ void Game::killPlayer()
setBlackScreen();
// Crea la nueva habitación y el nuevo jugador
room = new Room(asset->get(currentRoom), renderer, screen, resource, asset, options, itemTracker, &board.items, debug);
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, debug);
player = new Player(spawnPoint, "player.png", "player.ani", renderer, resource, asset, options, input, room, debug);
room->pause();

View File

@@ -7,14 +7,8 @@ Item::Item(item_t item)
{
const int itemSize = 8;
// Obten punteros a objetos
resource = item.resource;
asset = item.asset;
renderer = item.renderer;
// Crea objetos
texture = resource->getTexture(item.tileset);
sprite = new Sprite(item.x, item.y, itemSize, itemSize, texture, renderer);
// Crea objetos;
sprite = new Sprite(item.x, item.y, itemSize, itemSize, item.texture, item.renderer);
// Inicia variables
sprite->setSpriteClip((item.tile % 10) * itemSize, (item.tile / 10) * itemSize, itemSize, itemSize);
@@ -69,7 +63,7 @@ SDL_Point Item::getPos()
// Recarga la textura
void Item::reLoadTexture()
{
texture->reLoad();
sprite->getTexture()->reLoad();
}
// Asigna los colores del objeto

View File

@@ -2,7 +2,6 @@
#include <SDL2/SDL.h>
#include "common/asset.h"
#include "common/resource.h"
#include "common/sprite.h"
#include "common/utils.h"
#include <string>
@@ -12,27 +11,22 @@
struct item_t
{
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
std::string tileset; // Fichero con los graficos del item
int x; // Posicion del item en pantalla
int y; // Posicion del item en pantalla
int tile; // Numero de tile dentro de la textura
int counter; // Contador inicial. Es el que lo hace cambiar de color
color_t color1; // Uno de los dos colores que se utiliza para el item
color_t color2; // Uno de los dos colores que se utiliza para el item
SDL_Renderer *renderer; // El renderizador de la ventana
Texture *texture; // Textura con los graficos del item
std::string tileSetFile; // Ruta al fichero con los graficos del item
int x; // Posicion del item en pantalla
int y; // Posicion del item en pantalla
int tile; // Numero de tile dentro de la textura
int counter; // Contador inicial. Es el que lo hace cambiar de color
color_t color1; // Uno de los dos colores que se utiliza para el item
color_t color2; // Uno de los dos colores que se utiliza para el item
};
class Item
{
private:
// Objetos y punteros
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
Texture *texture; // Textura con los graficos del objeto
Sprite *sprite; // Sprite del objeto
Sprite *sprite; // Sprite del objeto
// Variables
std::vector<color_t> color; // Vector con los colores del objeto

View File

@@ -3,92 +3,10 @@
#include <fstream>
#include <sstream>
// Constructor
Room::Room(std::string file, SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, ItemTracker *itemTracker, int *items, Debug *debug)
{
// Copia los punteros a objetos
this->resource = resource;
this->renderer = renderer;
this->asset = asset;
this->screen = screen;
this->itemTracker = itemTracker;
this->itemsPicked = items;
this->debug = debug;
this->options = options;
// Inicializa variables
tileSize = 8;
mapWidth = 32;
mapHeight = 16;
paused = false;
itemColor1 = "magenta";
itemColor2 = "yellow";
autoSurfaceDirection = 1;
counter = 0;
// Crea los objetos
loadMapFile(file);
//texture = new Texture(renderer, asset->get(tileset));
texture = resource->getTexture(tileset);
tilesetWidth = texture->getWidth() / tileSize;
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
loadMapTileFile(asset->get(tileMapFile));
// Calcula las superficies
setBottomSurfaces();
setTopSurfaces();
setLeftSurfaces();
setRightSurfaces();
setLeftSlopes();
setRightSlopes();
setAutoSurfaces();
// Busca los tiles animados
setAnimatedTiles();
// Crea la textura para el mapa de tiles de la habitación
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (mapTexture == nullptr)
{
printf("Error: mapTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
}
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
// Pinta el mapa de la habitación en la textura
fillMapTexture();
// Establece el color del borde
screen->setBorderColor(stringToColor(options->palette, borderColor));
}
// Destructor
Room::~Room()
{
// Reclama la memoria utilizada por los objetos
//delete texture;
JA_DeleteSound(itemSound);
SDL_DestroyTexture(mapTexture);
for (auto enemy : enemies)
{
delete enemy;
}
for (auto item : items)
{
delete item;
}
for (auto a : aTile)
{
delete a.sprite;
}
}
// Carga las variables desde un fichero de mapa
bool Room::loadMapFile(std::string file_path)
// Carga las variables y texturas desde un fichero de mapa de tiles
std::vector<int> loadRoomTileFile(std::string file_path)
{
std::vector<int> tileMapFile;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
@@ -97,18 +15,64 @@ bool Room::loadMapFile(std::string file_path)
if (file.good())
{
// Procesa el fichero linea a linea
printf("Reading file %s\n\n", filename.c_str());
//printf("Reading file %s\n", filename.c_str());
while (std::getline(file, line))
{ // Lee el fichero linea a linea
if (line.find("data encoding") != std::string::npos)
{
// Lee la primera linea
std::getline(file, line);
while (line != "</data>")
{ // Procesa lineas mientras haya
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ','))
{
tileMapFile.push_back(std::stoi(tmp) - 1);
}
// Lee la siguiente linea
std::getline(file, line);
}
}
}
// Cierra el fichero
printf("TileMap loaded: %s\n", filename.c_str());
file.close();
}
else
{ // El fichero no se puede abrir
printf("Warning: Unable to open %s file\n", filename.c_str());
}
return tileMapFile;
}
// Carga las variables desde un fichero de mapa
room_t loadRoomFile(std::string file_path)
{
room_t room;
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
// El fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
//printf("Reading file %s\n\n", filename.c_str());
while (std::getline(file, line))
{
// Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo
if (line == "[enemy]")
{
enemy_t enemy;
enemy.resource = resource;
enemy.asset = asset;
enemy.renderer = renderer;
// enemy.renderer = renderer;
enemy.flip = false;
enemy.palette = options->palette;
enemy.palette = p_zxspectrum;
do
{
@@ -116,7 +80,7 @@ bool Room::loadMapFile(std::string file_path)
// Encuentra la posición del caracter '='
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setEnemy(&enemy, line.substr(0, pos), line.substr(pos + 1, line.length())))
{
@@ -125,19 +89,17 @@ bool Room::loadMapFile(std::string file_path)
} while (line != "[/enemy]");
// Añade el enemigo al vector de enemigos
enemies.push_back(new Enemy(enemy));
room.enemies.push_back(enemy);
}
// Si la linea contiene el texto [item] se realiza el proceso de carga de un item
else if (line == "[item]")
{
item_t item;
item.resource = resource;
item.asset = asset;
item.renderer = renderer;
// item.renderer = renderer;
item.counter = 0;
item.color1 = stringToColor(options->palette, itemColor1);
item.color2 = stringToColor(options->palette, itemColor2);
item.color1 = stringToColor(p_zxspectrum, "yellow");
item.color2 = stringToColor(p_zxspectrum, "magenta");
do
{
@@ -155,11 +117,12 @@ bool Room::loadMapFile(std::string file_path)
} while (line != "[/item]");
// Añade el item al vector de items
const SDL_Point itemPos = {item.x, item.y};
if (!itemTracker->hasBeenPicked(name, itemPos))
{
items.push_back(new Item(item));
}
// const SDL_Point itemPos = {item.x, item.y};
// if (!itemTracker->hasBeenPicked(room.name, itemPos))
//{
// room.items.push_back(new Item(item));
// }
room.items.push_back(item);
}
// En caso contrario se parsea el fichero para buscar las variables y los valores
@@ -168,7 +131,7 @@ bool Room::loadMapFile(std::string file_path)
// Encuentra la posición del caracter '='
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length())))
if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length())))
{
printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str());
}
@@ -176,149 +139,100 @@ bool Room::loadMapFile(std::string file_path)
}
// Cierra el fichero
printf("Closing file %s\n\n", filename.c_str());
printf("Room loaded: %s\n", filename.c_str());
file.close();
}
// El fichero no se puede abrir
else
{
printf("Warning: Unable to open %s file\n", filename.c_str());
return false;
}
return true;
}
// Carga las variables y texturas desde un fichero de mapa de tiles
bool Room::loadMapTileFile(std::string file_path)
{
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
std::string line;
std::ifstream file(file_path);
// El fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
printf("Reading file %s\n", filename.c_str());
while (std::getline(file, line))
{ // Lee el fichero linea a linea
if (line.find("data encoding") != std::string::npos)
{
// Lee la primera linea
std::getline(file, line);
while (line != "</data>")
{ // Procesa lineas mientras haya
std::stringstream ss(line);
std::string tmp;
while (getline(ss, tmp, ','))
{
tilemap.push_back(std::stoi(tmp) - 1);
}
// Lee la siguiente linea
std::getline(file, line);
}
}
}
// Cierra el fichero
printf("Closing file %s\n\n", filename.c_str());
file.close();
}
else
{ // El fichero no se puede abrir
printf("Warning: Unable to open %s file\n", filename.c_str());
return false;
}
return true;
return room;
}
// Asigna variables a partir de dos cadenas
bool Room::setVars(std::string var, std::string value)
bool setVars(room_t *room, std::string var, std::string value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tilemap")
if (var == "tileMapFile")
{
tileMapFile = value;
room->tileMapFile = value;
}
else if (var == "name")
{
name = value;
room->name = value;
}
else if (var == "bgColor")
{
bgColor = value;
room->bgColor = value;
}
else if (var == "border")
{
borderColor = value;
room->borderColor = value;
}
else if (var == "itemColor1")
{
itemColor1 = value;
room->itemColor1 = value;
}
else if (var == "itemColor2")
{
itemColor2 = value;
room->itemColor2 = value;
}
else if (var == "tileset")
else if (var == "tileSetFile")
{
tileset = value;
if (options->palette == p_zxspectrum)
room->tileSetFile = value;
/*if (options->palette == p_zxspectrum)
{
tileset = "standard.png";
tileSetFile = "standard.png";
}
else if (options->palette == p_zxarne)
{
tileset = "standard_zxarne.png";
}
tileSetFile = "standard_zxarne.png";
}*/
}
else if (var == "roomUp")
{
roomUp = value;
room->roomUp = value;
}
else if (var == "roomDown")
{
roomDown = value;
room->roomDown = value;
}
else if (var == "roomLeft")
{
roomLeft = value;
room->roomLeft = value;
}
else if (var == "roomRight")
{
roomRight = value;
room->roomRight = value;
}
else if (var == "autoSurface")
{
if (value == "right")
{
autoSurfaceDirection = 1;
room->autoSurfaceDirection = 1;
}
else
{
autoSurfaceDirection = -1;
room->autoSurfaceDirection = -1;
}
}
else if (var == "")
else if (var == "" || var.substr(0, 1) == "#")
{
}
@@ -331,19 +245,14 @@ bool Room::setVars(std::string var, std::string value)
}
// Asigna variables a una estructura enemy_t
bool Room::setEnemy(enemy_t *enemy, std::string var, std::string value)
bool setEnemy(enemy_t *enemy, std::string var, std::string value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileset")
if (var == "animation")
{
enemy->tileset = value;
}
else if (var == "animation")
{
enemy->animation = value;
enemy->animationString = value;
}
else if (var == "width")
@@ -406,7 +315,7 @@ bool Room::setEnemy(enemy_t *enemy, std::string var, std::string value)
enemy->color = value;
}
else if (var == "[/enemy]")
else if (var == "[/enemy]" || var == "tileSetFile" || var.substr(0, 1) == "#")
{
}
@@ -419,14 +328,14 @@ bool Room::setEnemy(enemy_t *enemy, std::string var, std::string value)
}
// Asigna variables a una estructura item_t
bool Room::setItem(item_t *item, std::string var, std::string value)
bool setItem(item_t *item, std::string var, std::string value)
{
// Indicador de éxito en la asignación
bool success = true;
if (var == "tileset")
if (var == "tileSetFile")
{
item->tileset = value;
item->tileSetFile = value;
}
else if (var == "counter")
@@ -461,6 +370,132 @@ bool Room::setItem(item_t *item, std::string var, std::string value)
return success;
}
// Constructor
Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, ItemTracker *itemTracker, int *itemsPicked, Debug *debug)
{
// Copia los punteros a objetos
this->renderer = renderer;
this->asset = asset;
this->screen = screen;
this->itemTracker = itemTracker;
this->itemsPicked = itemsPicked;
this->debug = debug;
this->options = options;
name = room->name;
bgColor = room->bgColor;
borderColor = room->borderColor;
itemColor1 = room->itemColor1 == ""?"yellow":room->itemColor1;
itemColor2 = room->itemColor2 == ""?"magenta":room->itemColor2;
roomUp = room->roomUp;
roomDown = room->roomDown;
roomLeft = room->roomLeft;
roomRight = room->roomRight;
tileSetFile = room->tileSetFile;
tileMapFile = room->tileMapFile;
autoSurfaceDirection = room->autoSurfaceDirection;
textureA = room->textureA;
textureB = room->textureB;
tileMap = room->tileMap;
// Inicializa variables
tileSize = 8;
mapWidth = 32;
mapHeight = 16;
paused = false;
counter = 0;
// itemColor1 = "magenta";
// itemColor2 = "yellow";
// autoSurfaceDirection = 1;
// Crea los enemigos
for (auto &enemy : room->enemies)
{
enemy.renderer = renderer;
enemies.push_back(new Enemy(enemy));
}
// Crea los items
for (auto &item : room->items)
{
const SDL_Point itemPos = {item.x, item.y};
if (!itemTracker->hasBeenPicked(room->name, itemPos))
{
item.renderer = renderer;
items.push_back(new Item(item));
}
}
// Crea los objetos
// loadRoomFile(file);
// texture = new Texture(renderer, asset->get(tileSetFile));
// texture = resource->getTexture(tileSetFile);
if (options->palette == p_zxspectrum)
{
texture = textureA;
}
else
{
texture = textureB;
}
tileSetWidth = texture->getWidth() / tileSize;
itemSound = JA_LoadSound(asset->get("item.wav").c_str());
// loadRoomTileFile(asset->get(tileMapFile));
// Calcula las superficies
setBottomSurfaces();
setTopSurfaces();
setLeftSurfaces();
setRightSurfaces();
setLeftSlopes();
setRightSlopes();
setAutoSurfaces();
// Busca los tiles animados
setAnimatedTiles();
// Crea la textura para el mapa de tiles de la habitación
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
if (mapTexture == nullptr)
{
printf("Error: mapTexture could not be created!\nSDL Error: %s\n", SDL_GetError());
}
SDL_SetTextureBlendMode(mapTexture, SDL_BLENDMODE_BLEND);
// Pinta el mapa de la habitación en la textura
fillMapTexture();
// Establece el color del borde
screen->setBorderColor(stringToColor(options->palette, room->borderColor));
}
// Destructor
Room::~Room()
{
// Reclama la memoria utilizada por los objetos
// delete texture;
JA_DeleteSound(itemSound);
SDL_DestroyTexture(mapTexture);
for (auto enemy : enemies)
{
delete enemy;
}
for (auto item : items)
{
delete item;
}
for (auto a : aTile)
{
delete a.sprite;
}
}
// Devuelve el nombre de la habitación
std::string Room::getName()
{
@@ -486,7 +521,7 @@ void Room::fillMapTexture()
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
SDL_RenderClear(renderer);
// Los tilesets son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
// Los tileSetFiles son de 20x20 tiles. El primer tile es el 0. Cuentan hacia la derecha y hacia abajo
SDL_Rect clip = {0, 0, tileSize, tileSize};
for (int y = 0; y < mapHeight; ++y)
@@ -496,13 +531,13 @@ void Room::fillMapTexture()
// Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1
// Tampoco hay que dibujar los tiles animados que estan en la fila 19 (indices)
const int index = (y * mapWidth) + x;
const bool a = (tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 19 * tilesetWidth);
const bool b = tilemap[index] > -1;
const bool a = (tileMap->at(index) >= 18 * tileSetWidth) && (tileMap->at(index) < 19 * tileSetWidth);
const bool b = tileMap->at(index) > -1;
if (b && !a)
{
clip.x = (tilemap[index] % tilesetWidth) * tileSize;
clip.y = (tilemap[index] / tilesetWidth) * tileSize;
clip.x = (tileMap->at(index) % tileSetWidth) * tileSize;
clip.y = (tileMap->at(index) / tileSetWidth) * tileSize;
texture->render(renderer, x * tileSize, y * tileSize, &clip);
// ****
@@ -702,37 +737,37 @@ tile_e Room::getTile(int index)
if (index < maxTile)
{
// Las filas 0-8 son de tiles t_wall
if ((tilemap[index] >= 0) && (tilemap[index] < 9 * tilesetWidth))
if ((tileMap->at(index) >= 0) && (tileMap->at(index) < 9 * tileSetWidth))
{
return t_wall;
}
// Las filas 9-17 son de tiles t_passable
else if ((tilemap[index] >= 9 * tilesetWidth) && (tilemap[index] < 18 * tilesetWidth))
else if ((tileMap->at(index) >= 9 * tileSetWidth) && (tileMap->at(index) < 18 * tileSetWidth))
{
return t_passable;
}
// Las filas 18-20 es de tiles t_animated
else if ((tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 21 * tilesetWidth))
else if ((tileMap->at(index) >= 18 * tileSetWidth) && (tileMap->at(index) < 21 * tileSetWidth))
{
return t_animated;
}
// La fila 21 es de tiles t_slope_r
else if ((tilemap[index] >= 21 * tilesetWidth) && (tilemap[index] < 22 * tilesetWidth))
else if ((tileMap->at(index) >= 21 * tileSetWidth) && (tileMap->at(index) < 22 * tileSetWidth))
{
return t_slope_r;
}
// La fila 22 es de tiles t_slope_l
else if ((tilemap[index] >= 22 * tilesetWidth) && (tilemap[index] < 23 * tilesetWidth))
else if ((tileMap->at(index) >= 22 * tileSetWidth) && (tileMap->at(index) < 23 * tileSetWidth))
{
return t_slope_l;
}
// La fila 23 es de tiles t_kill
else if ((tilemap[index] >= 23 * tilesetWidth) && (tilemap[index] < 24 * tilesetWidth))
else if ((tileMap->at(index) >= 23 * tileSetWidth) && (tileMap->at(index) < 24 * tileSetWidth))
{
return t_kill;
}
@@ -776,19 +811,7 @@ bool Room::itemCollision(SDL_Rect &rect)
// Recarga la textura
void Room::reLoadTexture()
{
if (options->palette == p_zxspectrum)
{
//texture->loadFromFile(asset->get("standard.png"), renderer);
texture = resource->getTexture("standard.png");
texture->reLoad();
}
else if (options->palette == p_zxarne)
{
//texture->loadFromFile(asset->get("standard_zxarne.png"), renderer);
texture = resource->getTexture("standard_zxarne.png");
texture->reLoad();
}
texture->reLoad();
fillMapTexture();
for (auto enemy : enemies)
@@ -806,20 +829,30 @@ void Room::reLoadTexture()
void Room::reLoadPalette()
{
// Cambia el color de los items
for (auto item:items)
for (auto item : items)
{
item->setColors(stringToColor(options->palette, itemColor1), stringToColor(options->palette, itemColor2));
}
// Cambia el color de los enemigos
for (auto enemy:enemies)
for (auto enemy : enemies)
{
enemy->setPalette(options->palette);
}
// Establece el color del borde
screen->setBorderColor(stringToColor(options->palette, borderColor));
// Cambia la textura
if (options->palette == p_zxspectrum)
{
texture = textureA;
}
else
{
texture = textureB;
}
// Recarga las texturas
reLoadTexture();
}
@@ -863,7 +896,7 @@ void Room::setBottomSurfaces()
// Busca todos los tiles de tipo muro que no tengan debajo otro muro
// Hay que recorrer la habitación por filas (excepto los de la última fila)
for (int i = 0; i < (int)tilemap.size() - mapWidth; ++i)
for (int i = 0; i < (int)tileMap->size() - mapWidth; ++i)
{
if (getTile(i) == t_wall && getTile(i + mapWidth) != t_wall)
{
@@ -883,12 +916,12 @@ void Room::setBottomSurfaces()
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
line.x1 = (tile.at(i) % mapWidth) * tileSize;
line.y = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
lastOne = i;
i++;
while (tile[i] == tile[i - 1] + 1)
while (tile.at(i) == tile.at(i - 1) + 1)
{
lastOne = i;
i++;
@@ -896,7 +929,7 @@ void Room::setBottomSurfaces()
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
bottomSurfaces.push_back(line);
if (tile[i] == -1)
if (tile.at(i) == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
}
@@ -910,7 +943,7 @@ void Room::setTopSurfaces()
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < (int)tilemap.size(); ++i)
for (int i = mapWidth; i < (int)tileMap->size(); ++i)
{
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - mapWidth) != t_wall)
{
@@ -930,12 +963,12 @@ void Room::setTopSurfaces()
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
line.x1 = (tile.at(i) % mapWidth) * tileSize;
line.y = (tile.at(i) / mapWidth) * tileSize;
lastOne = i;
i++;
while (tile[i] == tile[i - 1] + 1)
while (tile.at(i) == tile.at(i - 1) + 1)
{
lastOne = i;
i++;
@@ -943,7 +976,7 @@ void Room::setTopSurfaces()
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
topSurfaces.push_back(line);
if (tile[i] == -1)
if (tile.at(i) == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
}
@@ -976,13 +1009,13 @@ void Room::setLeftSurfaces()
while (i < (int)tile.size())
{
v_line_t line;
line.x = (tile[i] % mapWidth) * tileSize;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
line.x = (tile.at(i) % mapWidth) * tileSize;
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
while (tile.at(i) + mapWidth == tile[i + 1])
{
i++;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
leftSurfaces.push_back(line);
i++;
}
@@ -1014,13 +1047,13 @@ void Room::setRightSurfaces()
while (i < (int)tile.size())
{
v_line_t line;
line.x = ((tile[i] % mapWidth) * tileSize) + tileSize - 1;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1;
line.y1 = ((tile.at(i) / mapWidth) * tileSize);
while (tile.at(i) + mapWidth == tile[i + 1])
{
i++;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1;
rightSurfaces.push_back(line);
i++;
}
@@ -1031,7 +1064,7 @@ void Room::setLeftSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_l
std::vector<int> found;
for (int i = 0; i < (int)tilemap.size(); ++i)
for (int i = 0; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_slope_l)
{
@@ -1072,7 +1105,7 @@ void Room::setRightSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_r
std::vector<int> found;
for (int i = 0; i < (int)tilemap.size(); ++i)
for (int i = 0; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_slope_r)
{
@@ -1115,7 +1148,7 @@ void Room::setAutoSurfaces()
// Busca todos los tiles de tipo animado
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < (int)tilemap.size(); ++i)
for (int i = mapWidth; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_animated)
{
@@ -1135,12 +1168,12 @@ void Room::setAutoSurfaces()
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
line.x1 = (tile.at(i) % mapWidth) * tileSize;
line.y = (tile.at(i) / mapWidth) * tileSize;
lastOne = i;
i++;
while (tile[i] == tile[i - 1] + 1)
while (tile.at(i) == tile.at(i - 1) + 1)
{
lastOne = i;
i++;
@@ -1148,7 +1181,7 @@ void Room::setAutoSurfaces()
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
autoSurfaces.push_back(line);
if (tile[i] == -1)
if (tile.at(i) == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
}
@@ -1159,17 +1192,17 @@ void Room::setAutoSurfaces()
void Room::setAnimatedTiles()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_animated
for (int i = 0; i < (int)tilemap.size(); ++i)
for (int i = 0; i < (int)tileMap->size(); ++i)
{
if (getTile(i) == t_animated)
{
// la i me da la ubicación
// La i es la ubicación
const int x = (i % mapWidth) * tileSize;
const int y = (i / mapWidth) * tileSize;
// tilemap[i] me da el tile a poner
const int xc = (tilemap[i] % tilesetWidth) * tileSize;
const int yc = (tilemap[i] / tilesetWidth) * tileSize;
// TileMap->at(i) es el tile a poner
const int xc = (tileMap->at(i) % tileSetWidth) * tileSize;
const int yc = (tileMap->at(i) / tileSetWidth) * tileSize;
aTile_t at;
at.sprite = new Sprite(x, y, 8, 8, texture, renderer);

View File

@@ -4,7 +4,6 @@
#include "common/asset.h"
#include "common/debug.h"
#include "common/jail_audio.h"
#include "common/resource.h"
#include "common/screen.h"
#include "common/sprite.h"
#include "common/utils.h"
@@ -35,14 +34,52 @@ struct aTile_t
int xcOrig; // Poicion X donde se encuentra el primer tile de la animacion en la tilesheet
};
struct room_t
{
std::string name; // Nombre de la habitación
std::string bgColor; // Color de fondo de la habitación
std::string borderColor; // Color del borde de la pantalla
std::string itemColor1; // Color 1 para los items de la habitación
std::string itemColor2; // Color 2 para los items de la habitación
std::string roomUp; // Identificador de la habitación que se encuentra arriba
std::string roomDown; // Identificador de la habitación que se encuentra abajp
std::string roomLeft; // Identificador de la habitación que se encuentra a la izquierda
std::string roomRight; // Identificador de la habitación que se encuentra a la derecha
std::string tileSetFile; // Imagen con los graficos para la habitación
std::string tileMapFile; // Fichero con el mapa de indices de tile
std::vector<int> *tileMap; // Indice de los tiles a dibujar en la habitación
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
std::vector<enemy_t> enemies; // Listado con los enemigos de la habitación
std::vector<item_t> items; // Listado con los items que hay en la habitación
Texture *textureA; // Textura con los graficos de la habitación
Texture *textureB; // Textura con los graficos de la habitación
};
// Carga las variables desde un fichero de mapa
room_t loadRoomFile(std::string file);
// Carga las variables y texturas desde un fichero de mapa de tiles
std::vector<int> loadRoomTileFile(std::string file_path);
// Asigna variables a partir de dos cadenas
bool setVars(room_t *room, std::string var, std::string value);
// Asigna variables a una estructura enemy_t
bool setEnemy(enemy_t *enemy, std::string var, std::string value);
// Asigna variables a una estructura item_t
bool setItem(item_t *item, std::string var, std::string value);
class Room
{
private:
// Objetos y punteros
std::vector<Enemy *> enemies; // Listado con los enemigos de la habitación
std::vector<Item *> items; // Listado con los items que hay en la habitación
std::vector<int> *tileMap; // Indice de los tiles a dibujar en la habitación
Texture *texture; // Textura con los graficos de la habitación
Resource *resource; // Objeto con los recursos
Texture *textureA; // Textura con los graficos de la habitación
Texture *textureB; // Textura con los graficos de la habitación
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
Screen *screen; // Objeto encargado de dibujar en pantalla
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
@@ -62,9 +99,9 @@ private:
std::string roomDown; // Identificador de la habitación que se encuentra abajp
std::string roomLeft; // Identificador de la habitación que se encuentra a la izquierda
std::string roomRight; // Identificador de la habitación que se encuentra a la derecha
std::string tileset; // Imagen con los graficos para la habitación
std::string tileSetFile; // Imagen con los graficos para la habitación
std::string tileMapFile; // Fichero con el mapa de indices de tile
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
JA_Sound itemSound; // Sonido producido al coger un objeto
std::vector<h_line_t> bottomSurfaces; // Lista con las superficies inferiores de la habitación
std::vector<h_line_t> topSurfaces; // Lista con las superficies superiores de la habitación
@@ -76,26 +113,10 @@ private:
bool paused; // Indica si el mapa esta en modo pausa
std::vector<aTile_t> aTile; // Vector con los indices de tiles animados
std::vector<h_line_t> autoSurfaces; // Lista con las superficies automaticas de la habitación
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
int tileSize; // Ancho del tile en pixels
int mapWidth; // Ancho del mapa en tiles
int mapHeight; // Alto del mapa en tiles
int tilesetWidth; // Ancho del tileset en tiles
// Carga las variables desde un fichero de mapa
bool loadMapFile(std::string file);
// Carga las variables y texturas desde un fichero de mapa de tiles
bool loadMapTileFile(std::string file);
// Asigna variables a partir de dos cadenas
bool setVars(std::string var, std::string value);
// Asigna variables a una estructura enemy_t
bool setEnemy(enemy_t *enemy, std::string var, std::string value);
// Asigna variables a una estructura item_t
bool setItem(item_t *item, std::string var, std::string value);
int tileSetWidth; // Ancho del tileset en tiles
// Pinta el mapa de la habitación en la textura
void fillMapTexture();
@@ -135,7 +156,7 @@ private:
public:
// Constructor
Room(std::string file, SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, ItemTracker *item_tracker, int *items, Debug *debug);
Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, ItemTracker *itemTracker, int *itemsPicked, Debug *debug);
// Destructor
~Room();

View File

@@ -39,7 +39,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
l.enabled = false;
letters.push_back(l);
}
letters[0].enabled = true;
letters.at(0).enabled = true;
marqueeSpeed = 3;
// Cambia el color del borde