From 7c7e0c01e25e5fc53f872bd916dcad0a68614f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sat, 27 Aug 2022 22:53:06 +0200 Subject: [PATCH 1/5] =?UTF-8?q?A=C3=B1adidos=20enemigos=20tipo=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/actors/enemies/bug.ani | 2 +- data/actors/enemies/flying_eye.ani | 2 +- data/actors/enemies/flying_eye_horn.ani | 2 +- data/actors/enemies/walking_eye.ani | 2 +- source/animatedsprite.cpp | 6 +++--- source/enemy_engine.cpp | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data/actors/enemies/bug.ani b/data/actors/enemies/bug.ani index 2d0cc0f..11ba1b9 100644 --- a/data/actors/enemies/bug.ani +++ b/data/actors/enemies/bug.ani @@ -3,7 +3,7 @@ frame_width=16 frame_height=16 [animation] -name=walk +name=default speed=8 loop=0 frames=0,1,2,3,4,5 diff --git a/data/actors/enemies/flying_eye.ani b/data/actors/enemies/flying_eye.ani index 2d0cc0f..11ba1b9 100644 --- a/data/actors/enemies/flying_eye.ani +++ b/data/actors/enemies/flying_eye.ani @@ -3,7 +3,7 @@ frame_width=16 frame_height=16 [animation] -name=walk +name=default speed=8 loop=0 frames=0,1,2,3,4,5 diff --git a/data/actors/enemies/flying_eye_horn.ani b/data/actors/enemies/flying_eye_horn.ani index bdfcea2..98b9ec2 100644 --- a/data/actors/enemies/flying_eye_horn.ani +++ b/data/actors/enemies/flying_eye_horn.ani @@ -3,7 +3,7 @@ frame_width=16 frame_height=16 [animation] -name=walk +name=default speed=6 loop=0 frames=0,1,2,3,4,5 diff --git a/data/actors/enemies/walking_eye.ani b/data/actors/enemies/walking_eye.ani index 2d0cc0f..11ba1b9 100644 --- a/data/actors/enemies/walking_eye.ani +++ b/data/actors/enemies/walking_eye.ani @@ -3,7 +3,7 @@ frame_width=16 frame_height=16 [animation] -name=walk +name=default speed=8 loop=0 frames=0,1,2,3,4,5 diff --git a/source/animatedsprite.cpp b/source/animatedsprite.cpp index d433e0d..eaedf5a 100644 --- a/source/animatedsprite.cpp +++ b/source/animatedsprite.cpp @@ -28,15 +28,15 @@ AnimatedSprite::~AnimatedSprite() // Obtiene el indice de la animación a partir del nombre int AnimatedSprite::getIndex(std::string name) { - int result = -1; + int index = 0; for (int i = 0; i < animation.size(); i++) { if (animation[i].name == name) { - result = i; + index = i; } } - return result; + return index; } // Calcula el frame correspondiente a la animación diff --git a/source/enemy_engine.cpp b/source/enemy_engine.cpp index c98bebe..270289c 100644 --- a/source/enemy_engine.cpp +++ b/source/enemy_engine.cpp @@ -89,7 +89,7 @@ bool EnemyEngine::load(std::string file_path) printf("** enemy path loaded\n\n"); //enemies.push_back(new EnemyPath(enemy, p1, p2)); - enemy = new EnemyPath(enemy, p1, p2); + this->enemy = new EnemyPath(enemy, p1, p2); } } From bc464206c114f721c7bb6a37b1a09e8b7ddcd65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sat, 27 Aug 2022 23:26:48 +0200 Subject: [PATCH 2/5] Retocado el mapa --- data/map/01.tmx | 20 +++++++++--------- data/map/02.ene | 15 +++++++++++++ data/map/03.ene | 44 +++++++++++++++++++++++++++++++++++++++ data/map/03.map | 10 +++++++++ source/animatedsprite.cpp | 8 ++++++- source/enemy_engine.cpp | 25 ++-------------------- source/enemy_engine.h | 4 ---- source/game.cpp | 13 ++---------- source/prog.cpp | 1 + 9 files changed, 91 insertions(+), 49 deletions(-) create mode 100644 data/map/03.ene diff --git a/data/map/01.tmx b/data/map/01.tmx index a092352..756ef23 100644 --- a/data/map/01.tmx +++ b/data/map/01.tmx @@ -12,22 +12,22 @@ 0,18,19,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,50,51,52,0,0,0,0,0,0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,0,0,0,0, -0,0,0,366,367,367,368,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,101,102,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,430,431,431,432,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,583,584,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,615,616,69,70,0,0,0,93,94,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,189,190,101,102,0,0,0,125,126,0,0,0,0,0,0, -363,364,0,0,0,0,0,193,194,0,0,0,0,189,190,0,0,0,0,0,0,0,362,282,277,278,279,274,364,0,0,0,157,158,0,0,0,0,0,0, -295,396,0,0,0,0,0,225,226,0,0,0,0,189,190,0,0,362,275,275,275,275,313,314,309,310,311,312,396,0,0,0,189,190,0,0,0,0,0,0, -265,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,263,266,266,266,283,284,266,265,266,264,263,264,263,264,263,264,263,264,263,264,263,264, +0,0,0,0,239,240,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,93,94,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,366,367,367,368,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,125,126,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,430,431,431,432,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,159,160,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,191,192,0,0,0,0,0,93,94,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,189,190,241,242,0,0,0,125,126,0,0,0,0,0,0, +363,364,0,0,0,0,0,193,194,0,0,0,0,189,190,0,0,0,237,238,0,0,362,282,277,278,279,274,364,0,0,0,157,158,0,0,0,0,0,0, +295,396,0,0,0,0,0,225,226,0,0,0,0,189,190,0,0,362,275,275,275,275,313,314,309,310,311,312,396,0,0,0,189,190,0,0,237,238,0,0, +265,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,263,264,267,266,266,266,283,284,266,265,266,267,263,264,263,264,263,264,263,264,263,264,263,264, 295,296,295,296,295,296,295,296,295,265,295,296,295,296,295,296,295,296,295,296,295,296,315,316,298,297,298,296,295,296,295,296,295,296,295,296,295,296,295,296 diff --git a/data/map/02.ene b/data/map/02.ene index 72cf460..c6af4bc 100644 --- a/data/map/02.ene +++ b/data/map/02.ene @@ -11,4 +11,19 @@ x1=9 y1=12 x2=9 y2=20 +[/path] + +[path] +tileset=flying_eye_horn.png +animation=flying_eye_horn.ani +width=16 +height=16 +x=15 +y=5 +vx=0.5 +vy=0 +x1=5 +y1=5 +x2=30 +y2=5 [/path] \ No newline at end of file diff --git a/data/map/03.ene b/data/map/03.ene new file mode 100644 index 0000000..445a697 --- /dev/null +++ b/data/map/03.ene @@ -0,0 +1,44 @@ +[path] +tileset=walking_eye.png +animation=walking_eye.ani +width=16 +height=16 +x=13 +y=23 +vx=0.4 +vy=0 +x1=3 +y1=23 +x2=18 +y2=23 +[/path] + +[path] +tileset=walking_eye.png +animation=walking_eye.ani +width=16 +height=16 +x=22 +y=13 +vx=0.4 +vy=0 +x1=20 +y1=13 +x2=24 +y2=13 +[/path] + +[path] +tileset=walking_eye.png +animation=walking_eye.ani +width=16 +height=16 +x=27 +y=8 +vx=-0.4 +vy=0 +x1=25 +y1=8 +x2=29 +y2=8 +[/path] \ No newline at end of file diff --git a/data/map/03.map b/data/map/03.map index f82ee76..febd1a8 100644 --- a/data/map/03.map +++ b/data/map/03.map @@ -1,4 +1,5 @@ tileset_img=surface.png +enemy_file=03.ene bgColor1=143,86,59 bgColor2=69,40,60 @@ -31,4 +32,13 @@ x=22 y=12 [/diamond] +[diamond] +tileset=diamond.png +animation=diamond.ani +width=16 +height=16 +x=2 +y=22 +[/diamond] + [/actors] \ No newline at end of file diff --git a/source/animatedsprite.cpp b/source/animatedsprite.cpp index eaedf5a..a2036a0 100644 --- a/source/animatedsprite.cpp +++ b/source/animatedsprite.cpp @@ -28,7 +28,7 @@ AnimatedSprite::~AnimatedSprite() // Obtiene el indice de la animación a partir del nombre int AnimatedSprite::getIndex(std::string name) { - int index = 0; + int index = -1; for (int i = 0; i < animation.size(); i++) { if (animation[i].name == name) @@ -36,6 +36,12 @@ int AnimatedSprite::getIndex(std::string name) index = i; } } + + if (index == -1) + { + printf("** Warning: could not find \"%s\" animation\n", name.c_str()); + index = 0; + } return index; } diff --git a/source/enemy_engine.cpp b/source/enemy_engine.cpp index 270289c..0f4e731 100644 --- a/source/enemy_engine.cpp +++ b/source/enemy_engine.cpp @@ -22,8 +22,6 @@ EnemyEngine::~EnemyEngine() delete enemy; } enemies.clear(); - - delete enemy; } // Pinta los enemigos en pantalla @@ -33,7 +31,6 @@ void EnemyEngine::render() { enemy->render(); } - enemy->render(); } // Actualiza las variables del objeto @@ -43,7 +40,6 @@ void EnemyEngine::update() { enemy->update(); } - enemy->update(); } // Carga las variables desde un fichero @@ -88,8 +84,7 @@ bool EnemyEngine::load(std::string file_path) } while (line != "[/path]"); printf("** enemy path loaded\n\n"); - //enemies.push_back(new EnemyPath(enemy, p1, p2)); - this->enemy = new EnemyPath(enemy, p1, p2); + enemies.push_back(new EnemyPath(enemy, p1, p2)); } } @@ -172,20 +167,4 @@ bool EnemyEngine::setEnemy(enemy_t *enemy, SDL_Point *p1, SDL_Point *p2, std::st } return success; -} - -// Carga el vector de enemigos -//bool EnemyEngine::setEnemies(std::string file) -//{ -// // Elimina todos los enemigos anteriores -// for (auto enemy : enemies) -// { -// delete enemy; -// } -// enemies.clear(); -// -// // Carga el vector de enemigos desde un fichero -// const bool success = load(file); -// -// return success; -//} \ No newline at end of file +} \ No newline at end of file diff --git a/source/enemy_engine.h b/source/enemy_engine.h index 6e2dca0..c1b05f4 100644 --- a/source/enemy_engine.h +++ b/source/enemy_engine.h @@ -22,7 +22,6 @@ private: Map *map; // Mapa con la información de la habitación Player *player; // Puntero con el jugador std::vector enemies; // Vector con la lista de enemigos - EnemyPath *enemy; // Carga las variables desde un fichero bool load(std::string file_path); @@ -42,9 +41,6 @@ public: // Actualiza las variables del objeto void update(); - - // Carga el vector de enemigos - //bool setEnemies(std::string file); }; #endif diff --git a/source/game.cpp b/source/game.cpp index 58a5737..f01b25c 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -219,25 +219,16 @@ bool Game::changeMap(std::string file) { // Verifica que exista el fichero que se va a cargar if (asset->get(file) != "") { - // Elimina la habitación actual + // Elimina la habitación actual y crea un objeto nuevo a partir del fichero delete map; - - // Crea un objeto habitación nuevo a partir del fichero map = new Map(asset->get(file), renderer, asset, itemTracker); + // Elimina el gestor de enemigos y crea uno nuevo a partir de un fichero delete enemyEngine; enemyEngine = new EnemyEngine(renderer, asset, player, map, asset->get(map->getEnemyFile())); success = true; } - - // Carga los enemigos - // const std::string enemyFile = asset->get(map->getEnemyFile()); - // if (enemyFile != "") - //{ - // enemyEngine->setEnemies(enemyFile); - // success = true; - //} } return success; diff --git a/source/prog.cpp b/source/prog.cpp index e21b5be..c25ab97 100644 --- a/source/prog.cpp +++ b/source/prog.cpp @@ -146,6 +146,7 @@ bool Prog::setFileList() asset->add("/data/map/02.ene", data); asset->add("/data/map/03.map", data); asset->add("/data/map/03.tmx", data); + asset->add("/data/map/03.ene", data); asset->add("/data/map/surface.png", bitmap); // Ficheros de configuración From b6cbc65a2ab075e1504692a474e793098003ba27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 28 Aug 2022 07:30:13 +0200 Subject: [PATCH 3/5] =?UTF-8?q?corregido=20un=20bug=20en=20la=20ca=C3=ADda?= =?UTF-8?q?=20del=20personaje?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/player.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/source/player.cpp b/source/player.cpp index 1e0dba2..4dd518b 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -219,7 +219,6 @@ void Player::move() vx = 0.0f; } - // Mueve en el eje Y y comprueba colisiones con muros y += vy; if (checkMapCollisions()) @@ -238,8 +237,8 @@ void Player::move() vy = 0.0f; } - // Si no hay colisiones con los muros en el eje Y, comprueba no haya atravesado - // el suelo de un tile atravesble + // Si no hay colisiones con los muros en el eje Y, comprueba + // no haya atravesado el suelo de un tile atravesble else { const int a = (lastPosition.y + h) / tileSize; @@ -265,16 +264,22 @@ void Player::move() } } + const bool going_down2 = vy >= 0.0f; + const bool tile_aligned2 = ((int)y + h) % tileSize == 0; // Si está cayendo - if (vy >= 0.0f) + if (going_down2) { state = falling; - - if (isOnFloor()) + // Si está alineado con el tile mira el suelo (para que no lo mire si está + // dentro de un tile atravesable y lo deje a medias) + if (tile_aligned2) { - state = standing; + if (isOnFloor()) + { + state = standing; + } } - + // Si no esta enganchado a una plataforma if (hookedOnMovingPlatform == -1) { From d937e5578f263534f54af7b4bba82b3980e926d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 28 Aug 2022 07:50:08 +0200 Subject: [PATCH 4/5] Retocado el menu del titulo --- source/game.cpp | 2 +- source/prog.cpp | 2 +- source/title.cpp | 27 ++++++++++++++++++++++++--- source/title.h | 3 +++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/source/game.cpp b/source/game.cpp index f01b25c..44836ef 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -27,7 +27,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input) section.subsection = SUBSECTION_GAME_PLAY; musicEnabled = true; - debug = true; + debug = false; musicEnabled = !debug; } diff --git a/source/prog.cpp b/source/prog.cpp index c25ab97..3440797 100644 --- a/source/prog.cpp +++ b/source/prog.cpp @@ -26,7 +26,7 @@ Prog::Prog(std::string executablePath) } else { - section.name = SECTION_PROG_GAME; + section.name = SECTION_PROG_LOGO; } input = new Input(asset->get("gamecontrollerdb.txt")); screen = new Screen(window, renderer, options); diff --git a/source/title.cpp b/source/title.cpp index d8c35c1..034e5ca 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -46,7 +46,7 @@ Title::~Title() delete text; text = nullptr; - + delete text2; text2 = nullptr; @@ -64,9 +64,9 @@ void Title::initMenu() menu->loadAudioFile(asset->get("sound_menu_move.wav"), SOUND_MOVE); menu->init("TITLE", 0, 150, MENU_BACKGROUND_TRANSPARENT); - menu->addItem("START",2); + menu->addItem("START", 2); menu->addItem("OPTIONS", 5); - menu->addItem("EXIT"); + menu->addItem("EXIT"); menu->setDefaultActionWhenCancel(2); menu->setBackgroundColor({0x30, 0x30, 0x40}, 192); menu->setSelectorColor({0xe5, 0x1c, 0x23}, 0); @@ -103,6 +103,7 @@ void Title::update() } sprite->animate(); menu->update(); + checkMenu(); } } @@ -139,3 +140,23 @@ section_t Title::run() JA_StopMusic(); } + +// Comprueba el menu +void Title::checkMenu() +{ + const int menu = this->menu->getItemSelected(); + + switch (menu) + { + case 0: + section.name = SECTION_PROG_GAME; + break; + + case 2: + section.name = SECTION_PROG_QUIT; + break; + + default: + break; + } +} \ No newline at end of file diff --git a/source/title.h b/source/title.h index b0f67f3..7af44ca 100644 --- a/source/title.h +++ b/source/title.h @@ -42,6 +42,9 @@ private: // Crea el menu void initMenu(); + // Comprueba el menu + void checkMenu(); + public: // Constructor Title(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input); From 2929b1efb97d7af9673eff33d257e2a413a14763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Sun, 28 Aug 2022 07:51:46 +0200 Subject: [PATCH 5/5] =?UTF-8?q?Actualizado=20el=20numero=20de=20versi?= =?UTF-8?q?=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/title.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/title.cpp b/source/title.cpp index 034e5ca..6e70a57 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -118,7 +118,7 @@ void Title::render() // Dibuja los objetos sprite->render(); - text2->writeDX(TXT_CENTER | TXT_COLOR, 160, 205, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.6)", 0, {255, 93, 4}); + text2->writeDX(TXT_CENTER | TXT_COLOR, 160, 205, "@2016,2022 JAILDESIGNER & JAILBROTHER (v0.4)", 0, {255, 93, 4}); menu->render(); // Vuelca el contenido del renderizador en pantalla