Advertisement

How To Explode A Sprite In C

Started by May 20, 2020 10:30 AM
2 comments, last by SillyCow 4 years, 6 months ago

Hi,

As I am programming a paratrooper style game in Turbo C Ver, i need a code to explode the helicopters when hit by a bullet in a realistic way. I am looking for the similar simulation as programmed by Mr. Greg Kuperberg in his game ‘paratrooper’ in 70s!. I have almost completed all other graphic routines but stuck up in this rendering. I am confused with all details available in the net for ‘particle explosion’ as they are either too complex to understand or have written in other languages which i am not comfortable with.

I have given an extract of sample code for illustration purpose. The purpose is to explode this array “SPRITE_IMAGE”. This image consists of three colours, Blue, Yellow and White. I know how to animate the sprite to different locations of screen but not sure how to code for exploding this spite so that it falls down with velocity and gravity. Any simple method to do this since its a 2D game?

//Mode 13h programming in C
//Particle Explosure / Sprite Explosion
//This is not a complete code.
#define SCREEN_WIDTH   320
#define SCREEN_HEIGHT  200
#define SCREEN_SEGMENT 0xA000

char SPRITE_IMAGE[] =
       //A Simple Array Image of Blue(11), Yellow(14) and White(15)
  {
                         //6 x 6 array.
    11,11,11,11,11,11,
    11,14,14,14,14,11,
    11,14,15,15,14,11,
    11,14,15,15,14,11,
    11,14,14,14,14,11,
    11,11,11,11,11,11,
  };

*MySpriteImage = SPRITE_IMAGE;    // pointer to sprite image.

  typedef struct
  {
    int  x, y, velocity, gravity etc.......; 
  } Sprite;
  
  // Please help to complete with code or suggest some idea.

Thanks,

Pramod
India

Make a sequence of frames for the explosion, put them in a sprite sheet and cycle through them. If you search the web for ‘explosion sprite sheet’ you'll find lots of examples.

Also, it's 2020: What are you doing programming in Turbo C?

Advertisement


I sincerely love programming overly complex particle systems! There's something very rewarding and chaotic about them. :-D

Send each pixel at a random velocity in a direction radiating out from the sprite's centre:
example: Center of 6x6 sprite is <3,3> so the pixel at <0,0> will go in direction normalised(<0.0>,<3,3>) = <-1,-1>.

Now add gravity and animate.
Play with both constants of the amplitude of the starting velocity, and gravity to achieve the desired effect.

Looking at the video, it seems to me that objects hit from the left explode to the right: I would think that “paratrooper” also adds the velocity-vector of the bullet to the starting velocity of each pixel: It seems that characters hit by a bullet travelling to the left explode slightly to the left of where they were. Alternately you could just shift the explosion's “axis” from the centere of the sprite to wherever the bullet hit. (so that the centere is not <3,3> anymore)

Aside from that, to make the explosion more visually complex then a bunch of “powdered” pixels, you will notice that “paratrooper” chunks the pixels of similar colours: I would guess that when assigning starting velocities, they “scan” the sprite on the X axis, and they only re-randomise the starting velocity again if the pixel has a different colour: “Any pixels that are horizontally adjacent to each other will have the same starting velocity”. This causes the sprites to fly apart in different sized pieces instead of just turning to “dust”. Uniformity does not look good to the human eye, and this helps break it apart.

Note: Next time, you should include a link to a graphical example of what you are talking about.

Good luck, I would love to see a screenshot of your explosion once you have it up and running!



My Oculus Rift Game: RaiderV

My Android VR games: Time-Rider& Dozer Driver

My browser game: Vitrage - A game of stained glass

My android games : Enemies of the Crown & Killer Bees

This topic is closed to new replies.

Advertisement