May 5th, 2004
"N" is a Flash platform game that mixes a spectacular physics engine, fast-paced action and convincing A.I in a unique way.
The game comes also with an internal level editor to add new levels.
We interviewed Raigan Burns and Mare Sheppard from Metanet and asked them to talk about "N" in detail.

» You can download "N" from their website.

Q: First of all I'd like you to talk about your team members. Can you please introduce them ?
Metanet Software is comprised of two individuals, Raigan Burns and Mare Sheppard.
We live in Toronto and N is our first project as a team. Aside from game programming, Raigan does music and Mare does digital art.

Q: Is this your first flash game ?
Mare's first Flash game was CityDefender, which is being re-released later this year. But N is our first Flash game as Metanet Software.

Q: Where did you take inspiration for this game ?
From a number of places, ranging from abstract concepts to favourite games. N has roots in anime, minimalism, and our admiration for many games we've played, such as Soldat, Lode Runner, and Super Mario Bros.
We were also inspired by a number of papers published by various game developers -- one of the most important ones was Thomas Jakobsen's Advanced Character Physics paper.

Q: Can you describe the most important features of your game ?
(1) physics-based control
this was mostly inspired by other physics-driven games, such as elastomania and soldat. we thought that the depth of control and freedom created by a physics simulation would be really fun in a platform-game type of world.

(2) animation

Because we chose to make N in Flash, we were forced to accept certain limitations in terms of graphics and speed; because of the speed of the renderer, we knew that we could only have a small screen area changing each frame. so we could either make a smaller-sized game (320x200) which scrolled, or a larger game (800x600) which was mostly static -- we chose the latter.
We needed to make the characters in the game, especially the ninja, as engaging and individual as possible, even though they were required to be very small. We also wanted to be able to animate the ninja using keyframed animation as well as procedural animation; this meant that we couldn't simply draw the ninja in order to animate it. We had to build and "rig" a skeleton, similar to how 3D models are made for and used in other video games. We leaned on the Flash animation system to tween between existing static poses, which resulted in fluid movement and depth of character.

(3) design aesthetic

A popular conception of the ninja frequently involves weapons. Granted, a ninja's arsenal is very cool, but we wanted to emphasize the agility and awe-inspiring reflexes ninjas must also have. In N, the player is forced to avoid enemies rather than being able to eliminate them. This small change takes N from a standard platformer to one with a unique blend of action and puzzle elements. We really enjoy games with strange mechanics, and so many games have some type of shooting involved -- why not emphasize the movement instead?

Q: The game engine demonstrates spectacular physics simulations and precise collision detection. Can you get a little bit technical about it ?
The physics-based animation (of both the normal ninja and the ragdoll) is simply an implementation of Thomas Jakobsen's gdc2001 paper.There's nothing we can really add to that paper, we simply implemented his ideas in actionscript.

Our collision detection system is based on a grid; each cell (square) in the grid contains a static tile-shape. the collision system first uses the grid to determine which tiles are near the ninja, and then calls functions which actually test the ninja for intersection with the tiles.
T he collision tests against the tiles use a separating-axis-theorem-type approach: they test for overlap between the ninja and the tile along a set of directions. so, instead of a single 2D test, we use a series of 1D tests.

The SAT says that if we can find _a_ direction along which the shapes don't overlap, then the two shapes aren't intersecting; this lets us quit testing as soon as we find a "separating axis". So we only to the full amount of work (i.e. test all possible directions) when a collision actually occurs, which is relatively infrequent compared to the number of times the collision-testing functions are called.
W hen we find a collision, we push the ninja out of collision using "projection", as described in Jakobsen's paper. Since (at this point) we already have a set of directions along which the ninja and tile overlap, we simply choose the direction which has the least amount of overlap, and push the ninja out that way.

We've finished writing a series of tutorials which explains the collision detection system (and other interesting parts of the engine), including source code; we just need to make the diagrams and format them for html, and then they'll be released, so extremely in-depth information will be available very shortly on our website.


Q: The ninja has very nice animations, how did you work on those ?
We thought initially about what we might like to see the ninja do, and then began making static poses and keyframes for the animations. Once those were done, we tweened between keyframes and touched up the bone positions, and then added the new animation to the set of ninja animations. Then, at runtime we "hand-animate" the ninja by moving the playhead based on the value of some of the ninja's properties -- for instance, running is animated based on the surface velocity of the ninja, and jumping is animated based on the ninja's vertical velocity. This gives the player visual feedback about the state of the ninja.

Q: The death sequences are also nice and the ragdoll effect is great! Can you do a quick tutorial on how it works ?
It's straightforward "advanced character physics" from Jakobsen's paper.
T he ninja is modeled as 6 particles (2x hands, 1x shoulder, 1x pelvis, 2x legs), and 5 stick constraints (2x arms, 2x legs, 2x torso).
I n his paper, Jakobsen points out that you can implement different types of stick constraints, for instance instead of making sure the stick length is a constant value, you can instead make sure it's within some min/max range of values. we used this to allow the limbs to "bend", instead of always being a constant length.
to draw this model, we used the same skeleton/bone MCs as the keyframed animation; our trick (mentioned by Jakobsen) is to NOT model certain things, but instead simply fake them when rendering.
In our case, we model only the hand and shoulder to simulate an arm, NOT the elbow -- this way we can always make sure the elbow bends in the correct direction, without having to implement further (complicated) constraints. To determine where the elbow position is, given the hand and shoulder positions, we use a bit of geometry: we have the triangle shoulder-elbow-hand, we know the lengths of shoulder->hand, shoulder->elbow, and elbow->hand, so we figure out what the elbow's perpendicular distance from the shoulder->hand line should be.

click thumbnails to
enlarge them.





















click thumbnails to
enlarge them.

Q: Let's talk about the enemies. How did you implement their A.I. ?
Each game "entity" (enemies and objects, such as gold) is implemented as a very simple finite state machine, as described here: http://ai-depot.com/FiniteStateMachines/
Each entity can subscribe to various different events; an object-manager notifies all objects which have subscribed to event X whenever event X happens.

So, for instance, one of the events is "collision with player"; each game entity which registers his event has a callback TestVsPlayer() which returns true if the player collided, and false otherwise. It ALSO has to provide additional info in the case of "true". this way each object can respond differently to collision.
E ach event is implemented in the same way -- the object registers to receive notification of an event type, and must provide a callback function.

The other event types are very basic:
Update: this happens every time the game simulation is advanced; typically, objects "do" something, such as move or shoot, in response to this event.

Think: this is a special function; some AI processes such as raycasts are fairly expensive, and we need to make sure the simulation runs at at least 30fps. so, objects which need to run expensive calculations register for the Think event, and are notified once every FEW frames, instead of once per frame.
This way, we update the AI in small groups instead of all at once, and the cost of the calculations is spread over many frames. The idea comes from various AI articles in the "Games Programming Gems" series.
T he finding for moving objects is very simple and based on the tile-grid; grid cells which are empty can be moved through, and cells which contain non-empty shapes can't be moved through.

Q: An interesting element, among the enemies, is the homing missile. How did you implement the path-finding routines ?
The steering behaviour of the homing missile is another case of us simply implementing someone else's great idea; Craig Reynolds (who many will know in relation to "boids") wrote some articles about chasing behaviours for AI -- we simply implemented them exactly as described. ( http://www.red3d.com/cwr/steer/ )

Q: How did you plan the game engine ?
Our engines are sort of constantly evolving things. We start out with ideas for games and features we'd like to see in an engine, and we think about which ideas overlap enough to share an engine. We think about plausibility in terms of whatever platform we're using, how the engine can be tweaked and modified for future use, and how the systems will be broken down.
We often incorporate little projects we've been working on through the year, so the engine isn't built all at once, instead, it's progressive.
In this case, we'd been making various physics-simulators and tile-based collision systems for the past year or two, and so we took the latest version of each, modified them to be more game-friendly (they were designed as general simulators), and built the engine around that, adding things like the player logic and the object-manager as we needed them.

Q: Did you use strict OOP ?
Yes and no.
W e DID use the OOP idea of an "interface", but (since we were using actionscript 1) this was never explicitly defined, instead we simply made sure to document and follow these rules.
N ear the end we resorted to the tried-and-true solution of make hacky global variables, because the 2004flashinthecan award deadline was only a day away -- sadly, the judges thought that "starsky and hutch pinball" was a better video game than N

Q: Did you use Actionscript 1 or 2 ? Which one do you prefer/use ?
Actionscript 1, because we didn't have mx2004; we downloaded a demo and used that to publish the projectors so that they'd use the faster flash7 player.
We're beginning to use Actionscript 2 now though, but really -- the whole attraction of flash is how simple and fast it is to work with. The more rigid the language becomes, the less useful it is for quickly throwing together ideas. Specifically, we're not sure that investing the time to use AS2 is worth it, when we could instead invest the same amount of time and learn Java, and have access to the faster calculations and hardware acceleration.

Q: Did you use any particular "optimization trick" to squeeze every bit of performance out of the flash player ?
The only real technique we used was one which every games programmer should follow: never, ever use O(n2) algorithms.
A ll of the algorithms we implemented run in constant or linear time, which is the biggest "optimization" you can make in terms of performance.
S pecific to flash, function calls incur some overhead, so we actually eschewed using get/set methods for very-frequently-accessed properties, and instead simply referred directly to them (i.e. .pos instead of GetPos()).

I n hindsight this might now make as much of a difference now as it did in flash5.
A nother "trick" we used was return value optimization. Also, an important point to make is that the bottleneck of any flash game will almost never be the code (if it is, you're doing something wrong). it's the player's renderer (~60% of each frame is waiting for the screen to be drawn).
The speed of the renderer varies based on the area of the screen which changes, so if you want a large screen, use small moving objects. if you need scrolling/etc., you'll need to use a smaller screen.

Q: How long did it take to develop ?
6 weeks / 150 hours - plus hours developing physics sims/etc. in the first place (which took a few months of very lazy part-time work)
very roughly:
2 weeks: porting physics-sim into a more game-friendly collision/physics system
2 weeks: writing game code (enemies, etc.)
2 weeks: content (levels, graphics, sound) and testing/etc.

Q: What were the most difficult parts to develop ?
Ned, the editor, is a mess. Basically, it was written in a single day, and it's over 3000 lines of code, so that might tell you about how well-thought out it is we consider it a beta, for the most part -- it wasn't written for ease of use or for the general public, and still requires a number of changes.
soon we'll have to face that and rewrite it properly, but currently we're working on other, more fun things, such as a series of tutorials, and an online highscore system.

Q: Why did you choose to make the game a download-only executable ?
Speed. It's pretty CPU intensive, and the addition of a browser doesn't help.
M acromedia should invest some real time in developing some modern compiler technology for their language. for instance, even in flash7, the _length_ of a variable's name affects the speed of referencing it!!
T his is clearly done for no reason other than ease-of-implementation on the part of their programmers, and was fine in flash5, but now that they've had a couple years to get their footing, they should look at other byte-code-interpreted languages (such as Java) and see that their technology is obsolete.

Q: The flash player speed was recently enhanced with version 7. Do you think its performance is enough for games ?
well, it worked for N...

But we _were_ faced with limitations in terms of speed and graphics. however, our project was more ambitious in certain areas than many of the webgames being developed. the answer to this question really depends on what you're developing in Flash.

Q: The inevitable question: what would you expect from the next version of Flash ? Any wishlist ?
Other than a proper compiler/virtual machine (and maybe a JIT compiler), the only thing it really _needs_ is a faster renderer. I'm not sure if they can do anything about that without using OpenGL/DirectX, which I don't think they'll do.
we'd kill for the ability to read/write text files. _Kill_.
It's silly that this ability is still not included in the stand-alone player, since you can take your flash .swf, embed it in a director app, and use the director app as a "projector" which allows file IO. so basically, a home-brew projector made using macromedia's own tools is more functional than their official projector.. wtf?!
one of the biggest problems with macromedia is that they seem content to let 3rd party developers add the functionality they're too lazy to include themselves. I guess it's great for them -- they don't have to pay for adding basic features such as resolution-changing/etc... but in the end, it's the flash users who pay, which is pretty rude. their excuse is always "we need to keep the player size small", but.. one of our friends wrote a .dll in c to let us read/write files, and it's less than 1k in size.
we like flash, and think it's a great development tool, but there are certain aspects which make us think that maybe macromedia has too many marketing and PR people, and not enough good engineers.

Q: What about future projects ? Have you already planned new games ?
W ell, we want to first add the features we had to cut from N in order to finish it on time; for instance, the next release will feature an integrated online highscore system, including replays.
In terms of actually "new" stuff, we've started working on a new engine which will be polygon-based instead of tile based, and which will feature scrolling. We've also got a bunch of stuff we developed for N but didn't include, such as a little rope-physics simulation. And of course we have lots of ideas, but right now we haven't had time to properly work any of them out. Hopefully by the end of the summer we'll have a new game.

Right now, tutorials for N are our first priority -- we feel it's important to give back to the game dev community we've learned so much from.

 

back to SpotLight index



Have you played one of the best web games ever ?
Did you create the latest kick-ass flash game and would you like to seen it reviewed in these pages ?
Suggest us some high quality games to feature in our SpotLight!

Game suggestions HERE
| 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