From 8823543d4e6091b0d5d126b9e733cb848050f609 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Tue, 25 Feb 2020 20:09:38 +0300 Subject: [PATCH] Add impassable Wall cell --- src/game.cpp | 16 ++++++++++++++++ src/level.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/game.cpp b/src/game.cpp index 3655b3e..1a5e0ed 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -127,6 +127,13 @@ void Game::onMoving(sf::Keyboard::Key &key) // Hero exists the level! loadLevel(++current_level); + break; + + case CellType::Wall: + + // You can't pass through wall. Hero goes back to inital coordinates + hero->setPosition(initial_x, initial_y); + break; } @@ -175,6 +182,9 @@ void Game::renderMap() case CellType::Exit: rectangle_brush.setFillColor(sf::Color::Red); break; + case CellType::Wall: + rectangle_brush.setFillColor(sf::Color(60, 60, 60)); // Gray + break; case CellType::Water: default: rectangle_brush.setFillColor(sf::Color::Blue); @@ -219,6 +229,9 @@ void Game::loadLevel(int level_index) // Hardcoding is temporary! hero->setPosition(1, 1); hero->setCharges(2); + map[0][0] = CellType::Wall; + map[0][1] = CellType::Wall; + map[1][0] = CellType::Wall; map[1][1] = CellType::Ground; map[1][2] = CellType::Ground; map[1][3] = CellType::Ground; @@ -256,6 +269,9 @@ void Game::loadLevel(int level_index) map[8][8] = CellType::Ground; map[8][9] = CellType::Ground; map[8][10] = CellType::Exit; + map[8][11] = CellType::Wall; + map[7][11] = CellType::Wall; + map[4][3] = CellType::Wall; map[4][7] = CellType::Charge; level->setMap(map); break; diff --git a/src/level.h b/src/level.h index 6f9cd81..507a807 100644 --- a/src/level.h +++ b/src/level.h @@ -10,7 +10,8 @@ enum class CellType Charge = '$', Bridge = char(177), Hero = '@', - Exit = '#' + Exit = '#', + Wall = 'X' }; using coordinate = unsigned int;