bullets again

This is a discussion on bullets again within the Game Programming forums, part of the General Programming Boards category; I havetaken time to change over from using an array of bullets to a linked list of bullets. Now I ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    bullets again

    I havetaken time to change over from using an array of bullets to a linked list of bullets. Now I have two problems.

    When the first bullet is deleted the program crashes. This code works with the first element in the list.
    Code:
    else if(current->x == x && current->y == y)
       {
          temp = current;
          *headRef = current->next;
          free(temp);
       }
    As a result of switching over to linked lists my bullet checking code no longer works. Maybe, I'm not comparing my variables correctly?

    Code:
    void checkBullets(struct bulletList* head)
    {
       int i,k;
       struct bulletList* current = head;
    
       for(i = 0; i < MAX_ROW; i++)
       {
          for(k = 0; k < MAX_COL; k++)
          {
             while(current != NULL)
             {
                  if((current->x > alien[i][k].x && 
                      current->x < alien[i][k].x+alien[i][k].width &&
                      current->y > alien[i][k].y && 
                      current->y < alien[i][k].y+alien[i][k].height) && 
                      alien[i][k].alive == 1)
                  {
                      switch(alien[i][k].type)
                      {
                         case 1: player.score += 5; break;
                         case 2: player.score += 1000; break;
                         case 3: player.score += 75; break;
                      }                  
    
                      alien[i][k].alive = 0;  
                  }
               current = current->next;
             }
          }
       }
    
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    25
    Why dont you use vector instead of array/linked list? I think that would be the easiest and most reliable thing to use.
    take a look at
    c++ reference how to use the vector class

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bullets [2D]
    By St0rmTroop3er in forum Game Programming
    Replies: 3
    Last Post: 10-04-2004, 11:26 PM
  2. bouncing bullets
    By dydoko in forum Game Programming
    Replies: 8
    Last Post: 09-18-2003, 08:31 PM
  3. bullets
    By lambs4 in forum Game Programming
    Replies: 10
    Last Post: 08-13-2003, 06:32 AM
  4. pic movement
    By pode in forum Game Programming
    Replies: 31
    Last Post: 08-21-2002, 09:30 PM
  5. Allegro help-o
    By Vicious in forum Game Programming
    Replies: 109
    Last Post: 06-11-2002, 08:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21