2020-02-19 12:50:09 -05:00
|
|
|
#include "game.h"
|
|
|
|
|
|
|
|
Game::Game()
|
|
|
|
{
|
2020-02-20 13:34:41 -05:00
|
|
|
// Place the player with 10 initial charges onto x: 1, y: 1
|
|
|
|
hero = std::make_unique<Hero>(1, 1, 10);
|
|
|
|
|
|
|
|
// Generate level
|
|
|
|
level = std::make_unique<Level>();
|
|
|
|
|
2020-02-19 12:50:09 -05:00
|
|
|
sf::Window window(sf::VideoMode(640, 480), "SFML-Test Application", sf::Style::Default);
|
|
|
|
window.setActive();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Game::run()
|
|
|
|
{
|
|
|
|
clock = std::make_unique<sf::Clock>();
|
|
|
|
|
|
|
|
// On the game loop
|
|
|
|
while (main_window.isOpen())
|
|
|
|
{
|
|
|
|
sf::Event event;
|
|
|
|
while (main_window.pollEvent(event))
|
|
|
|
{
|
|
|
|
if (event.type == sf::Event::Closed)
|
|
|
|
main_window.close();
|
|
|
|
|
2020-02-20 13:34:41 -05:00
|
|
|
// Handling keyboard activity
|
|
|
|
if (event.type == sf::Event::KeyPressed)
|
|
|
|
{
|
|
|
|
// Move
|
|
|
|
onMoving(event.key.code);
|
|
|
|
}
|
2020-02-19 12:50:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2020-02-20 13:34:41 -05:00
|
|
|
|
|
|
|
Direction Game::getDirection(sf::Keyboard::Key &key) const
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case sf::Keyboard::A:
|
|
|
|
case sf::Keyboard::Left:
|
|
|
|
return Direction::LEFT;
|
|
|
|
|
|
|
|
case sf::Keyboard::W:
|
|
|
|
case sf::Keyboard::Up:
|
|
|
|
return Direction::UP;
|
|
|
|
|
|
|
|
case sf::Keyboard::D:
|
|
|
|
case sf::Keyboard::Right:
|
|
|
|
return Direction::RIGHT;
|
|
|
|
|
|
|
|
case sf::Keyboard::S:
|
|
|
|
case sf::Keyboard::Down:
|
|
|
|
return Direction::DOWN;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Direction::NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::onMoving(sf::Keyboard::Key &key)
|
|
|
|
{
|
|
|
|
// Determine where to move
|
|
|
|
const Direction direction = getDirection(key);
|
|
|
|
|
|
|
|
if (direction == Direction::NONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
|
|
int initial_x, initial_y;
|
|
|
|
hero->position(initial_x, initial_y);
|
|
|
|
|
|
|
|
// TO DO THE REST
|
|
|
|
}
|