+++ /dev/null
-#include "Game_state.h"
-
-Game_state::Game_state() : game_map{}, player{}, pause_game{false}
-{
-}
-
-void Game_state::update(Context& context)
-{
- if (pause_game)
- {
- context.saved_game = std::move(context.current_state);
- context.next_state = new Pause_menu{};
- pause_game = false;
- return;
- }
- game_map.update(context);
- player.update(context);
-}
-
-void Game_state::render(sf::RenderWindow& window) const
-{
- game_map.render(window);
- player.render(window);
-}
-
-void Game_state::handle_input(sf::Event& event)
-{
- switch (event.type)
- {
- case sf::Event::KeyPressed:
- switch(event.key.code)
- {
- case sf::Keyboard::Escape:
- pause_game = true;
- return;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-
- player.handle_input(event);
-}
\ No newline at end of file
+++ /dev/null
-#ifndef GAME_STATE_H
-#define GAME_STATE_H
-
-#include <SFML/Graphics.hpp>
-#include <memory>
-
-#include "State.h"
-#include "Map.h"
-#include "Player.h"
-#include "Menus.h"
-
-class Game_state : public State
-{
-public:
- Game_state();
- ~Game_state() = default;
-
- void update(Context& context) override;
- void render(sf::RenderWindow& window) const override;
- void handle_input(sf::Event& event) override;
- Map game_map;
-protected:
-private:
-
- Player player;
- bool pause_game;
-};
-
-#endif
\ No newline at end of file
#include <SFML/Graphics.hpp>
#include "constants.h"
-#include "State.h"
+
+struct Context;
class Map
{
+++ /dev/null
-#include "Menus.h"
-
-#include <iostream> //TA BORT!
-
-Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false}
-{
- texture.loadFromFile("assets/sack.png");
- sprite.setTexture(texture);
-
- sf::FloatRect gb {sprite.getGlobalBounds()};
- sprite.setOrigin(gb.width / 2, gb.height / 2);
- sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
-}
-
-void Start_menu::update(Context& context)
-{
- if (exit_menu)
- {
- context.next_state = new Game_state{};
- }
-}
-
-void Start_menu::render(sf::RenderWindow& window) const
-{
- window.draw(sprite);
-}
-
-void Start_menu::handle_input(sf::Event& event)
-{
- switch (event.type)
- {
- case sf::Event::KeyPressed:
- switch(event.key.code)
- {
- case sf::Keyboard::Enter:
- exit_menu = true;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-}
-
-Pause_menu::Pause_menu() : texture{}, sprite{}, exit_game{false}, resume_game{false}
-{
- texture.loadFromFile("assets/kir.png");
- sprite.setTexture(texture);
-
- sf::FloatRect gb {sprite.getGlobalBounds()};
- sprite.setOrigin(gb.width / 2, gb.height / 2);
- sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
-}
-
-void Pause_menu::update(Context& context)
-{
- if (resume_game)
- {
- context.next_state = std::move(context.saved_game);
- }
- else if (exit_game)
- {
- context.next_state = new Start_menu{};
- }
-}
-
-void Pause_menu::render(sf::RenderWindow& window) const
-{
- window.draw(sprite);
-}
-
-void Pause_menu::handle_input(sf::Event& event)
-{
- switch (event.type)
- {
- case sf::Event::KeyPressed:
- switch(event.key.code)
- {
- case sf::Keyboard::Enter:
- resume_game = true;
- break;
- case sf::Keyboard::Escape:
- exit_game = true;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-}
+++ /dev/null
-#ifndef MENUS_H
-#define MENUS_H
-
-#include <memory>
-
-#include "SFML/Graphics.hpp"
-#include "State.h"
-#include "constants.h"
-#include "Game_state.h"
-
-class Start_menu : public State
-{
-public:
- Start_menu();
- ~Start_menu() = default;
- void update(Context& context) override;
- void render(sf::RenderWindow& window) const override;
- void handle_input(sf::Event& event) override;
-
-private:
- sf::Texture texture;
- sf::Sprite sprite;
- bool exit_menu;
-};
-
-
-class Pause_menu : public State
-{
-public:
- Pause_menu();
- ~Pause_menu() = default;
- void update(Context& context) override;
- void render(sf::RenderWindow& window) const override;
- void handle_input(sf::Event& event) override;
-private:
- sf::Texture texture;
- sf::Sprite sprite;
- bool resume_game;
- bool exit_game;
-};
-
-#endif
\ No newline at end of file
#define OBJECT_H
#include <SFML/Graphics.hpp>
-#include "State.h"
+
+struct Context;
class Object
{
#include "Moving_object.h"
#include "constants.h"
-#include "State.h"
class Player : public Moving_object
{
+++ /dev/null
-#ifndef STATE_H
-#define STATE_H
-
-#include "SFML/Graphics.hpp"
-#include <memory>
-
-struct Context;
-
-class State
-{
-public:
- virtual void update(Context& context) = 0;
- virtual void render(sf::RenderWindow& window) const = 0;
- virtual void handle_input(sf::Event& event) = 0;
- virtual ~State() = default;
-};
-
-struct Context
-{
- State* current_state {nullptr};
- State* next_state {nullptr};
- State* saved_game {nullptr};
-};
-
-#endif
\ No newline at end of file
--- /dev/null
+#include "States.h"
+
+Game_state::Game_state() : game_map{}, player{}, pause_game{false}
+{
+}
+
+void Game_state::update(Context& context)
+{
+ if (pause_game)
+ {
+ context.running_game = std::move(static_cast<Game_state*>(context.current_state));
+ context.next_state = new Pause_menu{};
+ pause_game = false;
+ return;
+ }
+ game_map.update(context);
+ player.update(context);
+}
+
+void Game_state::render(sf::RenderWindow& window) const
+{
+ game_map.render(window);
+ player.render(window);
+}
+
+void Game_state::handle_input(sf::Event& event)
+{
+ switch (event.type)
+ {
+ case sf::Event::KeyPressed:
+ switch(event.key.code)
+ {
+ case sf::Keyboard::Escape:
+ pause_game = true;
+ return;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ player.handle_input(event);
+}
+
+Start_menu::Start_menu() : texture{}, sprite{}, exit_menu{false}
+{
+ texture.loadFromFile("assets/sack.png");
+ sprite.setTexture(texture);
+
+ sf::FloatRect gb {sprite.getGlobalBounds()};
+ sprite.setOrigin(gb.width / 2, gb.height / 2);
+ sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
+}
+
+void Start_menu::update(Context& context)
+{
+ if (exit_menu)
+ {
+ context.next_state = new Game_state{};
+ }
+}
+
+void Start_menu::render(sf::RenderWindow& window) const
+{
+ window.draw(sprite);
+}
+
+void Start_menu::handle_input(sf::Event& event)
+{
+ switch (event.type)
+ {
+ case sf::Event::KeyPressed:
+ switch(event.key.code)
+ {
+ case sf::Keyboard::Enter:
+ exit_menu = true;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+Pause_menu::Pause_menu() : texture{}, sprite{}, exit_game{false}, resume_game{false}
+{
+ texture.loadFromFile("assets/kir.png");
+ sprite.setTexture(texture);
+
+ sf::FloatRect gb {sprite.getGlobalBounds()};
+ sprite.setOrigin(gb.width / 2, gb.height / 2);
+ sprite.setPosition(S_WIDTH / 2, S_HEIGHT / 2);
+}
+
+void Pause_menu::update(Context& context)
+{
+ if (resume_game)
+ {
+ context.next_state = std::move(context.running_game);
+ }
+ else if (exit_game)
+ {
+ context.next_state = new Start_menu{};
+ }
+}
+
+void Pause_menu::render(sf::RenderWindow& window) const
+{
+ window.draw(sprite);
+}
+
+void Pause_menu::handle_input(sf::Event& event)
+{
+ switch (event.type)
+ {
+ case sf::Event::KeyPressed:
+ switch(event.key.code)
+ {
+ case sf::Keyboard::Enter:
+ resume_game = true;
+ break;
+ case sf::Keyboard::Escape:
+ exit_game = true;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+}
--- /dev/null
+#ifndef STATES_H
+#define STATES_H
+
+#include <memory>
+#include "SFML/Graphics.hpp"
+
+#include "constants.h"
+#include "Map.h"
+#include "Player.h"
+
+struct Context;
+
+class State
+{
+public:
+ virtual void update(Context& context) = 0;
+ virtual void render(sf::RenderWindow& window) const = 0;
+ virtual void handle_input(sf::Event& event) = 0;
+ virtual ~State() = default;
+};
+
+class Game_state : public State
+{
+public:
+ Game_state();
+ ~Game_state() = default;
+
+ void update(Context& context) override;
+ void render(sf::RenderWindow& window) const override;
+ void handle_input(sf::Event& event) override;
+ Map game_map;
+protected:
+private:
+ Player player;
+ bool pause_game;
+};
+
+class Start_menu : public State
+{
+public:
+ Start_menu();
+ ~Start_menu() = default;
+ void update(Context& context) override;
+ void render(sf::RenderWindow& window) const override;
+ void handle_input(sf::Event& event) override;
+
+private:
+ sf::Texture texture;
+ sf::Sprite sprite;
+ bool exit_menu;
+};
+
+class Pause_menu : public State
+{
+public:
+ Pause_menu();
+ ~Pause_menu() = default;
+ void update(Context& context) override;
+ void render(sf::RenderWindow& window) const override;
+ void handle_input(sf::Event& event) override;
+private:
+ sf::Texture texture;
+ sf::Sprite sprite;
+ bool resume_game;
+ bool exit_game;
+};
+
+struct Context
+{
+ State* current_state {nullptr};
+ State* next_state {nullptr};
+ Game_state* running_game {nullptr};
+};
+
+#endif
\ No newline at end of file
#include <memory>
#include "constants.h"
-#include "Game_state.h"
-#include "Menus.h"
-#include "State.h"
+#include "States.h"
int main ()