Explosions

This is a discussion on Explosions within the Game Programming forums, part of the General Programming Boards category; hi, im creating a game throught C++ using the SDL thing (ive already got a little help off you before, ...

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

    Explosions

    hi, im creating a game throught C++ using the SDL thing (ive already got a little help off you before, thanks by the way) and i was wondering if i could create a kind of explosion lasting one second or so when a collision is detected in the place of where my bad guy is

    i create the enemy using

    Code:
    evil[i] = new Sprite ("U:\\2E3\\hi\\hi\\wood.gif");
    and i was wondering if, when a collision is detected could a new picture be drawn (i.e. an explosion) and that picture to stay on screen for about a second

    by the way, i use

    Code:
    evil[i]->alive = false;
    to delete my guy off the screen, but that is called in the same place that i want to call explosions and when i create an explosion picture it just goes straight to alive = false before it even gets around to draw the pictures

    so basically what i want is

    Code:
    if (collision == true)
    {
    create a bad guy on screen for 1 second (or 16 frames because i think thats the speed it runs at)
    evil[i]->alive = false; // kill the guy after he has been up for a second
    }
    thanks if you can help

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > evil[i]->alive = false;

    So have more states
    evil[i]->state = alive;
    evil[i]->state = exploding;
    evil[i]->state = dead;

    If you're in the exploding state, have a frame counter to count which frame of the explosion sequence you're supposed to be drawing.

    When you get to the last explosion frame, move to the next state (ie dead)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Although you could use a single bitmap for an explosion, a particle engine would make the game look a lot better. I don't know if you're making a 2D game or 3D game, but this should work either way:

    http://nehe.gamedev.net/data/lessons....asp?lesson=19

    Most particle engines are difficult to make; however, this one is very simple, so it can be made like beginners like me .

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    11
    Quote Originally Posted by Salem
    > evil[i]->alive = false;

    So have more states
    evil[i]->state = alive;
    evil[i]->state = exploding;
    evil[i]->state = dead;

    If you're in the exploding state, have a frame counter to count which frame of the explosion sequence you're supposed to be drawing.

    When you get to the last explosion frame, move to the next state (ie dead)

    im actually not sure how to work that frame counter

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    You mean like extract a given frame from a GIF animation file?

    Code:
    if ( state == alive ) {
      // all other alive stuff
      if ( collision() ) {
        state = exploding;
        explodeFrame = 0;
      }
    } else if ( state == exploding ) {
      // draw a frame
      explodeFrame++;
      if ( explodeFrame == 16 ) {
        state = dead;
      }
    } else if ( state == dead ) {
      // woo hoo
      // add to player score and remove the enemy object
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    11
    oh, ok, i get that now, but what type will state be or is it a seperate method in my class

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > but what type will state be
    Well you previously had a boolean, alive or dead

    So an enum of
    Code:
    enum eState { alive, exploding, dead };
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    11
    im getting a weird error when i run this

    Code:
    error C2513: 'State' : no variable declared before '='
    after i write

    Code:
    State = exploding;
    any idea what it is, it also appears in other places

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Lemme guess, State is the name of the enum.

    Enums are types, so you need
    State myState;
    myState = exploding;

    Much like you would with an int
    int count;
    count = 2;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Mar 2006
    Posts
    11
    brilliant, thanks, just a few more things left that involve my code, not enums so i should be grand with it. thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with explosions
    By Dark_Phoenix in forum Game Programming
    Replies: 2
    Last Post: 01-15-2007, 01:58 AM
  2. Explosions
    By Fordy in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 07-07-2005, 04:36 PM

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