SkidWRX is my first attempt at Flash Actionscript. It is a fully featured top down race against the clock car driving game. It features lap timers, collision detection, and some car physics (allowing for handbrake slides and for differing surfaces). It also features some nice touches like skidmarks. If you want a quick race against the clock game for your site... here tis!

It is in its form now a fully playable game, and new courses can be created quickly for it. As such I am putting up the fla for download so that anyone who wishes to use, or even better build upon this engine can do so.

In downloading this engine, I only ask that you share any changes (and improvements!) with me, so that I can link to it and learn from it. I am in the process of creating a more advanced version with better physics, this will be released as it is done.

Car Graphics

Great resources for car graphics, are the GTA community websites, below are a list of sites with great top down racer car images, from Subaru WRXs to Dodge Vipers, Ferraris and Minis (please ask for permission before using).

Car Physics

There are a couple of good sites explaining car Physics. These are the Monstrous physics site, and the racer.nl site The Monstrous Physics site details a very true to life and accurate physics model for cars. Perhaps too much for the requirements of a flash racing game. It does however provide an excellent basis (if you have a head for maths!)

The other site racer.nl is a site dedicated to a free 3d racing game. It details physics, along with feature sets for a number of world tracks and cars. It is this aspect that is particularly useful, each car has a file with it called car.ini using this one can determine all the car specific details for differing cars, from gear ratios to dimension, weight power etc etc. These can then be used to create differing characteristics for diffferent cars. I hope to create a very accurate but very playable model soon. (I figure several years of engineering at University should be used at least once in my life!). The starting point for this engine is the fla from senocular, he has a source (called Driving) up at his website.

Changing Car Characteristics

In this implementation of the game this is limited (but can still be done) a user can configure a number of car specific attrributes this allows for multiple car types to be created. These are located in the action script for the car on frame 5 they are well commented so you should be able to figure them out ok.

accel = .2 // acceleration due to gas (up arrow)
steer = .08 // steering tightness
steer_normal = .08 // Default Steering
steer_handbrake = .099 // Incremental increases for handbrakeys
steer_threshold = 4 // Speed where steering at its most manouvreable
MINspd = -5 // max reverse speed
MAXspd = 22 // max speed on straightaway
MAXskiddisplay = 2 // Display skids on slides till this value reached
MAXturnSpd = 10 // maximum speed while turning
MaxTurnSkid = 18 // Maximum speed in turn before skidding
deccel = .92 // decelleration due to brakes (down arrow)
handbrake = .93 // decelleration due to brakes (down arrow)
handbrake_traction = 20 // Amount of slide for handbrake higher is more
drift = .98 // deceleration after letting off gas

Car collsion detection is done through using two movie clips placed at the front of the car object it self. Its simple at the minute, but down the track will allow for more accurate slams and crunches!

Changing World Characteristics

Most of these are explained with the code. The surface parameter allows the surface to be specified, play around here. One thing that could be fun is setting up parts of the track to be different surfaces, and on a hittest changing the value of surface, that allows for tarmac dirt, ice you name it to be a part of the game.

Traction is a value that determines 'slipperiness' and is used to make the car slide around more, like hammering on gravel!

// GLOBAL CONSTANTS AND VARIABLES

speed = 0 // duuuh!
surface = 3 // Tar = 10 gravel = 1 ice = 0.5
traction = 5 // the higher the more slippery init value
traction_max = 1 // Max Traction
bounceBack = .6 // percent of speed when bounced back from hitting an obstacle
laptimes = new Array() // Laptime counter
laps = 3 // number of laps
for(var i = 1;i <= laps;i++){ laptimes[i]=0;}
checkpoints = new Array() // Checkpoints - no cheating on laps
checks = 4 // number of checkpoints
for(var i = 0;i <= checks;i++){ checkpoints[i]=false;}
lap = 0 // current lap

Creating Tracks

This game currently only has one track hardwired into it. Further improvements in the future will allow for this to be changed. Anyways, this section will detail the creating of new tracks its a fairly quick, and dirty but fast process.

My track is about 1500x1500 bitmap image. I knocked it up in photoshop. All the track components are in the folder Track 1. The movieclip to use is racecourse and we use this to build all the track components. Maximum size is 2880x2880 (flash limits)

Load in your bitmap course.

Over the top of that put a vector image that represents the course. The engine will check to make sure you are on it, and if not will start to slow you down. make it a movieclip (F8) and call this instance track. Put it over the course so you can see it. some script will hide it from the game.

Create a new layer, and on this layer draw solids around all the things you can collide with. Cones, walls transparent walls in the middle of the track, whatever you like. Select it all and make it a movie clip. Name this instance of it crunchers

Finally use the checkpoint movie clip, and position (rotate etc etc) FOUR around the track. Call them check0, check1, check2, check3. These are here to stop dirty cheaters from not doing the full track!

Set the car start position on the car movie clip in both frames 4 and 5 of the movie. (I am sure theres a better way!)

Currently the tracks have no 'world boundary' there is retardation of the car speed if you go 'off piste' but you can drive around for ever anywhere!

Lap Timer

The laptimer uses the MCBenney timer prototype as described in the flashkit forums. I have added a display function that will display the time in minutes:seconds:milliseconds its called displaytime(ms), you can find it in frame 5 on the actionscript for the car, (most game code is in there!)

The array that stores the times, and displays them is a dirty dirty hack, and show my complete inablity to code :D. It is hardwired to only do three, should anyone come up with an version with better lap time handling I would be most impressed!

Sound

As such I have not added sound, however I have commented the areas where the skid sounds would be activated, as there are the handbrake skids and the going really fast round a corner skids.

Ideas for moving forward

There are a million ideas for moving forward, I intend on working hard on a car gaming engine and building an interesting collaborative racing game. Some quick sugggestions...

  • Hi score table
  • Loading more tracks after each one is completed
  • Better Lap timing
  • Sounds
  • Multiplayer!
  • Better physics
  • Better Collision
  • Tile generated tracks
  • Mini Map
I hope to learn as well from any improvements that others make, so please share as well.

Thanks

Some thanks I need to extend for aiding me in the development of this game. Most from the games forum at flashkit!

Tomsamson for getting me started on the skids and helping me understand the coordinate systems. MCbenney for sharing his timer code, very useful piece of code. senocular for his source on car movement which became a foundation block for this engine pepworks for sharing the zen of collision detection and thinking outside the 'boundary box'

Download!

Grab the FLA (3mb) (zipped)

One more thing, I hope that should you use this engine that somewhere you will include a link back to this site at http://www.markfennell.com

Support

If this is my first piece of actionscript you should really be able to figure out whats going on. Its pretty self explanatory. Feel free to email me, but please don't be disappointed if I don't have the time (or knowledge!) to help out! © Markfennell.com 2004

SkidWRX v1.0
The first version of the SkidWRX top down car racing game. With a lap timer, and a single track you pit your wits against the clock. Source link at bottom of page. License this game.

More Games