Guest User

Untitled

a guest
Oct 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1.    void GameField::handleEvents(SDL_Event & event) {
  2.         int x = 0,
  3.             y = 0;
  4.  
  5.         int x_pos = 0,
  6.             y_pos = 0;
  7.  
  8.         int cols = 0,
  9.             rows = 0;
  10.  
  11.         if (event.type == SDL_MOUSEBUTTONDOWN) {
  12.             if (event.button.button == SDL_BUTTON_LEFT) {
  13.                 x = event.button.x;
  14.                 y = event.button.y;
  15.  
  16.                 for (int b = 0; b < BOX_MAX; b++) {
  17.                     x_pos = ((BOX_SPRITE_WIDTH * cols) + BOX_SPRITE_WIDTH);
  18.                     y_pos = ((BOX_SPRITE_HEIGHT * rows) + BOX_SPRITE_HEIGHT);
  19.  
  20.                     if (x >= GameField::box[b].x && x <= x_pos) {
  21.                         if (y >= GameField::box[b].y && y <= y_pos) {
  22.                             if (GameField::box[b].type == EMPTY) {
  23.                                 GameField::box[b].type = CIRCLE;
  24.  
  25.                                 for (int bb = 0; bb < BOX_MAX; bb++) {
  26.                                     if (GameField::box[bb].last == true) {
  27.                                         GameField::box[bb].last = false;
  28.                                     }
  29.                                 }
  30.  
  31.                                 GameField::box[b].last = true;
  32.                             }
  33.  
  34.                             break;
  35.                         }
  36.                     }
  37.  
  38.                     if (cols == (BOX_MAX_COLS - 1)) {
  39.                         if (rows == (BOX_MAX_ROWS - 1))
  40.                             rows = 0;
  41.                         else
  42.                             rows++;
  43.  
  44.                         cols = 0;
  45.                     } else {
  46.                         cols++;
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.     }
Add Comment
Please, Sign In to add comment