Commit f86ffafa authored by Сулимов Игорь Андреевич's avatar Сулимов Игорь Андреевич
Browse files

Made GameState::render(); and partly GameState::event_handling();

parent 15cf5b94
No related merge requests found
Showing with 67 additions and 6 deletions
+67 -6
......@@ -38,9 +38,9 @@ namespace config {
const sf::Color BUTTON_COLOR_SELECTION{ 255, 180, 180 };
const sf::Color BUTTON_COLOR_FRAME{ 0, 0, 0 };
const sf::Color SELECT_LEVEL_BACKGROUND_COLOR{ 230,230,230 };
// const sf::Color GAME_COLOR_BACKGROUND_INGAME{ 230,230,230 };
// const sf::Color GAME_COLOR_BACKGROUND_WIN{ 0, 255, 0 };
// const sf::Color GAME_COLOR_BACKGROUND_LOST{ 255, 0, 0 };
const sf::Color GAME_COLOR_BACKGROUND_INGAME{ 230,230,230 };
const sf::Color GAME_COLOR_BACKGROUND_WIN{ 0, 255, 0 };
const sf::Color GAME_COLOR_BACKGROUND_LOST{ 255, 0, 0 };
const sf::Color GAME_COLOR_PACMAN{ 250, 150, 0 };
const sf::Color GAME_COLOR_ROOM{ 255, 255, 255 };
const sf::Color GAME_COLOR_WALL{ 0, 0, 0 };
......
......@@ -9,11 +9,11 @@ class GameState: public IState, public IWindowKeeper {
public:
void set_maze(Maze&& maze);
void set_context(GameContext&& context);
bool do_step() override {}; ///@todo
bool do_step() override;
protected:
void event_handling() override {}; ///@todo
void event_handling() override; ///@todo
void update() override {}; ///@todo
void render() override {}; ///@todo
void render() override; ///@todo
public:
GameState(IStateManager& state_manager,
const sf::VideoMode& video_mode, const std::string& window_title);
......
#include "States/GameState.h"
#include "States/SelectState.h"
GameState::GameState(IStateManager& state_manager, const sf::VideoMode& video_mode, const std::string& window_title):
IWindowKeeper(video_mode, window_title), IState(state_manager) {}
......@@ -9,4 +10,64 @@ void GameState::set_maze(Maze&& maze) {
void GameState::set_context(GameContext&& context) {
m_context_manager.reset(std::move(context));
}
bool GameState::do_step() {
while (m_window.isOpen()) {
event_handling();
update();
render();
return true;
}
}
void GameState::event_handling() {
sf::Event event;
while (m_window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
m_state_manager.set_next_state(std::make_unique<SelectState>(m_state_manager,
config::SELECT_LEVEL_VIDEO_MODE, config::SELECT_LEVEL_TITLE));
}
if (event.type == sf::Event::Resized) {
sf::View view = m_window.getView();
view.setSize(event.size.width, event.size.height);
m_window.setView(view);
}
// if (event.type == sf::Event::KeyPressed && m_context_manager.get_current_context().state == GameContext::INGAME) {
// process_key_pressed(event.key.code);
// break;
// }
// if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) &&
// sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
// auto cur_state = m_context_manager.get_current_context().state;
// m_context_manager.restore_previous_context();
// if (cur_state) {
// m_state_sounds.first.stop();
// m_state_sounds.second.stop();
// m_ptr_music_player->play_music();
// }
// break;
// }
}
}
void GameState::render() {
if (m_context_manager.get_current_context().state == GameContext::INGAME) {
m_window.clear(config::GAME_COLOR_BACKGROUND_INGAME);
}
else if (m_context_manager.get_current_context().state == GameContext::WIN) {
m_window.clear(config::GAME_COLOR_BACKGROUND_WIN);
}
else if (m_context_manager.get_current_context().state == GameContext::LOST) {
m_window.clear(config::GAME_COLOR_BACKGROUND_LOST);
}
m_maze.draw_into(m_window);
m_context_manager.get_current_context().pacman.draw_into(m_window);
for (auto& obj : m_context_manager.get_current_context().static_objects) {
obj->draw_into(m_window);
}
for (auto& obj : m_context_manager.get_current_context().dynamic_objects) {
obj->draw_into(m_window);
}
m_window.display();
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment