Advertisement
Weegee

loop_obstacles

Aug 19th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.33 KB | None | 0 0
  1. void loop_obstacles(WINDOW * win_game, struct obstaclelist * list_ob, struct bulletlist * list_bu, struct player * pl)
  2. {
  3.     struct obstacle * ob_cur;
  4.    
  5.     if (list_ob->count == 0)
  6.     {
  7.         /* Debugging */
  8.         int j;
  9.         char * string;
  10.        
  11.         string = malloc(4 + (size_t) get_digits((unsigned int) list_ob->count) + sizeof('\0'));
  12.         sprintf(string, "OC: %d", list_ob->count);
  13.        
  14.         for (j = 0; j < (int) strlen(string); j++)
  15.         {
  16.             mvwaddch(win_game, 0, 20 + j, ' ');
  17.         }
  18.        
  19.         create_obstacle(win_game, list_ob);
  20.        
  21.         mvwprintw(win_game, 0, 20, "OC: %d", list_ob->count);
  22.         wrefresh(win_game);
  23.        
  24.         free(string);
  25.     }
  26.     else if (list_ob->count > 0)
  27.     {
  28.         for (ob_cur = list_ob->head; ob_cur != NULL; ob_cur = ob_cur->next)
  29.         {
  30.             if (ob_cur->x_pos < FIELDMINX)
  31.             {
  32.                 assert(destroy_obstacle(win_game, list_ob, ob_cur) == EXIT_SUCCESS);
  33.             }
  34.             else
  35.             {
  36.                 struct bullet * bu_cur;
  37.                
  38.                 move_obstacle(win_game, ob_cur);
  39.                
  40.                 for (bu_cur = list_bu->head; bu_cur != NULL; bu_cur = bu_cur->next)
  41.                 {
  42.                     if (bu_cur->x_pos == ob_cur->x_pos && bu_cur->y_pos == ob_cur->y_pos)
  43.                     {
  44.                         int y = bu_cur->y_pos;
  45.                         int x = bu_cur->x_pos;
  46.                        
  47.                         /* Debug */
  48.                         fprintf(debuglog, "loop_bullets()\n\tObstacle %p collided with bullet %p!\n\tCollision x_pos: %d\n\tCollision y_pos: %d\n", (void *) ob_cur, (void *) bu_cur, ob_cur->x_pos, ob_cur->y_pos);
  49.                         fflush(debuglog);
  50.                        
  51.                         assert(destroy_obstacle(win_game, list_ob, ob_cur) == EXIT_SUCCESS);
  52.                         assert(destroy_bullet(win_game, list_bu, bu_cur) == EXIT_SUCCESS);
  53.                         set_char_attr(win_game, y, x, A_BOLD, YELLOW_BLACK, '*');
  54.                         pl->score += OBSTACLESCORE;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.        
  60.         if (list_ob->count < MAXOBSTACLES)
  61.         {
  62.             /* TODO: The longer the game runs, the more obstacles should spawn */
  63.             int prob = rand() % (100 - 1 + 1) + 1;
  64.             if (prob <= 100)
  65.             {
  66.                 /* Debugging */
  67.                 int j;
  68.                 char * string;
  69.                
  70.                 string = malloc(4 + (size_t) get_digits((unsigned int) list_ob->count) + sizeof('\0'));
  71.                 sprintf(string, "OC: %d", list_ob->count);
  72.                
  73.                 for (j = 0; j < (int) strlen(string); j++)
  74.                 {
  75.                     mvwaddch(win_game, 0, 20 + j, ' ');
  76.                 }
  77.                
  78.                 create_obstacle(win_game, list_ob);
  79.                
  80.                 mvwprintw(win_game, 0, 20, "OC: %d", list_ob->count);
  81.                 wrefresh(win_game);
  82.                
  83.                 free(string);
  84.             }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement