Artificial Intelligence eh? I wonder have I ever disclosed the AI system of Mr Ball? It's not that advanced really, as compared to today's AI, which uses things like Neural Networks and stuff like that. Those are serious maths, but in Mr Ball's case, the AI system is basically a...
Random Number Generator
Not convinced that the whole game is governed by a random number generator? Well, here's the proof:
See the random(...) command there? That's the proof!
Well, I'm just using what's given to me in Game Maker to my advantage. But it's just a number generator, how significant is it?
Now, the whole AI system of the enemy is basically like this:
-choose a random attack
-executes that attack
-repeat
But then, if you were given a chance to look deeper into the source code, it's not that simple. It used to be only that simple, but as the AI system grew and matured for 4 years, it has many more additions.
The AI system is actually a big timer. Whenever the timer reaches its target, it executes a long list of codes, which is the "main code" for the boss character (the one that makes the boss attack).
When the battle begins, the boss character sets one of its properties, aprev, to -1. This property just means "previous attack". Each attack has its own id number.
Attacks that are very simple will not change the value of aprev. But for an attack that is made of chains of different motions and animations, that attack change the value of aprev to its id number.
Every boss has this part of code:
if(aprev>-1)
{
a=aprev;
}
else
{
a=floor(random(.... /*Number of attacks*/))
}
which basically means that when "aprev>-1", keep executing the same attack as the previous, otherwise, choose another random attack.
Chained Attacks (the ones like the Deperation Attacks, or attacks that require the boss to move to a specific place) are subdivided into many different parts, which are called "phases" in the system. So, everytime the "main code" is executed and a Chained Attack is chosen, the "main code" will execute once for every phase.
This may sound a bit confusing, but that's just the way how Mr Ball works.
This system, as I have said, it's about 4 years old. The longest "main code" that I have written so far stretches for 958 lines (around 17.8 KB, for about 30 different attacks, in Mr Ball 2D)
There is one bad flaw about this system though, it's very HARD to debug. Yea, whenever something goes wrong, sometimes, it's very difficult to look for the error.
Another bad thing about this system is that the timer for the "main code" must always be reset. If the timer were to stop, the main code will not execute and the boss will do nothing. Now, this may not be so bad in some cases, but most of the time, when the boss stops doing anything, the level becomes boring. This is usually one of the most annoying bugs in the game.
Well, that's all about the basics of the AI system of Mr Ball. Nothing much to it really, it's just a creation of my imagination. It may not be the best, but as long as it works, it's good enough for me. See you then!
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment