AGS Awards nominations close at 13:59 GMT on Saturday 10 February 2018. You haven't yet nominated, so you've got 18 days and 10 hours left to play the games and decide which to nominate!

Author Topic: Coding Fight AI  (Read 123 times)

Coding Fight AI
« on: 30 Dec 2017, 02:19 »
Hi. I am creating a game in AGS and have recently finished creating the monster sprites in Aseprite. However, I am clueless as to how to code some sort of AI for a fight scene. I have a QFG kinda fight style in mind, how would I go about coding this? (I also skimmed the scripting tutorial, but still am confused as to how to code an AI).

Thank you.

PS In QFG the fight style angles are different from those of QFG4. One shows a front view of the villain whereas QFG4 shows a side scroll fight scene playing out. How would this be different in regard to code? (I have drawn all the villains from a side view in order to fulfill a QFG4 like fight scene).

Snarky

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: Coding Fight AI
« Reply #1 on: 30 Dec 2017, 08:23 »
It can be done, but it is a complex and difficult task. Mage's Initiation (a QFG clone being made in AGS) spent well over a year just fixing bugs in their combat system. That's not counting the time it took to write it in the first place, mind you! And this is for an experienced AGS coder with several major games released. (Admittedly their system sounds like it's very complex, with a lot of different spells, weapons and enemies to deal with.)

So my advice for you is to not try it. Not for your first game, at least.

Turn-based fighting is much easier, and you can see examples of it in e.g. some of the Oceanspirit Dennis games.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
Re: Coding Fight AI
« Reply #2 on: 30 Dec 2017, 19:06 »
Coding is not only about knowing the programming language, but first of all about writing algorithms and structuring your program.
Complex algorithms are usually broken into smaller parts, to make it easier to understand and code.

My biggest advice to anyone who begins to learn programming and wants to make something complex, like fighting in this topic:
First, write down what you'd like to have "on paper". At this stage there's no need to go into much details, just rough outline. What objects would you like to have on screen, how these objects act, how player is supposed to act.
Second, try to break the whole scene down to smaller tasks, and learn to make these one by one, separately. After you did, you will be able to combine complex scene out of those pieces.

For example, you want to have QFG-like combat. This involves a picture of a player that swings sword (or does other stuff) by player's command and picture of enemy that does actions by AI command. Essentially this means that there is some visual character that receives commands from a source. Source can be either player or AI script.

Try following: make a simplier scene (perhaps in a test game), where you have a character on screen, that runs animations when player presses a button. Learn how to test when action ends, so that player could not run new actions before that.

Then make another scene where same character is controlled by a script. Learn how to make it launch same actions randomly, by a timer.
It may be important to learn how to "detach" animation script from AI script, to make them independent of each other. This way you will be able to connect same AI script to multiple characters.

Next step: teach AI to react on opponent's actions. You do not have to have actual opponent for that. Implement "imaginary" opponent. For example, remember what opponent is doing (defending, attacking, etc) in a variable, put a text on screen telling that to make it easier for you, and let player change that imaginary action by key press. Make AI react to this variable: when you set it to "attack" - AI should defend, and vice versa (or other variants).

Fourth scene could be where two characters stand face to face. They may be even both controlled by AI. Make them fight with each other using techniques you learnt in previous three scenes.

After you succeed in this, move on to combat rules and GUI part, with health, winning and loosing conditions, and so forth.
« Last Edit: 30 Dec 2017, 19:08 by Crimson Wizard »