Advertisement
Guest User

Untitled

a guest
May 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.27 KB | None | 0 0
  1. /**
  2. Linux
  3. g++ AbsObject.cpp Camera.cpp main.cpp -o run.exe -lGL -lGLEW -lsfml-graphics -lsfml-window -lsfml-system && ./run.exe
  4.  
  5. Windows
  6. g++ AbsObject.cpp Camera.cpp main.cpp -o run.exe -IC:/glew/include -LC:/glew/lib -fpermissive -IC:/sfml/include -LC:/sfml/lib -IC:/glm -lsfml-window -lsfml-graphics -lsfml-system -lglew32 -lopengl32 -lglu32 && run.exe
  7.  
  8. Start Window
  9. */
  10. #include <iostream>
  11. #include <GL/glew.h>
  12. #include <SFML/Window.hpp>
  13. #include "AbsObject.h"
  14. #include "Camera.h"
  15. #include <stdlib.h>
  16. #include <time.h>
  17.  
  18.  
  19.  
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. bool win = false;
  25. bool yellow = false;
  26. bool blue = true;
  27.  
  28. sf::ContextSettings settings;
  29. settings.depthBits = 24;
  30. settings.stencilBits = 8;
  31. settings.antialiasingLevel = 4;
  32. settings.majorVersion = 3;
  33. settings.minorVersion = 0;
  34. srand (time(NULL));
  35.  
  36. sf::Window window(sf::VideoMode(3500, 2000), "Horse Play ", sf::Style::Default, settings);
  37. window.setPosition(sf::Vector2i(0,0));
  38.  
  39. GLenum status = glewInit();
  40. if(status != GLEW_OK)
  41. std::cout << "ERROR" << std::endl;
  42.  
  43. GLfloat points[] =
  44. {
  45. -0.5f, 0.5f, 0.0f,
  46. -0.5f,-0.5f, 0.0f,
  47. 0.5f,-0.5f, 0.0f,
  48.  
  49. -0.5f, 0.5f, 0.0f,
  50. 0.5f,-0.5f, 0.0f,
  51. 0.5f, 0.5f, 0.0f,
  52. };
  53.  
  54. const int BOARD_LENGTH = 3;
  55. const float TILE_SIZE = 0.2f;
  56. const float Xmover_SIZE = TILE_SIZE*0.76f;
  57. bool isPressed = false;
  58. int xPos = 0;
  59. int yPos = 0;
  60. bool black = false;
  61.  
  62. AbsObject object[BOARD_LENGTH][BOARD_LENGTH];
  63.  
  64. int pos[3][3]=
  65. {
  66. 0,0,0,
  67. 0,0,0,
  68. 0,0,0
  69. };
  70.  
  71. AbsObject Xmover(points,sizeof(points),1,0.77,0.61);
  72. Xmover.getScalePtr()->x = Xmover_SIZE/2;
  73. Xmover.getScalePtr()->y = Xmover_SIZE/2;
  74. Xmover.getTranslationPtr()->y = - TILE_SIZE*5;
  75. Xmover.getTranslationPtr()->x = - TILE_SIZE*5;
  76.  
  77. for(int i=0;i<BOARD_LENGTH;i++)
  78. {
  79. for(int j=0;j<BOARD_LENGTH;j++)
  80. {
  81.  
  82. if(i%2==0&&j%2==0 || i%2==1&&j%2==1)
  83. object[i][j].init(points,sizeof(points),1,1,1);
  84. else
  85. object[i][j].init(points,sizeof(points),1,1,1);
  86. object[i][j].getScalePtr()->x = TILE_SIZE/1.6f;
  87. object[i][j].getScalePtr()->y = TILE_SIZE/1.6f;
  88. object[i][j].getTranslationPtr()->y = i*TILE_SIZE - TILE_SIZE*5;
  89. object[i][j].getTranslationPtr()->x = j*TILE_SIZE - TILE_SIZE*5;
  90.  
  91. }
  92. }
  93.  
  94. bool trigger = false;
  95. Camera camera(70,800.0f/600.0f,0.01f,100.0f,0,0,3);
  96. camera.updateCamera();
  97.  
  98. //makes sure the program runs at 60 FPS
  99. const float TIME_PER_FRAME = 1.0f/60*1000;
  100. sf::Clock clock;
  101.  
  102. while (window.isOpen())
  103. {
  104. sf::Event event;
  105. while (window.pollEvent(event))
  106. {
  107. if (event.type == sf::Event::Closed)
  108. {
  109. window.close();
  110. }else if (event.type == sf::Event::Resized)
  111. {
  112. glViewport(0, 0, event.size.width, event.size.height);
  113. }//end else if
  114. }//end while
  115.  
  116. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  117. {
  118. if(!isPressed && yPos+1 < BOARD_LENGTH)
  119. {
  120. std::cout << "UP" << std::endl;
  121. Xmover.getTranslationPtr()->y += TILE_SIZE;
  122. yPos++;
  123. std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
  124. isPressed = true;
  125. }
  126. }
  127. else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
  128. {
  129. if(!isPressed && yPos-1 >= 0)
  130. {
  131. std::cout << "DOWN" << std::endl;
  132. Xmover.getTranslationPtr()->y -= TILE_SIZE;
  133. yPos--;
  134. std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
  135. isPressed = true;
  136. }
  137. }
  138.  
  139. else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
  140. {
  141. if(!isPressed && xPos-1 >= 0)
  142. {
  143. std::cout << "LEFT" << std::endl;
  144. Xmover.getTranslationPtr()->x -= TILE_SIZE;
  145. xPos--;
  146. std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
  147. isPressed = true;
  148. }
  149. }
  150.  
  151. else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  152. {
  153. if(!isPressed && xPos+1 < BOARD_LENGTH)
  154. {
  155. std::cout << "RIGHT" << std::endl;
  156. Xmover.getTranslationPtr()->x += TILE_SIZE;
  157. xPos++;
  158. std::cout <<"(" <<xPos<< "," << yPos<< ")" << std::endl;
  159. isPressed = true;
  160. }
  161. }
  162. // else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Z))
  163. // {
  164. // object[yPos][xPos].init(points,sizeof(points),1,1,0);
  165. // object[yPos][xPos].getScalePtr()->x = TILE_SIZE/1.6f;
  166. // object[yPos][xPos].getScalePtr()->y = TILE_SIZE/1.6f;
  167. // object[yPos][xPos].getTranslationPtr()->y = yPos*TILE_SIZE - TILE_SIZE*5;
  168. // object[yPos][xPos].getTranslationPtr()->x = xPos*TILE_SIZE - TILE_SIZE*5;
  169. // }
  170. else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
  171. {
  172. if(!isPressed)
  173. {
  174.  
  175. if(pos[yPos][xPos]==0)
  176. {
  177. std::cout<<"press"<<std::endl;
  178. if(blue)
  179. {
  180.  
  181.  
  182. object[yPos][xPos].init(points,sizeof(points),0,0,1);
  183. object[yPos][xPos].getScalePtr()->x = TILE_SIZE/1.6f;
  184. object[yPos][xPos].getScalePtr()->y = TILE_SIZE/1.6f;
  185. object[yPos][xPos].getTranslationPtr()->y = yPos*TILE_SIZE - TILE_SIZE*5;
  186. object[yPos][xPos].getTranslationPtr()->x = xPos*TILE_SIZE - TILE_SIZE*5;
  187. pos[yPos][xPos]=1;
  188. blue = false;
  189. yellow = true;
  190.  
  191. }
  192. else if(yellow)
  193. {
  194.  
  195. object[yPos][xPos].init(points,sizeof(points),1,1,0);
  196. object[yPos][xPos].getScalePtr()->x = TILE_SIZE/1.6f;
  197. object[yPos][xPos].getScalePtr()->y = TILE_SIZE/1.6f;
  198. object[yPos][xPos].getTranslationPtr()->y = yPos*TILE_SIZE - TILE_SIZE*5;
  199. object[yPos][xPos].getTranslationPtr()->x = xPos*TILE_SIZE - TILE_SIZE*5;
  200. pos[yPos][xPos]=2;
  201. yellow = false;
  202. blue = true;
  203. }
  204.  
  205. isPressed = true;
  206.  
  207. }
  208. }
  209.  
  210. }
  211. else
  212. {
  213. if(isPressed)
  214. isPressed = false;
  215. }
  216. ////horizontals
  217. if(pos[0][0]==1 && pos[1][0] == 1 && pos[2][0] == 1)
  218. {
  219. cout << "Blue wins" << endl;
  220. return main();
  221. }
  222. //
  223. else if(pos[0][0]==2 && pos[1][0] == 2 && pos[2][0] == 2)
  224. {
  225. cout << "Yellow wins" << endl;
  226. return main();
  227. }
  228. //
  229. else if(pos[0][0]==2 && pos[0][1] == 2 && pos[0][2] == 2)
  230. {
  231. cout << "Yellow wins" << endl;
  232. return main();
  233. }
  234. //
  235. else if(pos[0][0]==1 && pos[0][1] == 1 && pos[0][2] ==1)
  236. {
  237. cout << "Blue wins" << endl;
  238. return main();
  239. }
  240. //
  241. else if(pos[1][0]==1 && pos[1][1] == 1 && pos[1][2] ==1)
  242. {
  243. cout << "Blue wins" << endl;
  244. return main();
  245. }
  246. //
  247. else if(pos[1][0]==2 && pos[1][1] == 2 && pos[1][2] ==2)
  248. {
  249. cout << "Yellow wins" << endl;
  250. return main();
  251. }
  252. //
  253. else if(pos[2][0]==2 && pos[2][1] == 2 && pos[2][2] ==2)
  254. {
  255. cout << "Yellow wins" << endl;
  256. return main();
  257. }
  258. //
  259. else if(pos[2][0]==1 && pos[2][1] == 1 && pos[2][2] == 1)
  260. {
  261. cout << "Blue wins" << endl;
  262. return main();
  263. }
  264. //
  265. ////verticals
  266. else if(pos[0][0]==1 && pos[1][0] == 1 && pos[2][0] == 1)
  267. {
  268. cout << "Blue wins" << endl;
  269. return main();
  270. }
  271. //
  272. else if(pos[0][0]==2 && pos[1][0] == 2 && pos[2][0] == 2)
  273. {
  274. cout << "Yellow wins" << endl;
  275. return main();
  276. }
  277. //
  278. else if(pos[0][1]==1 && pos[1][1] == 1 && pos[2][1] == 1)
  279. {
  280. cout << "Blue wins" << endl;
  281. return main();
  282. }
  283. //
  284. else if(pos[0][1]==2 && pos[1][1] == 2 && pos[2][1] == 2)
  285. {
  286. cout << "Yellow wins" << endl;
  287. return main();
  288. }
  289. //
  290. else if(pos[0][2]==1 && pos[1][2] == 1 && pos[2][2] == 1)
  291. {
  292. cout << "Blue wins" << endl;
  293. return main();
  294. }
  295. //
  296. else if(pos[0][2]==2 && pos[1][2] == 2 && pos[2][2] == 2)
  297. {
  298. cout << "Yellow wins" << endl;
  299. return main();
  300. }
  301. //
  302. //diagonals
  303. else if(pos[0][0]==1 && pos[1][1] == 1 && pos[2][2] == 1)
  304. {
  305. cout << "Blue wins" << endl;
  306. return main();
  307. }
  308. //
  309. else if(pos[0][0]==2 && pos[1][1] == 2 && pos[2][2] == 2)
  310. {
  311. cout << "Yellow wins" << endl;
  312. return main();
  313. }
  314. //
  315. else if(pos[2][0]==1 && pos[1][1] == 1 && pos[0][2] == 1)
  316. {
  317. cout << "Blue wins" << endl;
  318. return main();
  319. }
  320. //
  321. else if(pos[2][0]==2 && pos[1][1] == 2 && pos[0][2] == 2)
  322. {
  323. cout << "Yellow wins" << endl;
  324. return main();
  325. }
  326.  
  327. ///////////////////////////////////////
  328.  
  329.  
  330. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  331.  
  332. for(int i=0;i<BOARD_LENGTH;i++)
  333. for(int j=0;j<BOARD_LENGTH;j++)
  334. object[i][j].draw(camera.getProjection());
  335.  
  336.  
  337. Xmover.draw(camera.getProjection());
  338. window.display();
  339.  
  340. //regulates the frames to 60
  341. sf::sleep(sf::milliseconds(TIME_PER_FRAME-
  342. clock.getElapsedTime().asMilliseconds()));
  343. clock.restart();
  344. }//end while
  345. return 0;
  346. }//end func
  347.  
  348. /*
  349. (T▽T) - proper response!
  350. FPS regulator now allows a specific rate of refresh. This makes
  351. game behaviour more understandable.
  352. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement