Voxel Game Maker

Docs Quick code

Racing

The race functions (place, lap, time, best lap, finished), the car's speed and a boost from code, with recipes for a podium ending and a lap-time bonus.

A level with Race gate objects is a race track, and with Game Settings ▸ Driving the player is a car (see the manual's behaviors page). The race runs by itself: the countdown, the laps, the AI Racer cars, the Boost pads, the wrong-way warning and the results. Code reads how it's going:

Function Gives
race_place() The player's place: 1 = in front (0 = no race in this level).
race_lap() The lap the player is on (1 at the start).
race_time() Seconds since GO (the finishing time once finished).
race_best() The player's best lap in seconds (0 = none yet).
race_finished() true once the player crosses the line on the last lap.
car_speed() How fast the player is going, in km/h.
car_boost(seconds = 1) A burst of speed for the player's car, like a Boost pad.

HUDs show the same without code: {race_place_text}, {race_lap}, {race_laps}, {race_time}, {race_best}, {race_speed}, and the Minimap element.

#A podium ending

wait_until(race_finished)
local place = race_place()
wait(4)
if place <= 3 then
  win_stars = 4 - place   -- 1st: three stars
  win()
else
  lose()
end

#A boost for a fast lap

local lap = race_lap()
every(0.5, function()
  if race_lap() > lap then
    lap = race_lap()
    if race_best() > 0 and race_best() < 30 then
      popup("Under 30 seconds! Have a boost.")
      car_boost(1.5)
    end
  end
end)