Skip to content

1. Track model and timing

Siorki edited this page Nov 10, 2013 · 4 revisions

The bare minimum for a racing game is a car, a track, and a clock. We will address the latter two first.

The grid

I chose the easy way for the track representation : no bends at a fancy angle, no junctions, crossroads nor superimposed sections. The track is a single curly line, laid out on a 16x16 map. Each tile can only contain a straight, a 90° curve, a bridge, or nothing. The game engine has to be kept compact and simple, so anything costly as far as code size is concerned was left out. The only exception is bridges and underpasses that are part of the feeling of the original Supercars, and that bring so much complexity to the tracks in Staccato.

Tiles

Minimal description

This 16x16 tile map is one of the representations of the track used during the game. It is not, however, the format used to store tracks inside the code, and is instead rebuilt each time a new track is chosen. I substituted a more compact description, which only features direction and altitude changes. Before going into details about the track format, I need to introduce two concepts :

  • a section is a portion of a track covering exactly one tile. Tiles may contain either 0 (grass), 1 (straight or curve) or 2 sections (bridge).
  • a block is a set of consecutive sections sharing the same curvature - all straight, or all in the same bend Section and blocks description

The track description is a array containing, in that order :

  • a float value, to be used as random seed to generate the terrain in the renderer. It serves no purpose for the model.
  • x, y, z : starting coordinates for the track (finish line).
  • a, b, c : series of triplets representing a block of the track
    • a is the direction : -2 for left, 0 for straight, +2 for right
    • b is the length of the block in sections (or tiles)
    • c is the slope, or delta altitude : positive for up, negative for down. Either a or c must be zero, the game engine does not support slanted curves.

Expansion for use by the engine

Upon loading a track, this shorthand description is used to produce both the tile map, and a detailed array of section, listing for each of them the location of the matching tile, its altitude, direction, angle, slope steepness, along with a flag to be used only for CPU cars. Both representations remap easily to each other : Starting from a section, the array contains its location on the map. Starting from a set of coordinates, the tile map gives the index of the section. For bridges, it contains both indexes, the one from the bridge being shifted eight bytes left. This limits the tracks to 256 sections, which proved to be enough (Maelstrom Speedway is 190 sections, or 3040m, long)

The index of sections is used by the game engine to make sure that the player follows them in order and does not take shortcuts. Braking to a stop past the finish line, backing up then crossing it again does not credit you with an extra lap. Neither does completing a U-turn and heading the wrong way, dodging the incoming CPU cars along the way.

Road width and collisions

The asphalt is only 12.8m wide. Said otherwise, the road width is 80% of the tile, 10% remain on each side. Two parallel strips of road, going side-by-side, therefore leave room for a small patch of grass in between them. This will be of importance upon rendering, and be presented in more details in the [geometry chapter]. It also impacts the model, as the cars are not allowed to stray on the grass. The road is bounded by solid barriers on each side, and since object deformation is not supported, they will stay in place and bounce the cars back on the asphalt. Road borders are thus considered to be rigid bodies upon computing collisions.

 

Back to main page | Article 2 : Car Physics