From 5530502bcfb7b52395a6984f5f7b7d49b60449f8 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 1 Jul 2022 21:26:43 +0200 Subject: [PATCH] cambiado el nombre de map.h a room.h --- data/room/01.room | 12 ++++++++++ data/room/02.room | 12 ++++++++++ source/asset.cpp | 17 ++++++++++---- source/asset.h | 3 +++ source/director.cpp | 10 ++++----- source/game.cpp | 6 ++--- source/game.h | 14 ++++++------ source/map.h | 22 ------------------ source/{map.cpp => room.cpp} | 0 source/room.h | 43 ++++++++++++++++++++++++++++++++++++ 10 files changed, 97 insertions(+), 42 deletions(-) create mode 100644 data/room/01.room create mode 100644 data/room/02.room delete mode 100644 source/map.h rename source/{map.cpp => room.cpp} (100%) create mode 100644 source/room.h diff --git a/data/room/01.room b/data/room/01.room new file mode 100644 index 0000000..63c8f42 --- /dev/null +++ b/data/room/01.room @@ -0,0 +1,12 @@ +id=1 +name=Test Room +bg_color=black +tileset=1 +limit_up=0 +limit_down=0 +limit_left=0 +limit_right=2 +tilemap=67,67,89,92,93 +enemy=1,0,0,0,1 +enemy=2,10,0,0,1 +item=1,10,10 \ No newline at end of file diff --git a/data/room/02.room b/data/room/02.room new file mode 100644 index 0000000..e8e2721 --- /dev/null +++ b/data/room/02.room @@ -0,0 +1,12 @@ +id=2 +name=Test Room 2 +bg_color=blue +tileset=1 +limit_up=0 +limit_down= +limit_left=1 +limit_right=0 +tilemap=67,67,89,92,93 +enemy=1,0,0,0,1 +enemy=2,10,0,0,1 +item=1,10,10 \ No newline at end of file diff --git a/source/asset.cpp b/source/asset.cpp index 608009b..a2cbef5 100644 --- a/source/asset.cpp +++ b/source/asset.cpp @@ -47,10 +47,10 @@ bool Asset::check() } // Resultado - if (success) - printf("\n** All files OK.\n\n"); - else - printf("\n** A file is missing. Exiting.\n\n"); + if (success) + printf("\n** All files OK.\n\n"); + else + printf("\n** A file is missing. Exiting.\n\n"); return success; } @@ -101,6 +101,15 @@ std::string Asset::getTypeName(int type) case data: return "DATA"; break; + case room: + return "ROOM"; + break; + case enemy: + return "ENEMY"; + break; + case item: + return "ITEM"; + break; default: return "ERROR"; break; diff --git a/source/asset.h b/source/asset.h index 5eaba36..8ed626d 100644 --- a/source/asset.h +++ b/source/asset.h @@ -14,6 +14,9 @@ enum assetType font, lang, data, + room, + enemy, + item, maxAssetType }; diff --git a/source/director.cpp b/source/director.cpp index 4705a8f..ab988ee 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -97,9 +97,7 @@ void Director::init(Uint8 name) mInput->bindKey(INPUT_RIGHT, SDL_SCANCODE_RIGHT); mInput->bindKey(INPUT_ACCEPT, SDL_SCANCODE_RETURN); mInput->bindKey(INPUT_CANCEL, SDL_SCANCODE_ESCAPE); - mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_Z); - mInput->bindKey(INPUT_BUTTON_2, SDL_SCANCODE_X); - mInput->bindKey(INPUT_BUTTON_3, SDL_SCANCODE_C); + mInput->bindKey(INPUT_BUTTON_1, SDL_SCANCODE_SPACE); mInput->bindKey(INPUT_BUTTON_PAUSE, SDL_SCANCODE_ESCAPE); mInput->bindKey(INPUT_BUTTON_ESCAPE, SDL_SCANCODE_ESCAPE); @@ -109,9 +107,7 @@ void Director::init(Uint8 name) mInput->bindGameControllerButton(INPUT_RIGHT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); mInput->bindGameControllerButton(INPUT_ACCEPT, SDL_CONTROLLER_BUTTON_B); mInput->bindGameControllerButton(INPUT_CANCEL, SDL_CONTROLLER_BUTTON_A); - mInput->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_X); - mInput->bindGameControllerButton(INPUT_BUTTON_2, SDL_CONTROLLER_BUTTON_Y); - mInput->bindGameControllerButton(INPUT_BUTTON_3, SDL_CONTROLLER_BUTTON_B); + mInput->bindGameControllerButton(INPUT_BUTTON_1, SDL_CONTROLLER_BUTTON_B); mInput->bindGameControllerButton(INPUT_BUTTON_PAUSE, SDL_CONTROLLER_BUTTON_GUIDE); mInput->bindGameControllerButton(INPUT_BUTTON_ESCAPE, SDL_CONTROLLER_BUTTON_GUIDE); } @@ -200,6 +196,8 @@ void Director::setFileList() mAsset->add("/media/lang/ba_BA.txt", lang); mAsset->add("/data/gamecontrollerdb.txt", data); mAsset->add("/data/config.bin", data, false); + mAsset->add("/data/room/01.room", room); + mAsset->add("/data/room/02.room", room); } // Carga el fichero de configuración diff --git a/source/game.cpp b/source/game.cpp index d2da821..7fffb9a 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -10,7 +10,7 @@ Game::Game(SDL_Window *window,SDL_Renderer *renderer, Asset *asset, Lang *lang, mInput = input; mScreen = new Screen(window, renderer); - mMap = new Map(); + mRoom = new Room(); mEventHandler = new SDL_Event(); mTextureText = new LTexture(); mText = new Text(mAsset->get("nokia2.txt"), mTextureText, renderer); @@ -34,8 +34,8 @@ Game::~Game() delete mScreen; mScreen = nullptr; - delete mMap; - mMap = nullptr; + delete mRoom; + mRoom = nullptr; delete mText; mText = nullptr; diff --git a/source/game.h b/source/game.h index 7987ff3..9b379ab 100644 --- a/source/game.h +++ b/source/game.h @@ -15,7 +15,7 @@ #include "lang.h" #include "screen.h" #include "asset.h" -#include "map.h" +#include "room.h" #include "jail_audio.h" #ifndef GAME_H @@ -28,21 +28,21 @@ private: SDL_Renderer *mRenderer; // El renderizador de la ventana SDL_Event *mEventHandler; // Manejador de eventos Screen *mScreen; // Objeto encargado de manejar el renderizador - Map *mMap; // Objeto encargado de gestionar el mapa del juego + Room *mRoom; // Objeto encargado de gestionar cada habitación del juego Asset *mAsset; // Objeto con la ruta a todos los ficheros de recursos Lang *mLang; // Objeto para gestionar los textos en diferentes idiomas - Input *mInput; // Manejador de entrada - Text *mText; // Fuente para los textos del juego + Input *mInput; // Objeto pata gestionar la entrada + Text *mText; // Objeto para los textos del juego Fade *mFade; // Objeto para renderizar fades - LTexture *mTextureText; // Textura para la fuente de texto Nokia grande + LTexture *mTextureText; // Textura para la fuente de texto Uint32 mTicks; // Contador de ticks para ajustar la velocidad del programa Uint8 mTicksSpeed; // Velocidad a la que se repiten los bucles del programa section_t mSection; // Seccion actual dentro del juego - // Inicializa las variables necesarias para la sección 'Game' + // Inicializa las variables void init(); - // Carga los recursos necesarios para la sección 'Game' + // Carga los recursos bool loadMedia(); public: diff --git a/source/map.h b/source/map.h deleted file mode 100644 index 8a153ec..0000000 --- a/source/map.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "ifdefs.h" -#include -#include - -#ifndef MAP_H -#define MAP_H - -// Clase Map -class Map -{ -private: - -public: - // Constructor - Map(); - - // Destructor - ~Map(); -}; - -#endif diff --git a/source/map.cpp b/source/room.cpp similarity index 100% rename from source/map.cpp rename to source/room.cpp diff --git a/source/room.h b/source/room.h new file mode 100644 index 0000000..fad6e45 --- /dev/null +++ b/source/room.h @@ -0,0 +1,43 @@ +#pragma once +#include "ifdefs.h" +#include +#include + +#ifndef ROOM_H +#define ROOM_H + +/* +Cada habitación se crea y destruye cada vez que se entra o sale de la misma +Cada habitacion si que tendra lo siguiente: +ID (numerico) +NOMBRE (texto) +COLOR DE FONDO (texto) +SET DE TILES (texto, hace referencia a un png de la colección) +LIMITE SUPERIOR (ID de la habitación superior), INFERIOR, IZQUIERDO y DERECHO +MAPA DE TILES (array con los indices de los tiles a utilizar) <-- hay que decidir si cada tile del set ya + tierne propiedades o se ponen en un mapa aparte +LISTADO DE ENEMIGOS (tipo, posicion, dx, dy) +LISTADO DE ITEMS (tipo, posicion) +*/ + +// Clase Room +class Room +{ +private: + int id; // Identificador + std::string name; // Nombre de la habitación + std::string bg_color; // Color de fondo de la habitación + std::string tileset; // Imagen con los graficos para la habitación + std::vector tilemap; // Indice de los tiles a dibujar en la habitación + std::vector enemy_list; // Listado con los enemigos de la habitación + std::vector item_list; // Listado con los items que hay en la habitación + +public: + // Constructor + Room(); + + // Destructor + ~Room(); +}; + +#endif