|
|
@ -16,6 +16,9 @@ Game::Game()
|
|
|
|
|
|
|
|
|
|
|
|
main_window.create(sf::VideoMode(window_side, window_side), "SFML-Test Application", sf::Style::Default);
|
|
|
|
main_window.create(sf::VideoMode(window_side, window_side), "SFML-Test Application", sf::Style::Default);
|
|
|
|
main_window.setActive();
|
|
|
|
main_window.setActive();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_level = 1;
|
|
|
|
|
|
|
|
loadLevel(current_level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Game::run()
|
|
|
|
int Game::run()
|
|
|
@ -98,26 +101,35 @@ void Game::onMoving(sf::Keyboard::Key &key)
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
// If the following cell is water
|
|
|
|
switch (level->cellOfType(attempt_x, attempt_y))
|
|
|
|
if (level->isCellOfType(attempt_x, attempt_y, CellType::Water))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
case CellType::Water:
|
|
|
|
|
|
|
|
|
|
|
|
// Try to use one charge to place a bridge
|
|
|
|
// Try to use one charge to place a bridge
|
|
|
|
if (hero->useCharge())
|
|
|
|
if (hero->useCharge())
|
|
|
|
level->placeBridge(attempt_x, attempt_y);
|
|
|
|
level->placeBridge(attempt_x, attempt_y);
|
|
|
|
// If hero doesn't have enough charges, we move Hero back
|
|
|
|
// If hero doesn't have enough charges, we move Hero back
|
|
|
|
else
|
|
|
|
else
|
|
|
|
hero->setPosition(initial_x, initial_y);
|
|
|
|
hero->setPosition(initial_x, initial_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case CellType::Charge:
|
|
|
|
|
|
|
|
|
|
|
|
// If the following cell is a charge
|
|
|
|
|
|
|
|
if (level->isCellOfType(attempt_x, attempt_y, CellType::Charge))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Hero picks up the charge; remove it from the map
|
|
|
|
// Hero picks up the charge; remove it from the map
|
|
|
|
hero->refillCharges(1);
|
|
|
|
hero->refillCharges(1);
|
|
|
|
level->removeCharge(attempt_x, attempt_y);
|
|
|
|
level->removeCharge(attempt_x, attempt_y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case CellType::Exit:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Hero exists the level!
|
|
|
|
|
|
|
|
loadLevel(++current_level);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Game::renderMap()
|
|
|
|
void Game::renderMap()
|
|
|
@ -160,6 +172,9 @@ void Game::renderMap()
|
|
|
|
case CellType::Bridge:
|
|
|
|
case CellType::Bridge:
|
|
|
|
rectangle_brush.setFillColor(sf::Color::Black);
|
|
|
|
rectangle_brush.setFillColor(sf::Color::Black);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CellType::Exit:
|
|
|
|
|
|
|
|
rectangle_brush.setFillColor(sf::Color::Red);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CellType::Water:
|
|
|
|
case CellType::Water:
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
rectangle_brush.setFillColor(sf::Color::Blue);
|
|
|
|
rectangle_brush.setFillColor(sf::Color::Blue);
|
|
|
@ -186,3 +201,65 @@ void Game::renderMap()
|
|
|
|
main_window.draw(rectangle_brush);
|
|
|
|
main_window.draw(rectangle_brush);
|
|
|
|
main_window.draw(text);
|
|
|
|
main_window.draw(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Game::loadLevel(int level_index)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Map map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fill the level with water
|
|
|
|
|
|
|
|
for (Row &row : map)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (CellType &cell : row)
|
|
|
|
|
|
|
|
cell = CellType::Water;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (level_index)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
// Hardcoding is temporary!
|
|
|
|
|
|
|
|
hero->setPosition(1, 1);
|
|
|
|
|
|
|
|
hero->setCharges(2);
|
|
|
|
|
|
|
|
map[1][1] = CellType::Ground;
|
|
|
|
|
|
|
|
map[1][2] = CellType::Ground;
|
|
|
|
|
|
|
|
map[1][3] = CellType::Ground;
|
|
|
|
|
|
|
|
map[1][4] = CellType::Ground;
|
|
|
|
|
|
|
|
map[2][2] = CellType::Ground;
|
|
|
|
|
|
|
|
map[3][2] = CellType::Ground;
|
|
|
|
|
|
|
|
map[3][3] = CellType::Ground;
|
|
|
|
|
|
|
|
map[3][3] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][3] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][4] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][5] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][6] = CellType::Ground;
|
|
|
|
|
|
|
|
map[7][6] = CellType::Ground;
|
|
|
|
|
|
|
|
map[9][6] = CellType::Ground;
|
|
|
|
|
|
|
|
map[8][7] = CellType::Exit;
|
|
|
|
|
|
|
|
map[2][3] = CellType::Charge;
|
|
|
|
|
|
|
|
level->setMap(map);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
// Hardcoding is temporary!
|
|
|
|
|
|
|
|
hero->setPosition(5, 5);
|
|
|
|
|
|
|
|
hero->setCharges(10);
|
|
|
|
|
|
|
|
map[5][6] = CellType::Ground;
|
|
|
|
|
|
|
|
map[5][5] = CellType::Ground;
|
|
|
|
|
|
|
|
map[5][4] = CellType::Ground;
|
|
|
|
|
|
|
|
map[4][5] = CellType::Ground;
|
|
|
|
|
|
|
|
map[4][6] = CellType::Ground;
|
|
|
|
|
|
|
|
map[4][4] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][6] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][5] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][4] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][7] = CellType::Ground;
|
|
|
|
|
|
|
|
map[6][8] = CellType::Ground;
|
|
|
|
|
|
|
|
map[5][8] = CellType::Ground;
|
|
|
|
|
|
|
|
map[8][8] = CellType::Ground;
|
|
|
|
|
|
|
|
map[8][9] = CellType::Ground;
|
|
|
|
|
|
|
|
map[8][10] = CellType::Exit;
|
|
|
|
|
|
|
|
map[4][7] = CellType::Charge;
|
|
|
|
|
|
|
|
level->setMap(map);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
main_window.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|