THE N BUNKER Discord Server nplusplus
Tutorials Introduction
Original by Metanet Software, 2005 (archived version).


Welcome to Metanet Software's tutorial section.

These tutorials are intended to give insight into how we programmed N, and as well to hopefully inspire other programmers to start projects. Enjoy!

Beyond HitTest(): Collision Detection in Flash  [ download slides ]

These tutorials are aimed at anyone interested in implementing 2D collision detection and response for games, or anyone interested in how we implemented various parts of N.

We'll try to explain everything from the bottom up, so there might be some sections you can skip; we'll also try to include enough information so that even relatively experienced game programmers will hopefully find a few ideas they haven't seen before.

Some of the material covered in the tutorials isn't part of the released version in N, but was developed for N and then not used. This material will probably pop up in games we release in the future.

The purpose of these tutorials is to explain some of the things we learned while programming N; we had a lot of help from various online resources and would like to help the community in return by contributing to it.

Our ulterior motive is that we're sick of crappy flash "games", and want more people to realize that actionscript is a viable platform for developing fun, exciting games which are not simply "flash games", but video games in their own right.

Flash is especially attractive for small developers since it allows extremely rapid development, albeit at the cost of execution speed. Perhaps once everyone expects the quality of games made with Flash to equal that of games written in other languages, we'll see more actual games made in flash, and fewer ads-posing-as-video-games (which really suck when compared to proper video games, and which shouldn't be considered video games at all).

Each tutorial will be accompanied by polished source from our engine; we'll be releasing the full, unpolished source (minus the online/networking code, for highscore-security reasons) whenever we finish our next game -- which should hopefully not be too long from now!

The source code is written in actionscript, but should be easily understandable (and might seem somewhat pseudocode-like) to c or java programmers.

One warning about the source is that our coding approach is perhaps slightly too unstructured; in actionscript, function calls incur a significant overhead cost, thus we decided that for often-used and "basic" properties (which are unlikely to change in implementation) we would abandon the OOP approach of using an interface of get/set routines:

GetPos(),SetPos(p),GetRadius(),SetRadius(r), etc.

and instead would directly access the properties of the objects:

.pos .r

However, this method wasn't used recklessly, and was always considered an "interface". For example, if an object supported the interface "dynamic shape", it was required to have the following properties, which should always contain up-to-date data:

.pos .r .xw .yw

In retrospect, the renderer of the flashplayer is so slow that it's unlikely that any runtime calculation will become the major bottleneck in a game -- unless you're doing something that shouldn't be done at runtime, such as using an O(n^2) algorithm or performing a large number of calculations on a long list. At the very least, you could implement Get/Set routines, and then replace them during optimisation with direct property accessing if you need every bit of speed.