Archived

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

Redline

2D One on one combat - Streetfighter style

Recommended Posts

Hi everyone, I think this is my first post but I''ve been hanging around these forums for quite some time now. I''ve decided it''s probably time to become a little more proactive...so without further ado, I have a question for you . I''ve been thinking about what would be required to develop a streetfighter style beat''em up what I''ve discovered is that there''s more to the task than I thought there would be. The main task comes from the actual game logic itself and I''ve been thinking of some kind of state management system for the characters, however, I wish to avoid full blown finite state machines (for chars) like Mugen uses, so to this end, I was thinking of implementing some kind of internal "scripting" system for the chars that uses a combination of text files and internal methods. This way I could define a (large) set of states that the character could posses (most states would be common over all characters I would assume) and then define a set of conditions that have to be met for each state to succeed. I want the characters to have their own fighting styles of course, so once a state has been set that character would play a script for that particular state. Animations would also be linked into the states via a vector position (so if standing was first in a enum, then the animations for that characters standing state would be stored in element 0 of the vector etc). Now, I said earlier that the scripts would be a combination of internal procedures and text files, the text files (which would later be converted to binary as user extensibility is not a concern here...initially anyway) would detail a bunch of actions to perform for each characters state using a group of prdefined generic procedures. So we could have: MoveLeft 1 Which would move a character left 1 pixel etc. There would obviously be other available movements like DropDown or Bounce etc which would allow as to define moves like a character being hit in the air hard and need to fall down hard and then bounce across the screen. I relize that this probably isn''t the overall "best" way of implementing this, but I think it would work quite well. Anyway, the point of posting this is to see what others think, there really isn''t a lot of info out there on this sort of thing which I found interesting. Erm, sorry for the large post, but thanks for reading if you got this far!

Share this post


Link to post
Share on other sites
Just to clarify, the conditions that have to met would form a set of triggers that would be checked each frame, this way we set a state when a specific trigger is satisfied.

Share this post


Link to post
Share on other sites
It may be worth having a search for Mugen, a 2D streety style fighting engine. They have a lot of docs with it that explains how to create and set up characters for it. Might be worth having a look for some *inspiration* On suitable tools and scripts etc.

Share this post


Link to post
Share on other sites
hmm... you can also do it this way: have your character to ''fix'' what kind of countering method or moves they have, eg. air defense/offence, standing defense/offence, crouching defense/offence, and chain-combos.... and then have your basic ''AI'' like this:
- enemy attack from ''sky'' -> execute air defense
- enemy standing defence -> execute crouching offence
- enemy fireball and in range xxx -> execute combo-1 (eg. jump forward, HP, crouch MK, qcf HP )

ie. air defence:
for Ryu/Sagat-like defined as dragon punch/uppercut
for Guile-like defined as Somersault kick.
....

... just some suggestion.


Share this post


Link to post
Share on other sites
Well, that''s kinda the way I am expecting to do it, except each move or "action" of a character is represented as one of it''s states, and those states of a character can be triggered depending on the states of others and whether or not there is a collision.

Share this post


Link to post
Share on other sites
So you would have a "character manager" to manage your character objects and the character manager would execute the scripts and notify the characters of their state changes?

Share this post


Link to post
Share on other sites
Yes, something similar to that. Except in this case the scripts are made up of functions that return bools based on certain conditions that need to be met. The granularity of the functions should be quite small, so the functions could be inlined and I''m thinking of setting up and array of function pointers to these functions so all the functions for one state can be called and if they all return true then that state is played out.

At the moment I''m trying to think of a way to implement a good way of controlling the characters for each state, some kind of scripting system is also in order, so if the character enters the "FALL_DOWN_AIR" state for example, a script will play that makes the character fall down to ground level in a manner specific to that character, this way we avoid a fighting game that is really generic i.e each character has it''s own style.

Share this post


Link to post
Share on other sites
If you have a single class called Character that implements several virtual functions, and then have every specific character type inherit from Character and override the virtual functions, by calling the function for player1.FallDown(), depending on the type of variable that player1 was created as, you will see something different. It avoids a great many case statements and insane logic loops.

For the combat scripting, most of the controls should be the same, or at least similar. The defensive AI should react essentially the same for all characters, but modified to their specialty. For instance, if someone is jumping in the air at you, Ryu would execute a high kick, but Balrog would do an uppercut. You can use the virtual functions that you override for that kind of thing as well.

You didn''t mention anything about difficulty levels, but a good starting point would probably be to set a timer and count from the time that the player makes an attack. Standard difficulty dictates that the computer must wait 1.00 seconds before reacting. Difficulty ranges from 0 to 100, with each point deducting 1/100th of a second from the reaction time. Anything above 90 or so should be essentially impossible because humans can only react so fast. After that point, the computer reacts faster than you to the point that an instant after you try a move, the computer would execute the appropriate counter move, making the game impossible to win at those levels except through extreme luck.

Just some thoughts. Good luck.


Looking for an honest video game publisher? Visit www.gamethoughts.com

Share this post


Link to post
Share on other sites
"If you have a single class called Character that implements several virtual functions, and then have every specific character type inherit from Character and override the virtual functions, by calling the function for player1.FallDown(), depending on the type of variable that player1 was created as, you will see something different. It avoids a great many case statements and insane logic loops."

I initally started doing it like that, but when I though about it some more I decided that I wanted to be able to just distribute a data file if I wanted to update any of the characters and not the .exe. It would make that particular part easier, but I have decided to go for the data file approach which stores data for all the states, this data relates to the characters attributes such as left movement velocity, right movement velocity, fall velocity (or weight etc). This way, I get a lot of control over specific states in which each character can be in while the state manager class tracks the states for each player and can inform them when they ned to change this way I can have a chain of states to play out for that character.

"For the combat scripting, most of the controls should be the same, or at least similar. The defensive AI should react essentially the same for all characters, but modified to their specialty. For instance, if someone is jumping in the air at you, Ryu would execute a high kick, but Balrog would do an uppercut. You can use the virtual functions that you override for that kind of thing as well."

Hmmm, good point. At the moment that sort of thing is linked to the animations for each state and I''m thinking that the collision detection first checks the outer boundaries of each frame to see if they overlapped and then checks all that animations collision rects to see where and if there is a collision.

So, while one character could play a kick animation for heavy kick another could (like you say) play a uppercut punch.

"You didn''t mention anything about difficulty levels, but a good starting point would probably be to set a timer and count from the time that the player makes an attack. Standard difficulty dictates that the computer must wait 1.00 seconds before reacting. Difficulty ranges from 0 to 100, with each point deducting 1/100th of a second from the reaction time. Anything above 90 or so should be essentially impossible because humans can only react so fast. After that point, the computer reacts faster than you to the point that an instant after you try a move, the computer would execute the appropriate counter move, making the game impossible to win at those levels except through extreme luck."

Yeah, I hadn''t put much thought into diffulty levels yet, I''ve been thinking from mainly a 2-player perspective as these games are always more fun this way, and also netplay functionality.

"Just some thoughts. Good luck."

Thanks .



Share this post


Link to post
Share on other sites
quote:
Original post by mtaber
... if someone is jumping in the air at you, Ryu would execute a high kick, but Balrog would do an uppercut...


Ryu doing a high kick?... unless the player is jump-dropping about 45deg or less... I would rather go for light dragon punch. Balrog uppercut?? Do you play Street Fighter 2? Are you saying Sagat's Tiger Uppercut?
quote:
... standard difficulty dictates that the computer must wait 1.00 seconds before reacting. Difficulty ranges from 0 to 100, with each point deducting 1/100th of a second from the reaction time. Anything above 90 or so should be essentially impossible because humans can only react so fast.


Good point. But I don't think 'standard' difficulty need to wait for a second? The player could give them nice combos.
quote:
After that point, the computer reacts faster than you to the point that an instant after you try a move, the computer would execute the appropriate counter move, making the game impossible to win at those levels except through extreme luck.

It depends on the player skill. Since every move got its own delay, you could use that advantage to trick the computer.. even if the computer have zero delay on the AI.


[EDIT] Ooops... I guess you mean Balrog normal punch. But this is only effective when the player is high-up above.


[edited by - DerekSaw on July 31, 2002 10:06:42 PM]

Share this post


Link to post
Share on other sites
DerekSaw, what I meant was if someone jumped at you and was really close. When that happened and you executed a heavy kick with Ryu, he would kick almost straight up.

Redline, you can change the parameters of the game very easily and still use inheritance. When you call the constructor to Character, then call character.init(CHARACTER_TYPE_1). In the init function, you can read data from a configuration file, describing CHARACTER_TYPE_1. If you abstract the attributes enough, like for instance you said move velocity, then all of them will have that attribute. You just define them differently in the data file. I think you''re making it more complicated than you have to.


Looking for an honest video game publisher? Visit www.gamethoughts.com

Share this post


Link to post
Share on other sites
quote:
Original post by mtaber
DerekSaw, what I meant was if someone jumped at you and was really close. When that happened and you executed a heavy kick with Ryu, he would kick almost straight up.

Redline, you can change the parameters of the game very easily and still use inheritance. When you call the constructor to Character, then call character.init(CHARACTER_TYPE_1). In the init function, you can read data from a configuration file, describing CHARACTER_TYPE_1. If you abstract the attributes enough, like for instance you said move velocity, then all of them will have that attribute. You just define them differently in the data file. I think you're making it more complicated than you have to.


Looking for an honest video game publisher? Visit www.gamethoughts.com


Indeed, that would work fairly well, and I have been considering this fact and what you have said and overall it would probably make it easier. In the end I suppose I was simply didn't like the idea of distributing and .exe to update the game.

[EDIT] That is, if I wanted to add characters to the game etc.



[edited by - Redline on August 3, 2002 10:53:00 AM]

Share this post


Link to post
Share on other sites
about AI...
you shouldn't write a perfect set of AI responses.. first of all it's damn boring and it's hard to do as well (almost impossible?)
Currently I use a simple AI in my game that just performs a random move depending on it's actual status, distance from enemy and if enemy is turned with back to AI or if AI is turned back to enemy.
So I have got something like:
if distance<50
random=rand()%100;
if random<30 callkick
else if random<60 call punch
else call nothing

It works very well if you take into accout that it doesn't need all that much effort to create. Additionally by using lots of randoms AI behaviour isn't predictable and it's fun to see what it does.
This AI is for an easy level. For more advance AI I want to add:
-for medium level - checking what enemy does and takeing it into account while performing own actions
-for hard level - additionally measure exact distance between AI and enemy and perform attacks/moves that will work best from this distance, also takeing into account enemy move.

So while easy level enemy is dumb and can be beaten quite easily, while bringing a lot of fun into game(because it doesn't wait 1sec between moves like someone proposed), medium and hard levels of CPU AI should be much harder to beat, but still keep a lot of randomness.

To define moves I use a state-machine which works very fine. Althrought I hardcode everything so there's no possibility to create characters by someone from outside. I have got also a more complex collision/hit detection system, which not only tells me if there was a hit or not, but also checks how exact a hit was and use a different actions for it. (for example a poor hit, while takeing some hitpoitns from enemy and makeing him go back a lil might still come as a bad move, because enemy will have a chance to start his counterattack before we finish our attack and get a chance to do something. Of course it's not the case if you make a good hit, then you can try a combo, or your enemy falls down if hit was really good)

[edited by - MirekCz on August 3, 2002 11:10:48 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by MirekCz
about AI...
you shouldn''t write a perfect set of AI responses.. first of all it''s damn boring and it''s hard to do as well (almost impossible?)
Currently I use a simple AI in my game that just performs a random move depending on it''s actual status, distance from enemy and if enemy is turned with back to AI or if AI is turned back to enemy.
So I have got something like:
if distance<50
random=rand()%100;
if random<30 callkick
else if random<60 call punch
else call nothing

It works very well if you take into accout that it doesn''t need all that much effort to create. Additionally by using lots of randoms AI behaviour isn''t predictable and it''s fun to see what it does.
This AI is for an easy level. For more advance AI I want to add:
-for medium level - checking what enemy does and takeing it into account while performing own actions
-for hard level - additionally measure exact distance between AI and enemy and perform attacks/moves that will work best from this distance, also takeing into account enemy move.



I agree, I wouldn''t hardcode AI response at all...ever, it would simply make the characters uninteresting. The points you bring up are valid and the technique seems simple but effective.

quote:


So while easy level enemy is dumb and can be beaten quite easily, while bringing a lot of fun into game(because it doesn''t wait 1sec between moves like someone proposed), medium and hard levels of CPU AI should be much harder to beat, but still keep a lot of randomness.

To define moves I use a state-machine which works very fine. Althrought I hardcode everything so there''s no possibility to create characters by someone from outside. I have got also a more complex collision/hit detection system, which not only tells me if there was a hit or not, but also checks how exact a hit was and use a different actions for it. (for example a poor hit, while takeing some hitpoitns from enemy and makeing him go back a lil might still come as a bad move, because enemy will have a chance to start his counterattack before we finish our attack and get a chance to do something. Of course it''s not the case if you make a good hit, then you can try a combo, or your enemy falls down if hit was really good)

[edited by - MirekCz on August 3, 2002 11:10:48 AM]



At this point in time I was thinking of implementing a simple vector/array of rects that define the hit locations on the characters (on a per frame basis of course), that way I avoid CPU intensive per-pixel collision detection and I get pretty much all the flexibility I need, and can add something similar to yours such as hit location detection (which is really neccessary if I want to play different animations depending on where they are hit).

Can I ask what type of method you used to implement your base game logic? That is, how do you detect when states in characters are to change? As you may have read, I am thinking of using a trigger list atm, which is made up of function pointers.

Share this post


Link to post
Share on other sites
Well I use a set of animations and depending on situation (standing, kneeing, flying) I allow only some specific animations to be started (upon key input).
I have got also a possibility to play more complex animations created from 2/3 smaller ones.

Share this post


Link to post
Share on other sites
It's possible to define a base player class and implement it almost completely in a data file. It would be much cleaner then what you propose, and still not have to distribute an exe. Might be worth noting that the exe is probably gonna be one of the smallest parts of your game, and in the real world, is almost always going to be redistributed along with any kind of patch.

Implementing a sort of scripting language as you propose would be very mod friendly (then again, so is what I suggest), and allow people to perhaps download custom fighting techniques and modify them to their liking.

Maybe you should consider having only one charachter to choose from, which is completely customizable, effectively leaving the AI to the people who play your game. Appealing to people who know a little more then average about martial arts and maybe AI might give your game its own little niche, it's going to need to be something special to get attention anyways.



[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people

[edited by - wild_pointer on August 6, 2002 8:03:48 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by wild_pointer
It''s possible to define a base player class and implement it almost completely in a data file. It would be much cleaner then what you propose, and still not have to distribute an exe. Might be worth noting that the exe is probably gonna be one of the smallest parts of your game, and in the real world, is almost always going to be redistributed along with any kind of patch.



Referring to the action functions? I could certainly use the states information data to create a generic movement function that uses the velocities to move the character around on the screen.

quote:

Implementing a sort of scripting language as you propose would be very mod friendly (then again, so is what I suggest), and allow people to perhaps download custom fighting techniques and modify them to their liking.



ATM I am thinking mainly of my sanity . To make it even easier I would probably have to create some sort of tool to help design the characters

quote:

Maybe you should consider having only one charachter to choose from, which is completely customizable, effectively leaving the AI to the people who play your game. Appealing to people who know a little more then average about martial arts and maybe AI might give your game its own little niche, it''s going to need to be something special to get attention anyways.



Hmm, and interesting idea. But then, people would still need to create the animations to go with those moves that they create.

Share this post


Link to post
Share on other sites
quote:
Original post by MirekCz
Well I use a set of animations and depending on situation (standing, kneeing, flying) I allow only some specific animations to be started (upon key input).
I have got also a possibility to play more complex animations created from 2/3 smaller ones.



Yeah, that sounds pretty good, but does it give you enough flexibility with your characters? I am thinking of being able to chain up states here (on a stack etc) so I could a group of actions played out.

Share this post


Link to post
Share on other sites