• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Fighting game

## Recommended Posts

Drcrs    122
Hi, I am working on Double Dragon like game. Be cause, I am learning game programming, I need some help for that: First, How is the best way to render in order the sprites? Second, the most real collision detection to use in a fighting game? I hope that you could help me, please :-) Thanks in advance Dr CRS

##### Share on other sites
amish1234    104
With a 2D side scroller, you''ll probably want to just render back to front. I don''t know that much about collision detection, but I''d use several boundary boxes, such as 2 for the arms, 2 for the legs, 1 for torso, and 1 for the head. That way, you can run your punch function and then see if the arm''s boundary box collides with another player''s/bot''s boundary box.

##### Share on other sites
nlo    130
1) Sort all your sprites/characters with the Y-coord, draw them from top to bottom, this will give u the correct order.

2) i think the best/fastest way is using bounding-box, easy to calculate & handle.

##### Share on other sites
King1297    127
Back to Front is ALWAYS the correct way in a 2d engine. To get a good 3d feel, I use a timer in my layer struct. I simply have the back layer's timer be like 0.2, then the next forward layer's timer0. at 0.4, and so on, with the frontmost layer being 1. I then multiply the layers timer by the Game Timer when blitting to the screen, and scroll accordingly.(the scroll rate at which the surface goes by)

if(VK_RIGHT)
{
for(int i=0;i is less then NumLayers;i++)

Layer.Position+=TimeElapsed*Layer[i].Timer;
}

if(VK_LEFT)
{
for(int i=0;i is less then NumLayers;i++)

Layer[i].Position-=TimeElapsed*Layer[i].Timer;

}
etc.

The back layers will go by slower, giving it a smooth feel.

To answer you collision detection for 2d, either Rects or Squares are the best way, although I have heard of ellipses, which are not out of the question with the faster processors.

I hope this helped!

-Matt

ps

I did the words, cause I could not use the < symbol in this forum

Edited by - king1297 on January 31, 2002 5:17:58 AM

##### Share on other sites
Dharma    122
Many years ago I made a fighting game for the Amiga. In a 2D fighting game you can make use of very simple collision detection. I used a simple collision system combining one boundary box for each character with current image/frame. This way I could tell what kind of kick/punch the player was hit by.

Good luck.

Mvh Mario..

##### Share on other sites
King1297    127
Good idea Dharma!

In your Class, you had a graphic as well as the type of kick/punch etc, and then you had a reaction to whych type? or how did it work?

##### Share on other sites
Drcrs    122
Hey guys!

Thanks to everybody!

Dr CRS

##### Share on other sites
Guest Anonymous Poster
BIG NOTE!!!!

Back to front is not always correct... if you use DX8 for your 2D (which is what the MS staff recomends, don''t ask me why I didn''t invent Win95 or DX1-DX3...) then back to front is acceptable but "speed-wise" it is far faster to render front to back. This happens because with DX8 all that nonsense fo rendering back to front and using painter algorithms and etc. is set aside and DX8 uses a z-buffer, which (for who dosn''t know) is an image the size of your render screen which is used to store depth values and then on blitting DX8 compares the depth value of the pixel he is rendering with previous depth values and determines if it should lose time rendering or not (hence if you render front to back you save some time).

Anoter note, although I don''t play around with 2D stuff (I''m more orientated to 3D stuff), another method you might use for that "3D-feeling", if you use DX8 you would forget all that code and simple play with the projection matrix.

BUT, if you don''t know DX8 you should ponder the cost if learning it for your game because it could slow down project BIG TIME (you could even lose months just learning some stuff, but in general it is actually really easy...).

##### Share on other sites
Drcrs    122
Yes, I am using DX 7 at the moment.
But I will keep in mind later with DX 8. Thanks

I have a doubt:

Before to render the sprites (back to front in this case), Must I use an algorithm to sort by Y coord, or is there another better method to do it?

(There are only up to 20 sprites on the screen, but if I would have more of them?)

Thanks again

Dr CRS

##### Share on other sites
Dharma    122
King1297

I had a reaction to what type of kick/punch was thrown. Also I didn't use "back to front" this is not good for a fighting game, not in my case anyway. I solved this the same way as the collision detection. So depending on what type of moves the characters was doing I decided what to be drawn last and what kind of reaction when a character was hit. In some cases it was critical what character to draw first/last, as when grabbing eachother while using knee etc.

collision in simple pseudo:

 if (collision) {    if ((player1.image) > 15) && (Player1.image < 23))        // Do some animation stuff    if ((player1.image) > 23) && (Player1.image < 30))        // do some other animation stuff }

Of course to make this efficient in real, you should have init code keeping track of which series of animation frames goes for each move.

Mvh Mario..

Edited by - dharma on January 31, 2002 10:10:45 AM

##### Share on other sites
Drcrs    122
Dharma:

dont you render from back to front? But, your game is like Street Fighter "only 2d" or like Double Dragon "3d" ?

If it is "3d", how you render in order the sprites?

Dr CRS

##### Share on other sites
Dharma    122
Drcrs

My game was 2D. For all the bg stuff I used "back to front", but for the fighting characters I did use the above technique wich I find simple and efficient enough in this case.

Play around with some of the ideas. I''m sure you''ll find an easy way of implementing a combination of the techniques mentioned in this thread.

Good luck.

##### Share on other sites
Prime    122
For my 2D scroller I found that if you make the bounding box slightly smaller than the sprite (say, around the main body), it can look pretty realistic. If the box surrounds the entire sprite, sometimes a collision is detected even though the sprite itself isn''t actually hit. This can be especially true for an irregular sprite.

Cheers,
Prime

##### Share on other sites
Dharma    122
I am sorry for my bad understanding in english here, or maybe I was a sleep while posting.

Of course I used "back to front". What I was trying to say was, in my game I draw the sprites sorted by Y for all the bg-stuff, but the fighting characters by what animation/kick/punch being used.

Sorry!

Warm regards
Mario..