You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

710 lines
15 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #include "game.hpp"
  2. void gluPerspective(double fovy,double aspect, double zNear, double zFar)
  3. {
  4. // Start in projection mode.
  5. glMatrixMode(GL_PROJECTION);
  6. glLoadIdentity();
  7. double xmin, xmax, ymin, ymax;
  8. ymax = zNear * tan(fovy * M_PI / 360.0);
  9. ymin = -ymax;
  10. xmin = ymin * aspect;
  11. xmax = ymax * aspect;
  12. glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
  13. }
  14. namespace betacore
  15. {
  16. Game::Game(MODE mode,
  17. int port,
  18. std::string url): ME(mode)
  19. {
  20. this->TITLE = Parser::mode(mode).c_str();
  21. printf("%s\t%d\t%d\n",this->TITLE, this->MONITOR_WIDTH, this->MONITOR_HEIGHT);
  22. if (init())
  23. {
  24. printf("Error loading init\n");
  25. return;
  26. }
  27. using namespace std::placeholders;
  28. std::function<void(SHAPE & s, MODE & m)> fn =
  29. std::bind(&Game::update, this, _1, _2);
  30. this->client = new Client(mode, port, url, fn);
  31. // SDL_DisplayMode DM;
  32. // SDL_GetCurrentDisplayMode(0, &DM);
  33. this->MONITOR_HEIGHT = 1080;
  34. this->MONITOR_WIDTH = 1920;
  35. SDL_Event event;
  36. while (this->KEEP_ALIVE)
  37. {
  38. //Handle Events
  39. this->events(event);
  40. this->paint();
  41. }
  42. close();
  43. }
  44. Game::~Game()
  45. {
  46. if (this->client != nullptr)
  47. delete this->client;
  48. this->client = nullptr;
  49. }
  50. int Game::init()
  51. {
  52. int result = 0;
  53. //Initialize SDL
  54. if (SDL_Init(SDL_INIT_VIDEO) < 0)
  55. {
  56. printf("Problem loading SLD Error: %s\n", SDL_GetError());
  57. }
  58. else
  59. {
  60. //OPEN GL VERSION 2.X
  61. SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  62. //OPEN GL VERSION ^.1
  63. SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
  64. //Create window
  65. int videoFlags = SDL_WINDOW_OPENGL;
  66. //videoFlags |= SDL_WINDOW_FULLSCREEN;
  67. videoFlags |= SDL_WINDOW_SHOWN;
  68. videoFlags |= SDL_WINDOW_RESIZABLE;
  69. //videoFlags |= SDL_WINDOW_BORDERLESS;
  70. // videoFlags |= SDL_WINDOW_INPUT_GRABBED;
  71. this->WINDOW = SDL_CreateWindow(
  72. this->TITLE,
  73. SDL_WINDOWPOS_CENTERED,
  74. SDL_WINDOWPOS_CENTERED,
  75. this->SCREEN_WIDTH,
  76. this->SCREEN_HEIGHT,
  77. videoFlags);
  78. if (WINDOW == NULL)
  79. {
  80. printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
  81. result = -1;
  82. }
  83. else
  84. {
  85. glContext = SDL_GL_CreateContext(WINDOW);
  86. if (glContext == NULL)
  87. {
  88. printf("Unable to crate Open GL Context: %s\n", SDL_GetError());
  89. result = -2;
  90. }
  91. else
  92. {
  93. //Try Vsync
  94. if (SDL_GL_SetSwapInterval(1) < 0)
  95. {
  96. printf("Vsync error:%s\n", SDL_GetError());
  97. }
  98. if (initGL())
  99. {
  100. printf("Problem working with OpenGL");
  101. }
  102. }
  103. }
  104. }
  105. return result;
  106. }
  107. int Game::initGL()
  108. {
  109. int result = 0;
  110. glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
  111. glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
  112. glDepthFunc(GL_LESS);
  113. glEnable(GL_DEPTH_TEST); // Enables Depth Testing
  114. glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
  115. glMatrixMode(GL_PROJECTION);
  116. /* Really Nice Perspective Calculations */
  117. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  118. glLoadIdentity();
  119. GLenum error = glGetError();
  120. if (error != GL_NO_ERROR)
  121. {
  122. printf("OpenGL Error %s\n");
  123. result = -1;
  124. return result;
  125. }
  126. glMatrixMode(GL_MODELVIEW);
  127. // Set up the view port
  128. glViewport(0, 0, this->SCREEN_WIDTH, this->SCREEN_HEIGHT);
  129. glMatrixMode(GL_PROJECTION);
  130. glLoadIdentity();
  131. gluPerspective(
  132. 45.0f,
  133. (GLfloat)this->SCREEN_WIDTH / (GLfloat)this->SCREEN_HEIGHT,
  134. 0.1f,
  135. 100.0f);
  136. glMatrixMode(GL_MODELVIEW);
  137. return result;
  138. }
  139. void Game::close()
  140. {
  141. SDL_DestroyWindow(this->WINDOW);
  142. WINDOW = NULL;
  143. SDL_Quit();
  144. }
  145. void Game::grid()
  146. {
  147. glPushMatrix();
  148. //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,gray);
  149. //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
  150. //glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 64);
  151. glTranslatef(0.0f, 0.0f, 0.0f);
  152. glLineWidth(2.5);
  153. glColor3f(1.0, 1.0, 1.0);
  154. /*grid*/
  155. float GRIDE_SIZE = 100;
  156. //X
  157. glBegin(GL_LINES);
  158. glVertex2f(-GRIDE_SIZE, 0);
  159. glVertex2f(GRIDE_SIZE, 0);
  160. glEnd();
  161. //Y
  162. glBegin(GL_LINES);
  163. glVertex2f(0, -GRIDE_SIZE);
  164. glVertex2f(0, GRIDE_SIZE);
  165. glEnd();
  166. //Z
  167. glBegin(GL_LINES);
  168. glVertex3f(0, 0, -GRIDE_SIZE);
  169. glVertex3f(0, 0, GRIDE_SIZE);
  170. glEnd();
  171. //X ticks
  172. float TICK_SIZE = .5;
  173. for (float f = -GRIDE_SIZE; f <= GRIDE_SIZE; f += 1)
  174. {
  175. //X
  176. glBegin(GL_LINES);
  177. glVertex3f(f, -TICK_SIZE, 0);
  178. glVertex3f(f, TICK_SIZE, 0);
  179. glEnd();
  180. //Y
  181. glBegin(GL_LINES);
  182. glVertex2f(-TICK_SIZE, f);
  183. glVertex2f(TICK_SIZE, f);
  184. glEnd();
  185. //Z
  186. glBegin(GL_LINES);
  187. glVertex3f(0, -TICK_SIZE, f);
  188. glVertex3f(0, TICK_SIZE, f);
  189. glEnd();
  190. }
  191. glPopMatrix();
  192. }
  193. void Game::triangle()
  194. {
  195. this->triangle(true);
  196. }
  197. void Game::triangle(bool filled)
  198. {
  199. glColor3f(1.0f, 0.0f, 0.0f);
  200. if (filled)
  201. glBegin(GL_POLYGON); // start drawing a polygon
  202. else
  203. glBegin(GL_LINE_LOOP);
  204. glColor3f(1.0f, 0.0f, 0.0f); // Set The Color To Red
  205. glVertex3f(0.0f, 1.0f, 0.0f); // Top
  206. glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
  207. glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
  208. glEnd(); // we're done with the polygon (smooth color interpolation)
  209. }
  210. void Game::square()
  211. {
  212. this->square(true);
  213. }
  214. void Game::square(bool filled)
  215. {
  216. glColor3f(0.0f, 0.0f, 1.0f);
  217. if (filled)
  218. glBegin(GL_QUADS); // start drawing a polygon (4 sided)
  219. else
  220. glBegin(GL_LINE_LOOP);
  221. glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
  222. glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
  223. glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
  224. glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
  225. glEnd(); // done with the polygon
  226. }
  227. void Game::box()
  228. {
  229. glColor3f(1.0f, 1.0f, 1.0f);
  230. glBegin(GL_LINE_LOOP);
  231. glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
  232. glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
  233. glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
  234. glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
  235. glEnd();
  236. }
  237. void Game::rectangle()
  238. {
  239. glColor3f(1.0f, 1.0f, 1.0f);
  240. glBegin(GL_LINE_LOOP);
  241. glVertex3f(-2.5f, 1.0f, 0.0f); // Top Left
  242. glVertex3f(2.5f, 1.0f, 0.0f); // Top Right
  243. glVertex3f(2.5f, -1.0f, 0.0f); // Bottom Right
  244. glVertex3f(-2.5f, -1.0f, 0.0f); // Bottom Left
  245. glEnd();
  246. }
  247. void Game::cross(bool filled)
  248. {
  249. double width = 0.15;
  250. if (filled)
  251. glBegin(GL_QUADS);
  252. else
  253. glBegin(GL_LINE_LOOP);
  254. glVertex3f(-0.5f, width, 0.0f); // Top Left
  255. glVertex3f(0.5f, width, 0.0f); // Top Right
  256. glVertex3f(0.5f, -width, 0.0f); // Bottom Right
  257. glVertex3f(-0.5f, -width, 0.0f); // Bottom Left
  258. glEnd();
  259. glPushMatrix();
  260. glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);
  261. if (filled)
  262. glBegin(GL_QUADS);
  263. else
  264. glBegin(GL_LINE_LOOP);
  265. glVertex3f(-0.5f, width, 0.0f); // Top Left
  266. glVertex3f(0.5f, width, 0.0f); // Top Right
  267. glVertex3f(0.5f, -width, 0.0f); // Bottom Right
  268. glVertex3f(-0.5f, -width, 0.0f); // Bottom Left
  269. glEnd();
  270. glPopMatrix();
  271. }
  272. void Game::compass()
  273. {
  274. glPushMatrix();
  275. glTranslatef(-1.5f, 0.0f, 0.0f);
  276. glColor3f(1.0f, 1.0f, 1.0f);
  277. this->cross(false);
  278. //MINI TRIANGLE
  279. glPushMatrix();
  280. glScalef(0.12f, 0.12f, 0.0f);
  281. glTranslatef(0.0f, 2.6f, 0.0f);
  282. this->triangle(this->KEY_UP_ARROW_ACTIVE);
  283. glPopMatrix();
  284. // MINI SQUARE
  285. glPushMatrix();
  286. glScalef(0.12f, 0.12f, 0.0f);
  287. glTranslatef(0.0f, -2.6f, 0.0f);
  288. this->square(this->KEY_DOWN_ARROW_ACTIVE);
  289. glPopMatrix();
  290. // MINI PENTAGON
  291. glPushMatrix();
  292. glScalef(0.12f, 0.12f, 0.0f);
  293. glTranslatef(-2.56f, 0.0f, 0.0f);
  294. this->pentagon(this->KEY_LEFT_ARROW_ACTIVE);
  295. glPopMatrix();
  296. // MINI CIRCLE
  297. glPushMatrix();
  298. glScalef(0.12f, 0.12f, 0.0f);
  299. glTranslatef(2.56f, 0.0f, 0.0f);
  300. glColor3f(0.0f, 1.0f, 0.0f);
  301. this->circle(this->KEY_RIGHT_ARROW_ACTIVE);
  302. glPopMatrix();
  303. glPushMatrix();
  304. glScalef(0.35f, 0.35f, 0.0f);
  305. glTranslatef(7.0f, 0.0f, 0.0f);
  306. glColor3f(0.0f, 1.0f, 1.0f);
  307. this->circle(this->KEY_SPACE_ACTIVE);
  308. glPopMatrix();
  309. glPushMatrix();
  310. glScalef(0.35f, 0.35f, 0.0f);
  311. glTranslatef(10.0f, 0.0f, 0.0f);
  312. glColor3f(1.0f, 1.0f, 0.0f);
  313. this->circle(this->KEY_RETURN_ACTIVE);
  314. glPopMatrix();
  315. glPopMatrix();
  316. }
  317. void Game::circle()
  318. {
  319. this->circle(true);
  320. }
  321. void Game::circle(bool filled)
  322. {
  323. //glBegin(GL_LINE_LOOP);
  324. // for (int i = 0; i <= 300; i++)
  325. // {
  326. // double angle = 2 * PI * i / 300;
  327. // double x = cos(angle);
  328. // double y = sin(angle);
  329. // glVertex2d(x, y);
  330. // }
  331. // glEnd();
  332. double radius = 1;
  333. if (filled)
  334. glBegin(GL_POLYGON);
  335. else
  336. glBegin(GL_LINE_LOOP);
  337. double angle1 = 0.0;
  338. glVertex2d(radius * cos(0.0), radius * sin(0.0));
  339. static const int circle_points = 100;
  340. static const float angle = 2.0f * 3.1416f / circle_points;
  341. int i;
  342. for (i = 0; i < circle_points; i++)
  343. {
  344. glVertex2d(radius * cos(angle1), radius * sin(angle1));
  345. angle1 += angle;
  346. }
  347. glEnd();
  348. }
  349. void Game::pentagon()
  350. {
  351. this->pentagon(true);
  352. }
  353. void Game::pentagon(bool filled)
  354. {
  355. glRotatef(-54.0f, 0.0f, 0.0f, 1.0f);
  356. glColor3f(1.0f, 0.0f, 1.0f);
  357. float angleIncrement = 360.0f / 5.0f;
  358. angleIncrement *= PI / 180.0f;
  359. if (filled)
  360. glBegin(GL_TRIANGLE_FAN);
  361. else
  362. glBegin(GL_LINE_LOOP);
  363. float angle = 0.0f;
  364. double radius = 1;
  365. for (int k = 0; k < 100; ++k)
  366. {
  367. glVertex3f(radius * cos(angle), radius * sin(angle), 0.0f);
  368. angle += angleIncrement;
  369. }
  370. glEnd();
  371. }
  372. void Game::user_screen()
  373. {
  374. glPushMatrix();
  375. glTranslatef(-1.5f, -1.0f, -6.0f);
  376. this->box();
  377. //this->box();
  378. //glTranslatef(-1.5f, 0.0f, -6.0f); // Move Left 1.5 Units And Into The Screen 6.0
  379. glTranslatef(-1.5f, -1.0f, -6.0f);
  380. // draw a triangle (in smooth coloring mode)
  381. switch (USER_CURRENT)
  382. {
  383. case TRIANGLE:
  384. this->triangle();
  385. break;
  386. case CIRCLE:
  387. glColor3f(0.0f, 1.0f, 0.0f);
  388. this->circle();
  389. break;
  390. case SQUARE:
  391. this->square();
  392. break;
  393. case PENTAGON:
  394. this->pentagon();
  395. break;
  396. }
  397. // glTranslatef(3.0f, 0.0f, 0.0f); // Move Right 3 Units
  398. // // draw a square (quadrilateral)
  399. // glColor3f(0.5f, 0.5f, 1.0f); // set color to a blue shade.
  400. glPopMatrix();
  401. }
  402. void Game::guest_screen()
  403. {
  404. glPushMatrix();
  405. glTranslatef(1.5f, -1.0f, -6.0f);
  406. this->box();
  407. glTranslatef(1.5f, -1.0f, -6.0f);
  408. // draw a triangle (in smooth coloring mode)
  409. switch (GUST_CURRENT)
  410. {
  411. case TRIANGLE:
  412. this->triangle();
  413. break;
  414. case CIRCLE:
  415. glColor3f(0.0f, 1.0f, 0.0f);
  416. this->circle();
  417. break;
  418. case SQUARE:
  419. this->square();
  420. break;
  421. case PENTAGON:
  422. this->pentagon();
  423. break;
  424. case UNKOWN:
  425. float gray = 105.0 / 255.0;
  426. glColor3f(gray, gray, gray);
  427. glPushMatrix();
  428. glRotatef(-45.0f, 0.0f, 0.0f, 1.0f);
  429. glScalef(2.0f, 2.0f, 0.0f);
  430. this->cross(true);
  431. glPopMatrix();
  432. break;
  433. }
  434. glPopMatrix();
  435. }
  436. void Game::top_screen()
  437. {
  438. glPushMatrix();
  439. glTranslatef(-0.0f, 1.25f, -6.0f);
  440. this->rectangle();
  441. this->compass();
  442. glPopMatrix();
  443. }
  444. void Game::paint()
  445. {
  446. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
  447. glMatrixMode(GL_MODELVIEW);
  448. glLoadIdentity();
  449. if (this->SHOW_GRID)
  450. {
  451. this->grid();
  452. }
  453. this->top_screen();
  454. this->user_screen();
  455. this->guest_screen();
  456. SDL_GL_SwapWindow(this->WINDOW);
  457. }
  458. void Game::resize(int width, int height)
  459. {
  460. glViewport(0, 0, width, height); // Reset The USER_CURRENT Viewport And Perspective Transformation
  461. glMatrixMode(GL_PROJECTION);
  462. glLoadIdentity();
  463. gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 100.0f);
  464. glMatrixMode(GL_MODELVIEW);
  465. }
  466. /**
  467. * key down
  468. * SDL_Keycode key_code
  469. */
  470. void Game::key_down(SDL_Keycode key_code)
  471. {
  472. switch (key_code)
  473. {
  474. case SDLK_ESCAPE:
  475. case SDLK_q:
  476. printf("Escape\n");
  477. this->KEEP_ALIVE = false;
  478. break;
  479. case SDLK_UP:
  480. printf("UP Key Pressed\n");
  481. this->on_key_up_arrow();
  482. this->KEY_UP_ARROW_ACTIVE = true;
  483. break;
  484. case SDLK_DOWN:
  485. printf("Down Key Pressed\n");
  486. this->on_key_down_arrow();
  487. this->KEY_DOWN_ARROW_ACTIVE = true;
  488. break;
  489. case SDLK_LEFT:
  490. printf("Left Key Pressed\n");
  491. this->on_key_left_arrow();
  492. this->KEY_LEFT_ARROW_ACTIVE = true;
  493. break;
  494. case SDLK_RIGHT:
  495. printf("Right Key Pressed\n");
  496. this->on_key_right_arrow();
  497. this->KEY_RIGHT_ARROW_ACTIVE = true;
  498. break;
  499. case SDLK_g:
  500. this->SHOW_GRID = !SHOW_GRID;
  501. break;
  502. case SDLK_SPACE:
  503. this->KEY_SPACE_ACTIVE = true;
  504. this->on_key_space();
  505. break;
  506. case SDLK_RETURN:
  507. this->KEY_RETURN_ACTIVE = true;
  508. this->on_key_enter();
  509. break;
  510. case SDLK_F11:
  511. if (FULL_SCREEN)
  512. {
  513. SDL_SetWindowPosition(this->WINDOW, 100, 100);
  514. SDL_RestoreWindow(this->WINDOW);
  515. //SDL_SetWindowResizable(this->WINDOW, SDL_TRUE);
  516. //SDL_SetWindowBordered(this->WINDOW, 1);
  517. SDL_SetWindowSize(this->WINDOW, SCREEN_WIDTH, SCREEN_HEIGHT);
  518. //SDL_SetWindowFullscreen(this->WINDOW,SDL_WINDOW_FULLSCREEN );
  519. }
  520. else
  521. {
  522. SDL_SetWindowPosition(this->WINDOW, 0, 0);
  523. //SDL_SetWindowResizable(this->WINDOW, SDL_FALSE);
  524. //SDL_SetWindowBordered(this->WINDOW, 0);
  525. SDL_SetWindowSize(this->WINDOW, MONITOR_WIDTH, MONITOR_HEIGHT);
  526. //SDL_SetWindowFullscreen(this->WINDOW,0 );
  527. }
  528. this->FULL_SCREEN = !this->FULL_SCREEN;
  529. SDL_ShowCursor(this->FULL_SCREEN);
  530. break;
  531. default:
  532. //Do nothing
  533. break;
  534. }
  535. }
  536. /**
  537. * key down
  538. * SDL_Keycode key_code
  539. */
  540. void Game::key_up(SDL_Keycode key_code)
  541. {
  542. switch (key_code)
  543. {
  544. case SDLK_UP:
  545. this->KEY_UP_ARROW_ACTIVE = false;
  546. break;
  547. case SDLK_DOWN:
  548. this->KEY_DOWN_ARROW_ACTIVE = false;
  549. break;
  550. case SDLK_LEFT:
  551. this->KEY_LEFT_ARROW_ACTIVE = false;
  552. break;
  553. case SDLK_RIGHT:
  554. this->KEY_RIGHT_ARROW_ACTIVE = false;
  555. break;
  556. case SDLK_SPACE:
  557. this->KEY_SPACE_ACTIVE = false;
  558. break;
  559. case SDLK_RETURN:
  560. this->KEY_RETURN_ACTIVE = false;
  561. break;
  562. case SDLK_F11:
  563. // SDL_DisplayMode dm;
  564. // SDL_RestoreWindow(this->WINDOW); //Incase it's maximized...
  565. // SDL_SetWindowSize(this->WINDOW, dm.w, dm.h + 10);
  566. // SDL_SetWindowPosition(this->WINDOW, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
  567. default:
  568. //Do nothing
  569. break;
  570. }
  571. }
  572. void Game::events(SDL_Event &event)
  573. {
  574. while (SDL_PollEvent(&event) != 0)
  575. {
  576. //https://wiki.libsdl.org/SDL_EventType
  577. switch (event.type)
  578. {
  579. case SDL_WINDOWEVENT:
  580. switch (event.window.event)
  581. {
  582. case SDL_WINDOWEVENT_RESIZED:
  583. //resize();
  584. break;
  585. case SDL_WINDOWEVENT_SIZE_CHANGED:
  586. this->resize(event.window.data1, event.window.data2);
  587. break;
  588. }
  589. break;
  590. //user-requested quit
  591. case SDL_QUIT:
  592. this->KEEP_ALIVE = false;
  593. break;
  594. //Mouse events
  595. case SDL_MOUSEBUTTONDOWN:
  596. case SDL_MOUSEMOTION:
  597. case SDL_MOUSEBUTTONUP:
  598. case SDL_MOUSEWHEEL:
  599. break;
  600. //Keyboard Events
  601. case SDL_KEYDOWN:
  602. this->key_down(event.key.keysym.sym);
  603. break;
  604. case SDL_KEYUP:
  605. this->key_up(event.key.keysym.sym);
  606. break;
  607. } //end switch(event.type)
  608. } //end-while
  609. }
  610. void Game::on_key_up_arrow()
  611. {
  612. // Toggle triangle
  613. this->USER_CURRENT = TRIANGLE;
  614. }
  615. void Game::on_key_down_arrow()
  616. {
  617. this->USER_CURRENT = SQUARE;
  618. }
  619. void Game::on_key_left_arrow()
  620. {
  621. this->USER_CURRENT = PENTAGON;
  622. }
  623. void Game::on_key_right_arrow()
  624. {
  625. this->USER_CURRENT = CIRCLE;
  626. }
  627. void Game::on_key_space()
  628. {
  629. this->client->send(false,this->USER_CURRENT);
  630. }
  631. void Game::on_key_enter()
  632. {
  633. this->client->send(true,this->USER_CURRENT);
  634. }
  635. void Game::update(SHAPE &s, MODE &m)
  636. {
  637. if (m == ME)
  638. this->USER_CURRENT = s;
  639. else
  640. this->GUST_CURRENT = s;
  641. }
  642. } // namespace betacore
  643. int main(int argc, char *argv[])
  644. {
  645. betacore::Game game(betacore::BOB, 4444, "localhost");
  646. return 0;
  647. }