Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------test_state.cpp---------------
- void test_state::Update(sf::RenderWindow* window)
- {
- if (paused)
- {
- // normalus zaidimas.
- }
- else
- {
- // zaidimas su pause.
- }
- }
- void test_state::Render(sf::RenderWindow* window)
- {
- }
- void test_state::Destroy(sf::RenderWindow* window)
- {
- std::cout << "Destroyed\n";
- }
- -------------------test_state.h-------------------------------
- #pragma once
- #include "game_state.h"
- class test_state : public tiny_state
- {
- public:
- void Initialize(sf::RenderWindow* window);
- void Update(sf::RenderWindow* window);
- void Render(sf::RenderWindow* window);
- void Destroy(sf::RenderWindow* window);
- private:
- bool paused;
- };
- ----------------game_state.h------------
- #pragma once
- #include <SFML\Graphics.hpp>
- class tiny_state
- {
- public:
- virtual void Initialize(sf::RenderWindow* window)
- {
- }
- virtual void Update(sf::RenderWindow* window)
- {
- }
- virtual void Render(sf::RenderWindow* window)
- {
- }
- virtual void Destroy(sf::RenderWindow* window)
- {
- }
- };
- class game_state
- {
- public:
- game_state()
- {
- this->state = NULL;
- }
- void SetWindow(sf::RenderWindow* window)
- {
- this->window = window;
- }
- void SetState(tiny_state* state)
- {
- if (this->state != NULL)
- {
- this->state->Destroy(this->window);
- }
- this->state = state;
- if (this->state != NULL)
- {
- this->state->Initialize(this->window);
- }
- }
- void Update()
- {
- if (this->state != NULL)
- {
- this->state->Update(this->window);
- }
- }
- void Render()
- {
- if (this->state != NULL)
- {
- this->state->Render(this->window);
- }
- }
- game_state()
- {
- if (this->state != NULL)
- {
- this->state->Destroy(this->window);
- }
- }
- private:
- sf::RenderWindow* window;
- tiny_state* state;
- };
- extern game_state coreState;
- -----------Source.cpp----------------------
- #include <iostream>
- int main()
- {
- int num1 = 5;
- int num2 = num2;
- std::cout << num1;
- std::cout << "\n";
- std::cout << num2;
- while (1);
- /*sf::RenderWindow window(sf::VideoMode(800, 600), "Ping");
- tiny_state state = tiny_state();
- coreState.SetWindow(&window);
- coreState.SetState(new test_state());
- // run the program as long as the window is open
- while (window.isOpen())
- {
- // check all the window's events that were triggered since the last iteration of the loop
- sf::Event event;
- while (window.pollEvent(event))
- {
- // "close requested" event: we close the window
- if (event.type == sf::Event::Closed)
- window.close();
- }
- coreState.Update();
- coreState.Render();
- }
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement