forked from jaildesigner-jailgames/jaildoctors_dilemma
La habitación ya empieza a mostrar algo del mapeado
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
id=1
|
id=1
|
||||||
name=Test Room
|
name=Test Room
|
||||||
bg_color=black
|
bg_color=cyan
|
||||||
tileset=1
|
tileset=room1.png
|
||||||
limit_up=0
|
room_up=0
|
||||||
limit_down=0
|
room_down=0
|
||||||
limit_left=0
|
room_left=0
|
||||||
limit_right=2
|
room_right=2
|
||||||
tilemap=67,67,89,92,93
|
tilemap=0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
|
||||||
enemy=1,0,0,0,1
|
enemy=1,0,0,0,1
|
||||||
enemy=2,10,0,0,1
|
enemy=2,10,0,0,1
|
||||||
item=1,10,10
|
item=1,10,10
|
||||||
@@ -2,10 +2,10 @@ id=2
|
|||||||
name=Test Room 2
|
name=Test Room 2
|
||||||
bg_color=blue
|
bg_color=blue
|
||||||
tileset=1
|
tileset=1
|
||||||
limit_up=0
|
room_up=0
|
||||||
limit_down=
|
room_down=
|
||||||
limit_left=1
|
room_left=1
|
||||||
limit_right=0
|
room_right=0
|
||||||
tilemap=67,67,89,92,93
|
tilemap=67,67,89,92,93
|
||||||
enemy=1,0,0,0,1
|
enemy=1,0,0,0,1
|
||||||
enemy=2,10,0,0,1
|
enemy=2,10,0,0,1
|
||||||
|
|||||||
BIN
media/tilesets/room1.png
Normal file
BIN
media/tilesets/room1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 583 B |
@@ -28,6 +28,7 @@ std::string Asset::get(std::string text)
|
|||||||
if (mFileList[i].file.find(text) != std::string::npos)
|
if (mFileList[i].file.find(text) != std::string::npos)
|
||||||
return mFileList[i].file;
|
return mFileList[i].file;
|
||||||
|
|
||||||
|
printf("Warning: file %s not found\n", text.c_str());
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ void Director::setFileList()
|
|||||||
mAsset->add("/data/config.bin", data, false);
|
mAsset->add("/data/config.bin", data, false);
|
||||||
mAsset->add("/data/room/01.room", room);
|
mAsset->add("/data/room/01.room", room);
|
||||||
mAsset->add("/data/room/02.room", room);
|
mAsset->add("/data/room/02.room", room);
|
||||||
|
mAsset->add("/media/tilesets/room1.png", bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
// Carga el fichero de configuración
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(SDL_Window *window,SDL_Renderer *renderer, Asset *asset, Lang *lang, Input *input)
|
Game::Game(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, Lang *lang, Input *input)
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
// Copia los punteros
|
||||||
mRenderer = renderer;
|
mRenderer = renderer;
|
||||||
@@ -10,7 +10,7 @@ Game::Game(SDL_Window *window,SDL_Renderer *renderer, Asset *asset, Lang *lang,
|
|||||||
mInput = input;
|
mInput = input;
|
||||||
|
|
||||||
mScreen = new Screen(window, renderer);
|
mScreen = new Screen(window, renderer);
|
||||||
mRoom = new Room();
|
mRoom = new Room(mAsset->get("01.room"), mRenderer, mAsset);
|
||||||
mEventHandler = new SDL_Event();
|
mEventHandler = new SDL_Event();
|
||||||
mTextureText = new LTexture();
|
mTextureText = new LTexture();
|
||||||
mText = new Text(mAsset->get("nokia2.txt"), mTextureText, renderer);
|
mText = new Text(mAsset->get("nokia2.txt"), mTextureText, renderer);
|
||||||
@@ -100,13 +100,16 @@ section_t Game::run()
|
|||||||
const color_t color = {0xAA, 0x55, 0x55};
|
const color_t color = {0xAA, 0x55, 0x55};
|
||||||
mScreen->start();
|
mScreen->start();
|
||||||
mScreen->clean(color);
|
mScreen->clean(color);
|
||||||
|
mScreen->clean(mRoom->getBGColor());
|
||||||
|
|
||||||
|
mRoom->draw();
|
||||||
|
|
||||||
// Escribe las medidas de ancho y alto de la pantalla
|
// Escribe las medidas de ancho y alto de la pantalla
|
||||||
mText->writeCentered(GAMECANVAS_CENTER_X, 0, std::to_string(GAMECANVAS_WIDTH), -1);
|
mText->writeCentered(GAMECANVAS_CENTER_X, 0, std::to_string(GAMECANVAS_WIDTH), -1);
|
||||||
mText->write(0, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), std::to_string(GAMECANVAS_HEIGHT), -1);
|
mText->write(0, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), std::to_string(GAMECANVAS_HEIGHT), -1);
|
||||||
|
|
||||||
// Texto en el centro de la pantalla
|
// Texto en el centro de la pantalla
|
||||||
mText->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), "New JailGame", -1);
|
mText->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y - (mText->getCharacterWidth() / 2), mRoom->getName(), -1);
|
||||||
|
|
||||||
// Actualiza la pantalla
|
// Actualiza la pantalla
|
||||||
mScreen->blit();
|
mScreen->blit();
|
||||||
|
|||||||
163
source/room.cpp
163
source/room.cpp
@@ -1,11 +1,168 @@
|
|||||||
#include "Map.h"
|
#include "room.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Map::Map()
|
Room::Room(std::string _file_path, SDL_Renderer *_renderer, Asset *_asset)
|
||||||
{
|
{
|
||||||
|
texture = new LTexture();
|
||||||
|
asset = _asset;
|
||||||
|
renderer = _renderer;
|
||||||
|
load(_file_path);
|
||||||
|
loadTextureFromFile(texture, asset->get(tileset), renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Map::~Map()
|
Room::~Room()
|
||||||
{
|
{
|
||||||
|
texture->unload();
|
||||||
|
delete texture;
|
||||||
|
texture = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga una habitación desde un fichero
|
||||||
|
bool Room::load(std::string _file_path)
|
||||||
|
{
|
||||||
|
// Indicador de éxito en la carga
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
// Carga los datos
|
||||||
|
printf("Reading file %s\n", filename.c_str());
|
||||||
|
while (std::getline(file, line))
|
||||||
|
{
|
||||||
|
int pos = line.find("=");
|
||||||
|
if (!setVars(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());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
printf("Closing file %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());
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asigna variables a partir de dos cadenas
|
||||||
|
bool Room::setVars(std::string _var, std::string _value)
|
||||||
|
{
|
||||||
|
// Indicador de éxito en la asignación
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
if (_var == "id")
|
||||||
|
{
|
||||||
|
id = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "name")
|
||||||
|
{
|
||||||
|
name = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "bg_color")
|
||||||
|
{
|
||||||
|
bg_color = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "tileset")
|
||||||
|
{
|
||||||
|
tileset = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "room_up")
|
||||||
|
{
|
||||||
|
room_up = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "room_down")
|
||||||
|
{
|
||||||
|
room_down = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "room_left")
|
||||||
|
{
|
||||||
|
room_left = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "room_right")
|
||||||
|
{
|
||||||
|
room_right = _value;
|
||||||
|
}
|
||||||
|
else if (_var == "tilemap")
|
||||||
|
{
|
||||||
|
std::stringstream ss(_value);
|
||||||
|
std::string tmp;
|
||||||
|
while (getline(ss, tmp, ','))
|
||||||
|
{
|
||||||
|
// printf("text - %s\n",tmp.c_str());
|
||||||
|
tilemap.push_back(std::stoi(tmp));
|
||||||
|
// printf("int - %i\n",std::stoi(tmp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el nombre de la habitación
|
||||||
|
std::string Room::getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el color de la habitación
|
||||||
|
color_t Room::getBGColor()
|
||||||
|
{
|
||||||
|
color_t color = {0x00, 0x00, 0x00};
|
||||||
|
if (bg_color == "white")
|
||||||
|
{
|
||||||
|
color = {0xFF, 0xFF, 0xFF};
|
||||||
|
}
|
||||||
|
else if (bg_color == "red")
|
||||||
|
{
|
||||||
|
color = {0xFF, 0x00, 0x00};
|
||||||
|
}
|
||||||
|
else if (bg_color == "green")
|
||||||
|
{
|
||||||
|
color = {0x00, 0xFF, 0x00};
|
||||||
|
}
|
||||||
|
else if (bg_color == "blue")
|
||||||
|
{
|
||||||
|
color = {0x00, 0x00, 0xFF};
|
||||||
|
}
|
||||||
|
else if (bg_color == "yellow")
|
||||||
|
{
|
||||||
|
color = {0xFF, 0xFF, 0x00};
|
||||||
|
}
|
||||||
|
else if (bg_color == "cyan")
|
||||||
|
{
|
||||||
|
color = {0x00, 0xFF, 0xFF};
|
||||||
|
}
|
||||||
|
else if (bg_color == "purple")
|
||||||
|
{
|
||||||
|
color = {0xFF, 0x00, 0xFF};
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja la habitación en pantalla
|
||||||
|
void Room::draw()
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
SDL_Rect clip = {0, 0, 8, 8};
|
||||||
|
texture->render(renderer,x, y, &clip);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ifdefs.h"
|
#include "ifdefs.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "asset.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -24,20 +26,42 @@ LISTADO DE ITEMS (tipo, posicion)
|
|||||||
class Room
|
class Room
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int id; // Identificador
|
std::string id; // Identificador
|
||||||
std::string name; // Nombre de la habitación
|
std::string name; // Nombre de la habitación
|
||||||
std::string bg_color; // Color de fondo de la habitación
|
std::string bg_color; // Color de fondo de la habitación
|
||||||
|
std::string room_up; // Identificador de la habitación que se encuentra arriba
|
||||||
|
std::string room_down; // Identificador de la habitación que se encuentra abajp
|
||||||
|
std::string room_left; // Identificador de la habitación que se encuentra a la izquierda
|
||||||
|
std::string room_right; // Identificador de la habitación que se encuentra a la derecha
|
||||||
std::string tileset; // Imagen con los graficos para la habitación
|
std::string tileset; // Imagen con los graficos para la habitación
|
||||||
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
|
std::vector<int> tilemap; // Indice de los tiles a dibujar en la habitación
|
||||||
std::vector<int> enemy_list; // Listado con los enemigos de la habitación
|
std::vector<int> enemy_list; // Listado con los enemigos de la habitación
|
||||||
std::vector<int> item_list; // Listado con los items que hay en la habitación
|
std::vector<int> item_list; // Listado con los items que hay en la habitación
|
||||||
|
LTexture *texture; // Textura con los graficos de la habitación
|
||||||
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
|
||||||
|
// Carga una habitación desde un fichero
|
||||||
|
bool load(std::string _file_path);
|
||||||
|
|
||||||
|
// Asigna variables a partir de dos cadenas
|
||||||
|
bool setVars(std::string _var, std::string _value);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Room();
|
Room(std::string _file_path, SDL_Renderer *_renderer, Asset *_asset);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Room();
|
~Room();
|
||||||
|
|
||||||
|
// Devuelve el nombre de la habitación
|
||||||
|
std::string getName();
|
||||||
|
|
||||||
|
// Devuelve el color de la habitación
|
||||||
|
color_t getBGColor();
|
||||||
|
|
||||||
|
// Dibuja la habitación en pantalla
|
||||||
|
void draw();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user