Advertisement
Guest User

Untitled

a guest
May 26th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.11 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. //
  217. if(pos[0][0]==1 && pos[1][0] == 1 && pos[2][0] == 1 ||
  218. pos[0][0]==1 && pos[0][1] == 1 && pos[0][2] == 1 ||
  219. pos[0][0]==1 && pos[1][1] == 1 && pos[2][2] == 1 ||
  220. pos[0][1]==1 && pos[1][1] == 1 && pos[1][2] == 1 ||
  221. pos[0][2]==1 && pos[2][1] == 1 && pos[2][2] == 1 ||
  222. pos[2][0]==1 && pos[1][1] == 1 && pos[0][2] == 1 ||
  223. pos[2][0]==1 && pos[2][1] == 1 && pos[2][2] == 1 ||
  224. pos[1][0]==1 && pos[1][1] == 1 && pos[1][2] == 1 ||
  225. pos[0][2]==1 && pos[1][2] == 1 && pos[2][2] == 1 ||
  226. pos[0][1]==1 && pos[1][1] == 1 && pos[2][1] == 1)
  227. {
  228. cout << "Blue wins" << endl;
  229. return main();
  230. }
  231. if(pos[0][0]==2 && pos[1][0] == 2 && pos[2][0] == 2 ||
  232. pos[0][0]==2 && pos[0][1] == 2 && pos[0][2] == 2 ||
  233. pos[0][0]==2 && pos[1][1] == 2 && pos[2][2] == 2 ||
  234. pos[0][1]==2 && pos[1][1] == 2 && pos[1][2] == 2 ||
  235. pos[0][2]==2 && pos[2][1] == 2 && pos[2][2] == 2 ||
  236. pos[2][0]==2 && pos[1][1] == 2 && pos[0][2] == 2 ||
  237. pos[2][0]==2 && pos[2][1] == 2 && pos[2][2] == 2 ||
  238. pos[1][0]==2 && pos[1][1] == 2 && pos[1][2] == 2 ||
  239. pos[0][2]==2 && pos[1][2] == 2 && pos[2][2] == 2 ||
  240. pos[0][1]==2 && pos[1][1] == 2 && pos[2][1] == 2)
  241. {
  242. cout << "Yellow wins" << endl;
  243. return main();
  244. }
  245.  
  246. ///////////////////////////////////////
  247.  
  248.  
  249. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  250.  
  251. for(int i=0;i<BOARD_LENGTH;i++)
  252. for(int j=0;j<BOARD_LENGTH;j++)
  253. object[i][j].draw(camera.getProjection());
  254.  
  255.  
  256. Xmover.draw(camera.getProjection());
  257. window.display();
  258.  
  259. //regulates the frames to 60
  260. sf::sleep(sf::milliseconds(TIME_PER_FRAME-
  261. clock.getElapsedTime().asMilliseconds()));
  262. clock.restart();
  263. }//end while
  264. return 0;
  265. }//end func
  266.  
  267. /*
  268. (T▽T) - proper response!
  269. FPS regulator now allows a specific rate of refresh. This makes
  270. game behaviour more understandable.
  271. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement