DickDynamite: behind the scenes
[ June 21, 2003 ] by Marco Lapi, a.k.a Lapo
This article is an overview on the features and the techniques employed in the making of "Dick Dynamite". Lapo also discusses the difficulties and the limits found working with Flash MX. Some of the complex topics touched in this article will be investigated in future articles.


(continues from page 1)

ARTIFICIAL INTELLIGENCE

In DickDynamite we have basically two different algorithms for the AI of the bad guys: one is "step-based" and the other is "path-based". Let me explain this a little bit better.

In order to make the enemies search Dick through the labirinth it is possible to calculate the next move of the sprite by just comparing it's position to the one of the hero and then taking the appropriate move (if the way is free).
This was our first approach to the problem and it is the type of AI that drives the most dumb of the enemy: The Blob.

Although this algorithm is not very complex and doesn't need too many cpu resources, it has some side-effects:
since the next move is calculated upon some "suppositions" based on the target position, this doesn't guarantee that you are really going in towards the hero. Maybe after 5 or 6 steps you'll come across a dead end.

Pic 2: the Blob uses a simple
algortithm to track Dick.

This can happen because just one step towards the target is calculated at every game cycle.

A better solution is to calculate the whole path to the target, and possibly the shortest one !
This is done using more complex algorithms (A* seems to be the most popular) that analyzes the entire map and constructs the right path between the enemy and the hero. (A series of articles will be published on this argument, stay tuned)

This kind of approach is the one we used to create the AI of the "Bouncer" and the "Hunter".
This part of the developement took us more time than what we expected: at first I wrote a simplified version of the A* (pronounced "A star") pathfind algorithm as a separate movieClip, just as a prototype.
Everything seemed to be ok, but once we implemented this in the game it was simply unusable !

The matter was that all these extra calculations slowed everything down to the point that all the game animations
had some sort of "hiccup" everytime the enemy calculated a new path.

So I went back to the prototype and started doing a series of benchmarks and ARRRRRRGHHHHH !!
I found that the average time for calculating a path was between 290 to 600 milliseconds, way toooo slooooow !

After some weeks of researches and experiments, I came up with a better solution, still based the A* algorithm
but much lighter, which allowed us to search a path in about 40-70 milliseconds !
To improve performance and save cpu time we also added a "path caching" system in the game: this optimizes the calculations
by reusing some of the information computed in the previous game cycles.

(continues on page 3)


        
 
 
Name: Marco Lapi, a.k.a Lapo
Location: Fossano, Italy
Age: 34
Flash experience: started out with Flash 4 back in 1999
Job: web designer/developer
Website: http://www.gotoandplay.it/
 
 
| Homepage | News | Games | Articles | Multiplayer Central | Reviews | Spotlight | Forums | Info | Links | Contact us | Advertise | Credits |

| www.smartfoxserver.com | www.gotoandplay.biz | www.openspace-engine.com |

gotoAndPlay() v 3.0.0 -- (c)2003-2008 gotoAndPlay() Team -- P.IVA 03121770048