Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Enemy AI for 2D Brawler

Author
Message
Torioda
8
Years of Service
User Offline
Joined: 18th Nov 2015
Location:
Posted: 18th Nov 2015 22:51
Need help for a 2D Brawler. I have a player character moving on screen and now I need to make an enemy AI to attack the character. The book I have in covering the subject doesn't do a good job in explaining or providing examples of code that I can use for my game. Any help, suggestions, or links are appreciated. Thank you.
Suicidal Sledder
19
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 1st Dec 2015 03:37
explain 2D?

like a top down view like RTS perspective or more like the oldschool mortal kombat / streetfighter type games?

If you mean more of a top down view brawler then I would highly suggest A* for path finding and then a RNG (random number generator) to decide ranged/melee attacks and what attack to use.

If you mean more of a side view like MK or SF then I would use states with a RNG. Use if/then to see if the enemy is within range, if it is then use the RNG to pick an attack. if the enemy is not in range then you can chose between states for retreating/advancing until it is in range, then every so often use the RNG to pick an attack or "set" of attacks like combos.

The wide variety of moves and combos can be stored easily in a UDT which would also be helpful for storing animation frame numbers. If you need help with A* you can google tones of tuts as it is a very common pathfinding algorithm. I also have DBPro code for A* that I wrote back in the day that I would be happy to share.

Cheers
Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who\'da thunk it?
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 1st Dec 2015 08:49
I think it has to tie in together with the actual player handling and animation code.

I mean, handling the movement and animation logic with AI in minds makes sense. Like, when your character is doing anything, there are only a few things that they can do next - if they are standing still then they can walk or duck or jump or attack, but if your character is ducking, they can only attack or stand back up again. I would see it as modes, maybe 32 different actions, and each action can lead to definable actions. Maybe you'd have a matrix of modes, 2D, and cross reference the modes, so mode 0 might be an idle loop, then any modes that can be set from an idle loop get added to the matrix, if walk forward is mode 1, and walk backwards is 2, then...

0,0=1
0,1=1
0.2=1

You would add all the modes, and check each loop for possible next moves. This not only provides reliable and controlled animation handling, it also makes it much easier to add AI. If an AI character is idle, then it can move forward or back, or jump etc - but each 'option' would be defined already, so you mostly just worry about picking the best option.
People say boxing is like chess, and there's chess boxing, and really you could apply chess AI to a fighting game in the same spirit. Like at any point, based on the characters mode, there will be options for the next move to perform... so what if you assigned certain variables to check and give each option a value...

Character is jumping and is above the opponent, +10
Character is moving closer to opponent, +2
Opponent is attacking, -5
Character defend attack, +5
Opponent is within striking distance, +2
But opponent is defending -2

So with these sorts of conditions, you can assign each move option a score, and pick the highest scoring move each time.


I'm actually working on a 2D beat-em-up myself... for other reasons though. I'm an Atari ST fan, and the ST never got a really bold fighting game, like the ones we saw in arcades and neo-geo or even the Amiga. The ST port of StreetFighter2 was horrific, and we never even got Mortal Kombat. Anyway, I'm making a fighting game on ST, with big bold sprites and mostly it's just because there isn't one already. It runs at about 15fps, which is not too shabby for a 7mhz computer and probably 2 or 3 times smoother than SF2. The action mode matrix is what I'm doing for that, because a whole lot of conditions would slow things down too much - effectively it pre-calculates the possible moves so you can avoid the numerous and messy IF...THEN statements.

Login to post a reply

Server time is: 2024-03-29 09:26:28
Your offset time is: 2024-03-29 09:26:28