Desert Rally

This is a 3D flash game I wrote with ActionScript 3 using nothing but Flex SDK compiler on Linux (no Adobe Flash Professional, no external libs). Size is a mere 700 KB. No external lib used. No Adobe Flash Professional used. What's interesting about this game is how I approached optimizations in terms of performance and final file size. Below is some of the interesting challanges I faced:

Challenge 1: Arabic fonts: Prior to Flash 10 The only way to guarentee Arabic text looks fine was to convert text to vector graphics (or bitmap). But that makes the file size big and text can not be dynamically generated. I was in luck flash 10 has Arabic support. But some systems don't have Arabic fonts so I had to embed one. But since the font size is relatively big (it's a stylish font), I found a way to selectively embed only certain characters that I needed. That reduced my final font size from 110KB to 40KB.

Challenge 2: 3D looking cars: I used Softimage to render the car using toon material. I wrote a little script to render the car from 231 angles (21 steps in yaw, 11 in roll). I made sure the car is symmetrical so that I only need to render 21x11 frames instead of 21x21. The frames are rendered with alpha channel and combinied into one 990x1260 image using ImageMagick. Then to save space, the RGB and alpha are split into 2 files, RGB is saved as jpg. Alpha is saved as indexed png (16 colors palette).

Challenge 3: Car colors: It would take way too much space to create one image for each car color. The obvious solution would be to split the car windows and body and apply color transformation to the body. But that also takes extra disk space since there will be one extra image. So I wrote simple pixel shader (yes, flash has pixel shaders!) that "magically" changes the color of the body and leaves the windows color intact.

Challenge 4: 3D hills: The ground tile is a small image that's repeated vertically. After randomly scattering the hills around, each hill gets 2 memory spaces. One for the hill image that'll be dynamically generated based on the texture of the ground at that position. The other one is for hightmap that's also created dynamically by drawing a blurred white circle on a black background. The hill bitmap is first filled with the background tile based on its position. Then I wrote a displacement shader that creates a bump in that image by displacing pixels based on the heightmap. After that another shader does the lighting using normals created from the heightmap. After rendering the hills, the heightmaps are kept in memory because they're needed in the physics simulation part (to test the height at points inside the hill rectangles).

Click on the game area to focus keyboard input. Use arrow keys to play, space key to select, and escape key to go to main screen.

DesertRally

Alternative content

Get Adobe Flash player