Thread: not drawing my bad guys

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    11

    not drawing my bad guys

    hi im currently making a game in C++ and SDL and i have collisions working and i was wondering if there was a way to not draw the bad guy when a collision is detected

    my code for drawing is
    Code:
      for (int i=0; i<size; i++)
            {
                    evil[i].draw(surf);
            }
    the method draw is
    Code:
    void Sprite::draw(SDL_Surface *surf)
    {
            SDL_Rect rect;
    
            if(m_hasImage)
            {
                    // if an image has been loaded then use that
                    rect.x = static_cast<int>(m_x);
                    rect.y = static_cast<int>(m_y);
                    rect.w = rect.h = 0;
                    SDL_BlitSurface(m_image, 0, surf, &rect);
            }
            else
            {
                    // Otherwise just draw a red square
                    rect.x = static_cast<int>(m_x);
                    rect.y = static_cast<int>(m_y);
                    rect.w = m_w;
                    rect.h = m_h;
                    SDL_FillRect(surf, &rect, 0xff0000);  
            }
    }
    so basically, when a collison is detected., i was wondering if there was a way to not draw the guy other than just set his coordinates way off the screen (which is what i have now)

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Code:
    if( !CollidingWithAnything())
    {
      rest of draw
    }
    that's 1 way of doing it

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You could also give each of your enemies a visible variable which is set to false when there is a collision and only draw enemies who's visible variable is set to true.

  4. #4
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    yes that is a way but you should just delete it right on the spot to free up system memory as soon as possible

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    11
    Quote Originally Posted by Quantum1024
    You could also give each of your enemies a visible variable which is set to false when there is a collision and only draw enemies who's visible variable is set to true.

    thast what i tried but when i said (if true) draw the sprites but i dont know what to put in for if false because it wouldnt run properly if it didnt know what to do at false

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    11
    also, my collisions funtion is in my main program and my draw method is in the class, so i sont think i can call collisions in draw

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A few programs for you guys to check out
    By Siggy in forum C++ Programming
    Replies: 6
    Last Post: 12-31-2004, 02:56 AM
  2. How bad is bad
    By caroundw5h in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 11-12-2004, 09:26 AM
  3. Shocking(kind of)
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 12-10-2002, 08:52 PM
  4. good news and bad news
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 10-27-2001, 07:31 AM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM