Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. ------------------test_state.cpp---------------
  2.  
  3. void test_state::Update(sf::RenderWindow* window)
  4. {
  5. if (paused)
  6. {
  7.  
  8. // normalus zaidimas.
  9. }
  10. else
  11. {
  12. // zaidimas su pause.
  13. }
  14. }
  15. void test_state::Render(sf::RenderWindow* window)
  16. {
  17. }
  18. void test_state::Destroy(sf::RenderWindow* window)
  19. {
  20. std::cout << "Destroyed\n";
  21. }
  22.  
  23. -------------------test_state.h-------------------------------
  24.  
  25. #pragma once
  26.  
  27. #include "game_state.h"
  28.  
  29. class test_state : public tiny_state
  30. {
  31. public:
  32. void Initialize(sf::RenderWindow* window);
  33. void Update(sf::RenderWindow* window);
  34. void Render(sf::RenderWindow* window);
  35. void Destroy(sf::RenderWindow* window);
  36. private:
  37. bool paused;
  38.  
  39.  
  40. };
  41.  
  42. ----------------game_state.h------------
  43.  
  44. #pragma once
  45. #include <SFML\Graphics.hpp>
  46.  
  47. class tiny_state
  48. {
  49. public:
  50. virtual void Initialize(sf::RenderWindow* window)
  51. {
  52. }
  53. virtual void Update(sf::RenderWindow* window)
  54. {
  55. }
  56. virtual void Render(sf::RenderWindow* window)
  57. {
  58. }
  59. virtual void Destroy(sf::RenderWindow* window)
  60. {
  61. }
  62. };
  63.  
  64. class game_state
  65. {
  66. public:
  67. game_state()
  68. {
  69. this->state = NULL;
  70. }
  71.  
  72. void SetWindow(sf::RenderWindow* window)
  73. {
  74. this->window = window;
  75.  
  76. }
  77.  
  78. void SetState(tiny_state* state)
  79. {
  80. if (this->state != NULL)
  81. {
  82. this->state->Destroy(this->window);
  83. }
  84. this->state = state;
  85. if (this->state != NULL)
  86. {
  87. this->state->Initialize(this->window);
  88. }
  89. }
  90. void Update()
  91. {
  92. if (this->state != NULL)
  93. {
  94. this->state->Update(this->window);
  95. }
  96.  
  97. }
  98. void Render()
  99. {
  100. if (this->state != NULL)
  101. {
  102. this->state->Render(this->window);
  103. }
  104.  
  105. }
  106. game_state()
  107. {
  108. if (this->state != NULL)
  109. {
  110. this->state->Destroy(this->window);
  111. }
  112. }
  113. private:
  114. sf::RenderWindow* window;
  115. tiny_state* state;
  116.  
  117. };
  118.  
  119. extern game_state coreState;
  120.  
  121. -----------Source.cpp----------------------
  122.  
  123.  
  124. #include <iostream>
  125.  
  126. int main()
  127. {
  128. int num1 = 5;
  129. int num2 = num2;
  130. std::cout << num1;
  131. std::cout << "\n";
  132. std::cout << num2;
  133. while (1);
  134.  
  135. /*sf::RenderWindow window(sf::VideoMode(800, 600), "Ping");
  136.  
  137. tiny_state state = tiny_state();
  138.  
  139. coreState.SetWindow(&window);
  140. coreState.SetState(new test_state());
  141.  
  142.  
  143. // run the program as long as the window is open
  144. while (window.isOpen())
  145. {
  146. // check all the window's events that were triggered since the last iteration of the loop
  147. sf::Event event;
  148. while (window.pollEvent(event))
  149. {
  150. // "close requested" event: we close the window
  151. if (event.type == sf::Event::Closed)
  152. window.close();
  153. }
  154. coreState.Update();
  155. coreState.Render();
  156.  
  157. }
  158.  
  159. */
  160. return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement