Advertisement
Weegee

Untitled

Aug 18th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. void loop_bullets(WINDOW * win_game, struct bulletlist * list_bu, struct player * pl, struct obstaclelist * list_ob)
  2. {
  3.     struct bullet * bu_cur;
  4.    
  5.     /* Debugging */
  6.     int j;
  7.     char * string;
  8.    
  9.     string = malloc(4 + (size_t) get_digits((unsigned int) list_bu->count) + sizeof('\0'));
  10.     sprintf(string, "BC: %d", list_bu->count);
  11.    
  12.     for (j = 0; j < (int) strlen(string); j++)
  13.     {
  14.         mvwaddch(win_game, 0, 40 + j, ' ');
  15.     }
  16.    
  17.     mvwprintw(win_game, 0, 40, "BC: %d", list_bu->count);
  18.     wrefresh(win_game);
  19.    
  20.     free(string);
  21.    
  22.     if (list_bu->count > 0)
  23.     {
  24.         for (bu_cur = list_bu->head; bu_cur != NULL; bu_cur = bu_cur->next)
  25.         {
  26.             if (bu_cur->x_pos > FIELDMAXX)
  27.             {
  28.                 assert(destroy_bullet(win_game, list_bu, bu_cur) == EXIT_SUCCESS);
  29.             }
  30.             else
  31.             {
  32.                 struct obstacle * ob_cur;
  33.                
  34.                 move_bullet(win_game, bu_cur);
  35.                
  36.                 for (ob_cur = list_ob->head; ob_cur != NULL; ob_cur = ob_cur->next)
  37.                 {
  38.                     if (bu_cur->x_pos == ob_cur->x_pos && bu_cur->y_pos == ob_cur->y_pos)
  39.                     {
  40.                         int y = bu_cur->y_pos;
  41.                         int x = bu_cur->x_pos;
  42.                        
  43.                         /* Debug */
  44.                         fprintf(debuglog, "loop_bullets()\n\tBullet %p collided with obstacle %p!\n\tCollision x_pos: %d\n\tCollision y_pos: %d\n", (void *) bu_cur, (void *) ob_cur, ob_cur->x_pos, ob_cur->y_pos);
  45.                         fflush(debuglog);
  46.                        
  47.                         assert(destroy_bullet(win_game, list_bu, bu_cur) == EXIT_SUCCESS);
  48.                         assert(destroy_obstacle(win_game, list_ob, ob_cur) == EXIT_SUCCESS);
  49.                         set_char_attr(win_game, y, x, A_BOLD, YELLOW_BLACK, '*');
  50.                         pl->score += OBSTACLESCORE;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement