Sign in to follow this  
TheFatGecko

How to kung fu

Recommended Posts

TheFatGecko    206
I want to build a really simple 2D kung fu game, like "ye air kung fu" on the old 64k machines. But i'm stuck! I'm not quite sure how should I deal with the mechanics of the code. i.e. the basic data structures needed to keep tabs of the combat and rules of combat. Also, what type of collision detection should I go for (the game will be 2D) 1) Break the body up into geometric regions. i.e a sphere for the head, quads for body, arms and legs. 2) pixel-pixel overlap test. Limbs, torso, and head have corresponding alpha maps for collision detection. Can anyone point to some source-code, tutorials on fighting style code and data structures. I've tried googling for days but to no avail, the words "kung fu" etc lead to lots of irrelevant sites.

Share this post


Link to post
Share on other sites
yckx    1298
Not having done this before, I'd probably try a pixel-pixel overlap test. Limit damage dealing to certain frames of attack animations, and have some sort of "lookup" in the alpha or a separate image to see if damage should be dealt.

Maybe I should explain better. Say you have a punch anim that goes through 15 frames, and damage should be dealt if the character connects with his fist during frames 4-10. The other frames are wind-up and follow-through, and so don't deal damage. Using alpha as a lookup, you could use, say, 50% alpha for collision detection and 100% alpha for damage-dealing areas. So in most frames, you have a 50% alpha over the whole character, but in frames 4-10, the fist would be 100% alpha. If the player connects with a 100% alpha pixel, he deals damage.

I have no real idea if this is a good way to do this. It's just the idea I'd try first. This would allow for glancing and solid blows if you allow for damage every possible frame. For example, you could deal 5 damage every frame the player connects. Or if you didn't want to do that, you could deal 35 on the first frame he connects and set a flag to not check any more for that punch anim.

Share this post


Link to post
Share on other sites
ghosted    445
I believe the Streetfighter games, and many similar titles, have data representing hitboxes attached to each and every frame of animation. Not sure if those hitboxes were pixel data, polygon shapes or simple rectangles but I'm fairly sure it was a laborious process. If you simply break the player up into componnet parts you'll end up with a player that looks, and maybe even acts, like a puppet.

You might want to look up a homebrew project called Mugen which was a Streetfighter style engine for PC.

Share this post


Link to post
Share on other sites
TheFatGecko    206
ghosted: cheers for the Mugen lead. I've had a look, but it doesn't look like there's any source code or articles concerning the mechanics of the engine.

yckx: like the idea, not sure how it would work but will play around with that

Any ideas about the rule logic:

i.e.

player1 attacks, player 2 defends:
____if player1 uses a normal blow, then defend works
____if player1 uses a "super" move defend fails

player1 attacks, player 2 attacks:
____if player1 uses a "super" move and player2 doesn't then ...

there must be countless scenarios, rules, and importantly, exceptions for different attack/defend combinations.

Any idea how to implement this cleanly without ending up with a big mess of IF conditions that try to deal with every possible case. The problem is extending the rules and adding new characters with new capabilities/rule exceptions.




Share this post


Link to post
Share on other sites
yckx    1298
Quote:
Original post by TheFatGecko
Any ideas about the rule logic:

Most fighting games have high/low or high/mid/low attacks and defenses.

Share this post


Link to post
Share on other sites
DarkMerchant    100
pixel to pixel collision is probably your best bet. FatGecko, your second question points to the reason most don't make fighting games until well versed in the game creation process. the AI for fighting games easily becomes very complex and muddled very quickly. Don't be scared tho, it is def good fun. not sure if you've found some good pixel on pixel collision yet...if not pm me.

Share this post


Link to post
Share on other sites
leiavoia    960
Normally i would not advise pixel-based collisions, but this is a rare case. In the whole game you will only have 2 objects that need collisions (excluding floor + 2 walls). You should be able to afford the processor power to do pixel checking. However, you should do that on top of regular hitbox/geometry checking. If the geometry check works, then check for individual pixels for 100% accuracy.

The reality of it though is that if you have even reasonably loose polygons for the hit geometries, it's practically indistinguishable from pixel checking, which makes messing with pixels redundant. Street Fighter II for instance obvious uses bounding polygons instead of checking for pixels. If it worked for them, it can work for you too!

Share this post


Link to post
Share on other sites
smr    2468
I wouldn't use pixel collision. In a game such as this, I wouldn't want to award damage on such a blow that only connects with one or pixels. In addition to that, it's simply not necessary. Simple rects would more than suffice for hit checks. Don't make your code any more complicated than it has to be. Or in other words, keep things as simple as possible, but no simpler.

Share this post


Link to post
Share on other sites
d000hg    1199
I'd do geometric checking. Then you know what part of the body has been hit (by which part of the attacker). You can implement blocking more easily and have some parts more vulnerable.

Share this post


Link to post
Share on other sites
CyberFox    198
Based on what I have heard here the main concern with pixel based hittesting is:
Complexity
A scrape would be the same as a full blow

Now my suggestion (does nothing to the complexity mind you, I’ll get to that):
Have the alpha maps be gradient, so that the value is higher closer to the center and lower at the edges. That way you can easily know how much of a blow you exerted on the opponent based on the intensity of the pixel you hit.

Now for simplifying:
Designate for each frame a point that is the attack point (your fist for example). Now just use that single point as a lookup into the opponent’s alpha map (with some translation from screen to relative cords of course) and use only that one point (you could also use four points if you want to be precise, then just average the intensities).

Anyway, my two cents.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this