From 87d7bd03ff452a1dd6301ba6b78310fa57c31508 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 5 Sep 2022 10:15:07 +0200 Subject: [PATCH 1/2] =?UTF-8?q?A=C3=B1adida=20la=20paleta=20de=20spectrum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 2 +- source/input.cpp | 2 +- source/input.h | 6 +- source/item.cpp | 2 +- source/logo.h | 2 +- source/ltexture.h | 2 +- source/main.cpp | 2 +- source/screen.h | 6 +- source/text.cpp | 2 +- source/utils.cpp | 227 ++++++++++++++++++++++++++++++++------------ todo.txt | 12 +-- 11 files changed, 184 insertions(+), 81 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 516de18..90096ba 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -28,7 +28,7 @@ Director::Director(std::string path) options->filter = FILTER_NEAREST; options->vSync = true; options->screenWidth = GAMECANVAS_WIDTH * options->windowSize; - options->screenHeight = GAMECANVAS_HEIGHT * options->windowSize; + options->screenHeight = GAMECANVAS_HEIGHT * options->windowSize; options->integerScale = true; options->keepAspect = true; diff --git a/source/input.cpp b/source/input.cpp index dc8b705..59c4bb0 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -177,7 +177,7 @@ bool Input::discoverGameController() std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl; } - //mGameController = mConnectedControllers[0]; + // mGameController = mConnectedControllers[0]; SDL_GameControllerEventState(SDL_ENABLE); } diff --git a/source/input.h b/source/input.h index 5e41608..a463b34 100644 --- a/source/input.h +++ b/source/input.h @@ -49,8 +49,8 @@ private: }; GameControllerBindings_t mGameControllerBindings[17]; // Vector con las teclas asociadas a los inputs predefinidos - //SDL_GameController *mGameController; // Manejador para el mando - std::vector mConnectedControllers; + // SDL_GameController *mGameController; // Manejador para el mando + std::vector mConnectedControllers; std::vector mControllerNames; int mNumGamepads; std::string mDBpath; // Ruta al archivo gamecontrollerdb.txt @@ -72,7 +72,7 @@ public: void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button); // Comprueba si un input esta activo - bool checkInput(Uint8 input, bool repeat, int device=INPUT_USE_ANY, int index=0); + bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0); // Comprueba si hay algun mando conectado bool gameControllerFound(); diff --git a/source/item.cpp b/source/item.cpp index e97f6c1..d65dc9e 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -10,7 +10,7 @@ Item::Item(item_t item) renderer = item.renderer; // Crea objetos - texture = new LTexture(renderer,asset->get(item.tileset)); + texture = new LTexture(renderer, asset->get(item.tileset)); sprite = new Sprite(item.x, item.y, 8, 8, texture, renderer); // Inicia variables diff --git a/source/logo.h b/source/logo.h index 1f4bda3..ae3da4b 100644 --- a/source/logo.h +++ b/source/logo.h @@ -24,7 +24,7 @@ private: SDL_Event *eventHandler; // Manejador de eventos std::vector sprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES Sprite *sprite2; // Sprite para manejar la textura2 - std::vector color; // Vector con los colores para el fade + std::vector color; // Vector con los colores para el fade int counter; // Contador section_t section; // Estado del bucle principal para saber si continua o se sale int ticks; // Contador de ticks para ajustar la velocidad del programa diff --git a/source/ltexture.h b/source/ltexture.h index 87d2f75..ff23c6f 100644 --- a/source/ltexture.h +++ b/source/ltexture.h @@ -15,7 +15,7 @@ private: SDL_Renderer *renderer; // Renderizador donde dibujar la textura int width; // Ancho de la imagen int height; // Alto de la imagen - std::string path; // Ruta de la imagen de la textura + std::string path; // Ruta de la imagen de la textura public: // Constructor diff --git a/source/main.cpp b/source/main.cpp index d3e961b..17ca04d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -11,7 +11,7 @@ Empezado en Castalla el 01/07/2022. int main(int argc, char *args[]) { printf("Starting the game...\n\n"); - + // Crea el objeto Director Director *mDirector = new Director(args[0]); diff --git a/source/screen.h b/source/screen.h index d0f39e5..22c524e 100644 --- a/source/screen.h +++ b/source/screen.h @@ -8,10 +8,10 @@ struct anchor_t { - int left; // Parte izquierda de la pantalla de juego - int right; // Parte drecha de la pantalla de juego + int left; // Parte izquierda de la pantalla de juego + int right; // Parte drecha de la pantalla de juego int center; // Parte central horizontal de la pantalla de juego - int top; // Parte superior de la pantalla de juego + int top; // Parte superior de la pantalla de juego int bottom; // Parte infoerior de la pantalla de juego int middle; // Parte central vertical de la pantalla de juego }; diff --git a/source/text.cpp b/source/text.cpp index e3b8598..954d4e1 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -180,5 +180,5 @@ int Text::getCharacterWidth() // Recarga la textura void Text::reLoadTexture() { - texture->reLoad(); + texture->reLoad(); } \ No newline at end of file diff --git a/source/utils.cpp b/source/utils.cpp index dbf35d3..10c52b2 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -143,70 +143,173 @@ bool checkCollision(SDL_Point &p, SDL_Rect &r) // Devuelve un color_t a partir de un string color_t stringToColor(std::string str) { - color_t color = {0x00, 0x00, 0x00}; - if (str == "black") + const std::string palette = "spectrum"; + + if (palette = "spectrum") { - color = {0x00, 0x00, 0x00}; + if (str == "black") + { + return {0x00, 0x00, 0x00}; + } + + else if (str == "light_black") + { + return {0x00, 0x00, 0x00}; + } + + else if (str == "blue") + { + return {0x00, 0x00, 0xFF}; + } + + else if (str == "light_blue") + { + return {0x00, 0x00, 0xEE}; + } + + else if (str == "red") + { + return {0xFF, 0x00, 0x00}; + } + + else if (str == "light_red") + { + return {0xEE, 0x00, 0x00}; + } + + else if (str == "purple") + { + return {0xFF, 0x00, 0xFF}; + } + + else if (str == "light_purple") + { + return {0xEE, 0x00, 0xEE}; + } + + else if (str == "green") + { + return {0x00, 0xFF, 0x00}; + } + + else if (str == "light_green") + { + return {0x00, 0xEE, 0x00}; + } + + else if (str == "cyan") + { + return {0x00, 0xFF, 0xFF}; + } + + else if (str == "light_cyan") + { + return {0x00, 0xEE, 0xEE}; + } + + else if (str == "yellow") + { + return {0xFF, 0xFF, 0x00}; + } + + else if (str == "light_yellow") + { + return {0xEE, 0xEE, 0x00}; + } + + else if (str == "white") + { + return {0xEE, 0xEE, 0xEE}; + } + + else if (str == "light_white") + { + return {0xFF, 0xFF, 0xFF}; + } } - else if (str == "light_black") + + else { - color = {0x3C, 0x35, 0x1F}; + if (str == "black") + { + return {0x00, 0x00, 0x00}; + } + + else if (str == "light_black") + { + return {0x3C, 0x35, 0x1F}; + } + + else if (str == "blue") + { + return {0x31, 0x33, 0x90}; + } + + else if (str == "light_blue") + { + return {0x15, 0x59, 0xDB}; + } + + else if (str == "red") + { + return {0xA7, 0x32, 0x11}; + } + + else if (str == "light_red") + { + return {0xD8, 0x55, 0x25}; + } + + else if (str == "purple") + { + return {0xA1, 0x55, 0x89}; + } + + else if (str == "light_purple") + { + return {0xCD, 0x7A, 0x50}; + } + + else if (str == "green") + { + return {0x62, 0x9A, 0x31}; + } + + else if (str == "light_green") + { + return {0x9C, 0xD3, 0x3C}; + } + + else if (str == "cyan") + { + return {0x28, 0xA4, 0xCB}; + } + + else if (str == "light_cyan") + { + return {0x65, 0xDC, 0xD6}; + } + + else if (str == "yellow") + { + return {0xE8, 0xBC, 0x50}; + } + + else if (str == "light_yellow") + { + return {0xF1, 0xE7, 0x82}; + } + + else if (str == "white") + { + return {0xBF, 0xBF, 0xBD}; + } + + else if (str == "light_white") + { + return {0xF2, 0xF1, 0xED}; + } } - else if (str == "blue") - { - color = {0x31, 0x33, 0x90}; - } - else if (str == "light_blue") - { - color = {0x15, 0x59, 0xDB}; - } - else if (str == "red") - { - color = {0xA7, 0x32, 0x11}; - } - else if (str == "light_red") - { - color = {0xD8, 0x55, 0x25}; - } - else if (str == "purple") - { - color = {0xA1, 0x55, 0x89}; - } - else if (str == "light_purple") - { - color = {0xCD, 0x7A, 0x50}; - } - else if (str == "green") - { - color = {0x62, 0x9A, 0x31}; - } - else if (str == "light_green") - { - color = {0x9C, 0xD3, 0x3C}; - } - else if (str == "cyan") - { - color = {0x28, 0xA4, 0xCB}; - } - else if (str == "light_cyan") - { - color = {0x65, 0xDC, 0xD6}; - } - else if (str == "yellow") - { - color = {0xE8, 0xBC, 0x50}; - } - else if (str == "light_yellow") - { - color = {0xF1, 0xE7, 0x82}; - } - else if (str == "white") - { - color = {0xBF, 0xBF, 0xBD}; - } - else if (str == "light_white") - { - color = {0xF2, 0xF1, 0xED}; - } - return color; + + return {0x00, 0x00, 0x00}; } \ No newline at end of file diff --git a/todo.txt b/todo.txt index 3c200e2..80a7096 100644 --- a/todo.txt +++ b/todo.txt @@ -7,9 +7,9 @@ x (A) Colisiones con los enemigos {cm:2022-08-29} x (A) Decidir un diseño para qué sucede en caso de morir: Recordar el punto por donde se entró al mapa y la velocidad en el eje X/Y que llevaba el personaje, crear puntos de reaparicion en las habitaciones, etc {cm:2022-08-29} x En el Jet Set Willy el juego recuerda la posicion y el momento. En las Tres Luces de Glaurung solo la posición. Se va a optar por seguir el diseño del Jet Set Willy {cm:2022-08-29} x (A) Crear tiles que maten {cm:2022-08-29} -(A) Modificar el salto para que coincida con el del JSW, no ha de colisionar lateralmente +x (A) Modificar el salto para que coincida con el del JSW, no ha de colisionar lateralmente -(A) Crear tiles que deslicen, (no tipo hielo sino cinta) +(A) Crear tiles que arrastren, tipo cinta transportadora (A) Tiles animados (A) Crear ascensores x (A) Enemigos de diferente tamaño {cm:2022-08-30} @@ -27,10 +27,10 @@ x (A) Tecla + y - para cambiar tamaño de ventana. O control F1 a F4 {cm:2022-08 (A) Añadir a cada habitación el color del nombre de la habitación x (A) Crear el logo al estilo del logo de ERBE o TOPO, con lineas que lo formen -(A) El titulo del juego hacerlo parecido al del Jet Set Willy in Paris - - Ha de generarse como las cargas de pantalla de spectrum - - Luego se colorea - - Finalmente, cada elemento cambia de color como si fueran luces de neon +x (A) El titulo del juego hacerlo parecido al del Jet Set Willy in Paris + x - Ha de generarse como las cargas de pantalla de spectrum + x - Luego se colorea + x - Finalmente, cada elemento cambia de color como si fueran luces de neon x (A) En el titulo del juego, por la parte inferior ha de aparecer una marquesina con texto, al estilo demoscene x (A) La pantalla de titulo no tiene menu, solo un PRESS ENTER TO PLAY From a121850adbd3ac713fba74cfeb4489a7eb0fff09 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 5 Sep 2022 13:51:55 +0200 Subject: [PATCH 2/2] =?UTF-8?q?A=C3=B1adido=20el=20color=20del=20borde=20p?= =?UTF-8?q?ara=20cada=20habitaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/room/01.room | 1 + data/room/02.room | 3 ++- data/room/03.room | 3 ++- data/room/04.room | 5 +++-- data/room/05.room | 1 + source/game.cpp | 6 +++--- source/item.cpp | 2 +- source/logo.cpp | 2 +- source/room.cpp | 13 +++++++++++-- source/room.h | 5 ++++- source/scoreboard.cpp | 4 ++-- source/utils.cpp | 10 +++++----- todo.txt | 2 +- 13 files changed, 37 insertions(+), 20 deletions(-) diff --git a/data/room/01.room b/data/room/01.room index 326940a..34bd926 100644 --- a/data/room/01.room +++ b/data/room/01.room @@ -1,5 +1,6 @@ name=void main bgColor=black +border=red tileset=standard.png roomUp=0 roomDown=0 diff --git a/data/room/02.room b/data/room/02.room index 7a2d4e1..c878c4a 100644 --- a/data/room/02.room +++ b/data/room/02.room @@ -1,5 +1,6 @@ name=case switch bgColor=black +border=green tileset=standard.png roomUp=0 roomDown=04.room @@ -23,7 +24,7 @@ x1=14 y1=0 x2=14 y2=12 -color=purple +color=magenta [/enemy] [item] diff --git a/data/room/03.room b/data/room/03.room index 07f7acc..a809c47 100644 --- a/data/room/03.room +++ b/data/room/03.room @@ -1,5 +1,6 @@ name=the edge bgColor=light_black +border=black tileset=standard.png roomUp=0 roomDown=05.room @@ -55,7 +56,7 @@ x1=16 y1=2 x2=16 y2=13 -color=purple +color=magenta [/enemy] [item] diff --git a/data/room/04.room b/data/room/04.room index caae25b..fc8a58e 100644 --- a/data/room/04.room +++ b/data/room/04.room @@ -1,5 +1,6 @@ name=The Fridge bgColor=blue +border=blue tileset=standard.png roomUp=02.room roomDown=0 @@ -23,7 +24,7 @@ x1=1 y1=3 x2=14 y2=3 -color=purple +color=magenta [/enemy] [enemy] @@ -55,7 +56,7 @@ x1=15 y1=12 x2=30 y2=12 -color=light_purple +color=light_magenta [/enemy] [item] diff --git a/data/room/05.room b/data/room/05.room index 51bda39..3efc44e 100644 --- a/data/room/05.room +++ b/data/room/05.room @@ -1,5 +1,6 @@ name=sigmasua bgColor=black +border=blue tileset=standard.png roomUp=03.room roomDown=0 diff --git a/source/game.cpp b/source/game.cpp index 29282f6..0b1a8da 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -19,7 +19,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) // Crea los objetos scoreboard = new ScoreBoard(renderer, asset, &playerLives, &itemsPicked, &clock); itemTracker = new ItemTracker(); - room = new Room(asset->get(currentRoom), renderer, asset, itemTracker, &itemsPicked); + room = new Room(asset->get(currentRoom), renderer, screen, asset, itemTracker, &itemsPicked); player = new Player(spawnPoint, asset->get("player01.png"), asset->get("player01.ani"), renderer, asset, input, room); eventHandler = new SDL_Event(); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); @@ -260,7 +260,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, asset, itemTracker, &itemsPicked); + room = new Room(asset->get(file), renderer, screen, asset, itemTracker, &itemsPicked); // Pasa la nueva habitación al jugador player->setRoom(room); @@ -318,7 +318,7 @@ void Game::killPlayer() delete player; // Crea la nueva habitación y el nuevo jugador - room = new Room(asset->get(currentRoom), renderer, asset, itemTracker, &itemsPicked); + room = new Room(asset->get(currentRoom), renderer, screen, asset, itemTracker, &itemsPicked); player = new Player(spawnPoint, asset->get("player01.png"), asset->get("player01.ani"), renderer, asset, input, room); } diff --git a/source/item.cpp b/source/item.cpp index d65dc9e..a956f21 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -26,7 +26,7 @@ Item::Item(item_t item) c = stringToColor("red"); color.push_back(c); - c = stringToColor("purple"); + c = stringToColor("magenta"); color.push_back(c); c = stringToColor("green"); diff --git a/source/logo.cpp b/source/logo.cpp index 7e7c777..00a348d 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -49,7 +49,7 @@ Logo::Logo(SDL_Renderer *renderer, Screen *screen, Asset *asset) c = stringToColor("red"); color.push_back(c); - c = stringToColor("purple"); + c = stringToColor("magenta"); color.push_back(c); c = stringToColor("green"); diff --git a/source/room.cpp b/source/room.cpp index 8c17617..c449f99 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -4,11 +4,12 @@ #include // Constructor -Room::Room(std::string file_path, SDL_Renderer *renderer, Asset *asset, ItemTracker *itemTracker, int *items) +Room::Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset *asset, ItemTracker *itemTracker, int *items) { // Copia los punteros a objetos - this->asset = asset; this->renderer = renderer; + this->asset = asset; + this->screen = screen; this->itemTracker = itemTracker; this->itemsPicked = items; @@ -24,6 +25,9 @@ Room::Room(std::string file_path, SDL_Renderer *renderer, Asset *asset, ItemTrac // Pinta el mapa de la habitación en la textura fillMapTexture(); + + // Establece el color del borde + screen->setBorderColor(borderColor); } // Destructor @@ -213,6 +217,11 @@ bool Room::setVars(std::string var, std::string value) bgColor = stringToColor(value); } + else if (var == "border") + { + borderColor = stringToColor(value); + } + else if (var == "tileset") { tileset = value; diff --git a/source/room.h b/source/room.h index c87ed9d..6017d90 100644 --- a/source/room.h +++ b/source/room.h @@ -3,6 +3,7 @@ #include "utils.h" #include "asset.h" +#include "screen.h" #include "enemy.h" #include "item.h" #include "item_tracker.h" @@ -39,6 +40,7 @@ class Room private: std::string name; // Nombre de la habitación color_t bgColor; // Color de fondo de la habitación + color_t borderColor; // Color de fondo 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 @@ -49,6 +51,7 @@ private: std::vector items; // 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 + Screen *screen; // Objeto encargado de dibujar en pantalla ItemTracker *itemTracker; // Lleva el control de los objetos recogidos SDL_Renderer *renderer; // El renderizador de la ventana SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación @@ -72,7 +75,7 @@ private: public: // Constructor - Room(std::string file_path, SDL_Renderer *renderer, Asset *asset, ItemTracker *item_tracker, int *items); + Room(std::string file_path, SDL_Renderer *renderer, Screen *screen, Asset *asset, ItemTracker *item_tracker, int *items); // Destructor ~Room(); diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 5ce2973..d11f21f 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -29,7 +29,7 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *it c = stringToColor("red"); color.push_back(c); - c = stringToColor("purple"); + c = stringToColor("magenta"); color.push_back(c); c = stringToColor("green"); @@ -50,7 +50,7 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, int *lives, int *it c = stringToColor("light_red"); color.push_back(c); - c = stringToColor("light_purple"); + c = stringToColor("light_magenta"); color.push_back(c); c = stringToColor("light_green"); diff --git a/source/utils.cpp b/source/utils.cpp index 10c52b2..135a2da 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -145,7 +145,7 @@ color_t stringToColor(std::string str) { const std::string palette = "spectrum"; - if (palette = "spectrum") + if (palette == "spectrum") { if (str == "black") { @@ -177,12 +177,12 @@ color_t stringToColor(std::string str) return {0xEE, 0x00, 0x00}; } - else if (str == "purple") + else if (str == "magenta") { return {0xFF, 0x00, 0xFF}; } - else if (str == "light_purple") + else if (str == "light_magenta") { return {0xEE, 0x00, 0xEE}; } @@ -260,12 +260,12 @@ color_t stringToColor(std::string str) return {0xD8, 0x55, 0x25}; } - else if (str == "purple") + else if (str == "magenta") { return {0xA1, 0x55, 0x89}; } - else if (str == "light_purple") + else if (str == "light_magenta") { return {0xCD, 0x7A, 0x50}; } diff --git a/todo.txt b/todo.txt index 80a7096..46d6754 100644 --- a/todo.txt +++ b/todo.txt @@ -23,7 +23,7 @@ x (A) Tecla F para pasar a pantalla completa {cm:2022-08-30} x (A) Tecla + y - para cambiar tamaño de ventana. O control F1 a F4 {cm:2022-08-30} (A) Poner en el marcador el indicador de si esta sonando la música (A) Poner en el marcador el numero de habitaciones visitadas -(A) Añadir a cada habitación el color del borde +x (A) Añadir a cada habitación el color del borde (A) Añadir a cada habitación el color del nombre de la habitación x (A) Crear el logo al estilo del logo de ERBE o TOPO, con lineas que lo formen