From 2967ccdae76fbb21c706323ef0ef85d2e75cd270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Thu, 15 Sep 2022 17:15:26 +0200 Subject: [PATCH] Trabajando con los tiles que matan --- data/room/04.tmx | 10 +++++----- source/game.cpp | 3 +++ source/player.cpp | 2 -- source/room.cpp | 45 ++++++++++----------------------------------- source/room.h | 2 +- 5 files changed, 19 insertions(+), 43 deletions(-) diff --git a/data/room/04.tmx b/data/room/04.tmx index 0d6cf7e..81442a2 100644 --- a/data/room/04.tmx +++ b/data/room/04.tmx @@ -6,12 +6,12 @@ 25,249,249,249,249,249,249,249,249,249,249,249,249,249,0,0,0,0,249,249,249,249,249,249,249,249,249,249,249,249,249,25, 25,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,25, 25,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,25, -25,0,0,0,0,0,0,0,0,0,0,0,0,0,230,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25, +25,0,0,0,0,0,0,0,0,0,0,0,0,0,230,230,230,230,0,0,0,0,0,0,0,0,0,0,0,0,0,25, 25,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,25, -25,25,25,25,0,25,25,25,25,25,0,25,25,25,25,0,0,230,0,0,0,0,0,0,0,0,0,0,0,0,0,25, -25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,270,270,270,270,270,270,270,0,0,270,0,25, -25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,290,0,0,0,0,0,0,0,25, -25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,290,0,0,0,0,0,0,0,25, +25,25,25,25,0,25,25,25,25,25,0,25,25,25,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25, +25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,270,270,270,270,270,270,270,270,270,0,0,270,0,25, +25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,290,0,0,0,0,0,0,0,0,25, +25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,290,0,0,0,0,0,0,0,0,25, 25,0,0,0,0,0,0,0,0,0,0,25,25,25,25,0,0,25,25,25,25,25,25,25,0,0,0,0,0,0,0,25, 25,0,0,0,0,229,229,229,229,229,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25, 25,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,25, diff --git a/source/game.cpp b/source/game.cpp index 5188e74..7e298b6 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -23,6 +23,9 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, D // currentRoom = "06.room"; // spawnPoint = {14 * 8, 9 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; + + currentRoom = "04.room"; + spawnPoint = {9 * 8, 11 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; // **** // Crea los objetos diff --git a/source/player.cpp b/source/player.cpp index 23e0dde..c432984 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -341,7 +341,6 @@ void Player::move() if (ly > -1) { y = ly - h; - // setState(s_standing); } } @@ -385,7 +384,6 @@ void Player::move() if (ry > -1) { y = ry - h; - // setState(s_standing); } } diff --git a/source/room.cpp b/source/room.cpp index 59187d9..0d8d8bf 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -604,45 +604,14 @@ std::string Room::getRoom(int border) // Devuelve el tipo de tile que hay en ese pixel tile_e Room::getTile(SDL_Point point) { - const int maxTile = mapWidth * mapHeight; const int pos = ((point.y / tileSize) * mapWidth) + (point.x / tileSize); - tile_e tile = t_empty; - - if (pos < maxTile) - { - // Las filas 0-7 son de tiles t_wall - if ((tilemap[pos] >= 0) && (tilemap[pos] < 8 * tilesetWidth)) - { - return t_wall; - } - - // La fila 8 es de tiles t_slope_r - else if ((tilemap[pos] >= 8 * tilesetWidth) && (tilemap[pos] < 9 * tilesetWidth)) - { - return t_slope_r; - } - - // La fila 9 es de tiles t_slope_l - else if ((tilemap[pos] >= 9 * tilesetWidth) && (tilemap[pos] < 10 * tilesetWidth)) - { - return t_slope_l; - } - - // Las filas 10-18 son de tiles t_passable - if ((tilemap[pos] >= 10 * tilesetWidth) && (tilemap[pos] < 19 * tilesetWidth)) - { - return t_passable; - } - } - - return tile; + return getTile(pos); } // Devuelve el tipo de tile que hay en ese indice tile_e Room::getTile(int index) { const int maxTile = mapWidth * mapHeight; - tile_e tile = t_empty; if (index < maxTile) { @@ -664,14 +633,20 @@ tile_e Room::getTile(int index) return t_slope_l; } - // Las filas 10-18 son de tiles t_passable - if ((tilemap[index] >= 10 * tilesetWidth) && (tilemap[index] < 19 * tilesetWidth)) + // Las filas 10-17 son de tiles t_passable + if ((tilemap[index] >= 10 * tilesetWidth) && (tilemap[index] < 18 * tilesetWidth)) { return t_passable; } + + // Las fila 18 es de tiles t_kill + if ((tilemap[index] >= 18 * tilesetWidth) && (tilemap[index] < 19 * tilesetWidth)) + { + return t_kill; + } } - return tile; + return t_empty; } // Indica si hay colision con un enemigo a partir de un rectangulo diff --git a/source/room.h b/source/room.h index 6357348..6ab8130 100644 --- a/source/room.h +++ b/source/room.h @@ -36,7 +36,7 @@ enum tile_e t_passable, t_slope_l, t_slope_r, - t_death + t_kill }; // Clase Room