2009 March 10
The 4k flash game contest at gamepoetry is over, and the gag order about entries has been lifted. I decided to try my hand at this, and came up with a game that's a little different than you normally see. This game REQUIRES a webcam.
For the apple people with an iSight, some settings jiggling may be necessary: Right-click on any the movie and choose "Settings...", then click on the camera icon. Choose "IIDC FireWire Video" from the menu. You might have to reload the page. This tip from: Christian Cantrell
Get the source
Face Dodge illustrates 3 things for me: The mean-shift histogram tracking algorithm, procedural music, and a smidge of flash 10's 3d abilities.
First things first, Andre Michelle deserves a HUGE shoutout for the music code. I minimally modified one of his experiments to get it in there. I don't claim to understand every little bit either, though I have the majority down.
The mean-shift algorithm is the heart of the game, and is more-or-less the same algorithm you'll find described in the results of a google search. The main differences here are that I used some bit manipulation to reduce the histogram space from 256x256x256 to 16x16x16, and I did not use the bhattacharya coefficient (though I wanted to, it works "well-enough" without it) to fine tune the convergence. If you're anything like me, reading over the algorithm itself will mean a lot more than a wordy description, so I do recommend it.
For the 3d, it's a simple matter of creating a single 3-sided column (left, front, right), and moving that around in 3d with the help of the flash 10 features, and blitting it to a bitmap. This can simulate a crapload of columns and only needs one actual display copy.
Tricks to keep the filesize down: The biggest trick I discovered was to use the flex compiler raw-metadata directive and pass it an empty string. This results in no metadata going into the swf, and saved me a crucial 250 bytes. Other tips include keeping strings short, abstracting repeated code to functions, removing any class references possible. For instance I could eliminate MouseEvent by using the string "click" rather than MouseEvent.CLICK, and using stage.stageX rather than event.stageX.
Related tags: competition, game
