Advertisement
swistusmen

GAME APLIANCES

May 21st, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. ///////////////////Biblioteki game aplicances
  2. #ifndef GAMEAPLIANCES_HPP_INCLUDED
  3. #define GAMEAPLIANCES_HPP_INCLUDED
  4.  
  5. #endif // GAMEAPLIANCES_HPP_INCLUDED
  6. #pragma once
  7. #include <iostream>
  8. #include <SFML/Graphics.hpp>
  9. #include <list>
  10.  
  11. enum ButtonActions {Play,Back,Forward,Other,Nothing};
  12.  
  13. enum MenuTribe {Powrot, Nic, FramePerSeconds};
  14.  
  15. class Button{
  16. public:
  17. void draw(sf::RenderWindow&);
  18. void FullFill(int,int,std::string &,ButtonActions );//wypelnia tekst i wspó³rzêdne
  19. Button();
  20. ButtonActions IsClicked(int,int);
  21. private:
  22. sf::Sprite duszek;
  23. sf::Font tekscior;
  24. sf::Texture teksturka;
  25. sf::Text napis;
  26. ButtonActions action;
  27. };
  28.  
  29. class MenuPanel{
  30. public:
  31. MenuPanel();
  32.  
  33. int Run(sf::RenderWindow&);
  34.  
  35. private:
  36. void draw(sf::RenderWindow&);
  37. void ProcessEvents(sf::RenderWindow&);
  38. MenuTribe IsClicked(int, int);
  39. MenuTribe Tryb=MenuTribe::Nic;
  40. int WhatToDo();
  41. int HandleFPS();
  42.  
  43. Button taski[2];
  44. sf::Event zdarzenie;
  45. };
  46.  
  47. class FPSwindow
  48. {
  49. public:
  50. FPSwindow();
  51. void draw(sf::RenderWindow&);
  52. void update (int );
  53. private:
  54. std::string FPS="A";
  55.  
  56. sf::Sprite ikona;
  57. sf::Font font;
  58. sf::Texture teksturka;
  59. sf::Text napis;
  60. };
  61.  
  62. class Taskbar{
  63. public:
  64. Taskbar();
  65. void draw(sf::RenderWindow &);
  66. ButtonActions IsClicked(int, int);
  67. void update(int);
  68. private:
  69. Button taski[4];
  70. FPSwindow FPScounter;
  71. };
  72. ///////////////////////////////////////
  73. #include <iostream>
  74. #include <SFML/Graphics.hpp>
  75. #include <list>
  76. #include "GameApliances.hpp"
  77. #include <string>
  78.  
  79. void MenuPanel::draw(sf::RenderWindow& appwindow)
  80. {
  81. taski[0].draw(appwindow);
  82. taski[1].draw(appwindow);
  83. }
  84.  
  85. int MenuPanel::Run(sf::RenderWindow& appwindow)
  86. {
  87. int i=0;
  88. while(i==0){
  89. appwindow.clear();
  90. draw(appwindow);
  91. ProcessEvents(appwindow);
  92. i=WhatToDo();
  93. }
  94. }
  95.  
  96. int MenuPanel::HandleFPS()
  97. {
  98. return 0;
  99. }
  100.  
  101. int MenuPanel::WhatToDo()
  102. {
  103. switch(Tryb)
  104. {
  105. case MenuTribe::Nic:
  106. {
  107. return 0;
  108. }break;
  109. case MenuTribe::Powrot:
  110. {
  111. return -1;
  112. }
  113. case MenuTribe::FramePerSeconds:
  114. {
  115. return HandleFPS();
  116. }break;
  117. }
  118. }
  119.  
  120. void MenuPanel::ProcessEvents(sf::RenderWindow& appwindow)
  121. {
  122. while(appwindow.pollEvent(zdarzenie))
  123. {
  124. if(zdarzenie.type==sf::Event::Closed)
  125. {
  126. appwindow.close();
  127. exit(0);
  128. }
  129. if(zdarzenie.type==sf::Event::MouseButtonPressed)
  130. {
  131. Tryb=IsClicked(zdarzenie.mouseButton.x,zdarzenie.mouseButton.y);
  132. }
  133. }
  134. }
  135.  
  136. MenuTribe MenuPanel::IsClicked(int x,int y)
  137. {
  138. ButtonActions bufor=ButtonActions::Nothing;
  139. for(int i=0;i<2;i++)
  140. {
  141. bufor=taski[i].IsClicked(x,y);
  142. if(ButtonActions::Nothing!=bufor)
  143. {
  144. switch(bufor)
  145. {
  146. case ButtonActions::Play:
  147. {
  148. return MenuTribe::Powrot;
  149. }break;
  150. case ButtonActions::Other:
  151. {
  152. return MenuTribe::FramePerSeconds;
  153. }break;
  154. }
  155. }
  156. }
  157. return MenuTribe::Nic;
  158. }
  159.  
  160. MenuPanel::MenuPanel()
  161. {
  162. std::string buf="FPS setter";
  163. taski[0].FullFill(600,400,buf,ButtonActions::Other);
  164. buf="Powrot";
  165. taski[1].FullFill(600,1200,buf,ButtonActions::Play);
  166. }
  167.  
  168.  
  169. FPSwindow::FPSwindow()
  170. {
  171. teksturka.loadFromFile("ikona.jpg");
  172. ikona.setTexture(teksturka);
  173. font.loadFromFile("font.ttf");
  174. napis.setFont(font);
  175. napis.setString(FPS);
  176. ikona.setPosition(1850,1550);
  177. napis.setPosition(1850,1550);
  178. }
  179.  
  180.  
  181. void FPSwindow::draw(sf::RenderWindow&appwindow)
  182. {
  183. appwindow.draw(ikona);
  184. appwindow.draw(napis);
  185. }
  186.  
  187. void FPSwindow::update (int a){
  188.  
  189. FPS=std::to_string(a);
  190. napis.setString(FPS);
  191. }
  192.  
  193. void Taskbar::update(int a)
  194. {
  195. FPScounter.update(a);
  196. }
  197.  
  198. ButtonActions Taskbar::IsClicked(int x, int y)
  199. {
  200. for(int i=0;i<4;i++)
  201. {
  202. if(ButtonActions::Nothing!=taski[i].IsClicked(x,y))
  203. return taski[i].IsClicked(x,y);
  204. }
  205. return ButtonActions::Nothing;
  206. }
  207.  
  208. ButtonActions Button::IsClicked(int x,int y)
  209. {
  210. if((x>duszek.getGlobalBounds().left)&&(x<duszek.getGlobalBounds().width)&&
  211. (y>duszek.getGlobalBounds().top)&&(y>duszek.getGlobalBounds().height))
  212. return action;
  213. return Nothing;
  214. }
  215.  
  216. void Taskbar::draw(sf::RenderWindow& appwindow)
  217. {
  218. for(int i=0;i<4;i++)
  219. taski[i].draw(appwindow);
  220. FPScounter.draw(appwindow);
  221. }
  222.  
  223. Taskbar::Taskbar()
  224. {
  225. std::string napis="Play";
  226. taski[0].FullFill(200,1520,napis,ButtonActions::Play);
  227. napis="StepBack";
  228. taski [1].FullFill(600,1520,napis,ButtonActions::Back);
  229. napis="StepForward";
  230. taski [2].FullFill(1000,1520,napis,ButtonActions::Forward);
  231. napis="Other";
  232. taski [3].FullFill(1400,1520,napis,ButtonActions::Other);
  233. }
  234.  
  235. void Button::FullFill(int x,int y,std::string & tresc,ButtonActions akcja)
  236. {
  237. duszek.setPosition(x,y);
  238. napis.setPosition(x+150,y+80);
  239. napis.setString(tresc);
  240. action=akcja;
  241. }
  242.  
  243. void Button::draw(sf::RenderWindow& appwindow)
  244. {
  245. appwindow.draw(duszek);
  246. appwindow.draw(napis);
  247. }
  248.  
  249. /*Button::Button(std::string& ciag)
  250. {
  251. teksturka.loadFromFile("button.jpg");
  252. duszek.setTexture(teksturka);
  253. tekscior.loadFromFile("font.ttf");
  254. napis.setFont(tekscior);
  255. napis.setString(ciag);
  256. duszek.setPosition(100,100);
  257. napis.setPosition(150,150);
  258. }*/
  259.  
  260. Button::Button()
  261. {
  262. teksturka.loadFromFile("button.jpg");
  263. duszek.setTexture(teksturka);
  264. tekscior.loadFromFile("font.ttf");
  265. napis.setFont(tekscior);
  266. action=ButtonActions::Other;
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement