local function drawTextTopSpeed()
    display.text({
        text = "TOP",
        pos = vec2(145, 60),
        letter = vec2(32,57),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -5,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "SPEED",
        pos = vec2(235, 60),
        letter = vec2(32,57),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -5,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "BIA",
        pos = vec2(435, 60),
        letter = vec2(32,57),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -10,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "S",
        pos = vec2(479, 60),
        letter = vec2(32,57),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -12,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "l    l",
        pos = vec2(395, 20),
        letter = vec2(30,957),
        font = 'fonts/f312',
        alignment = 1,
        width = 100,
        spacing = -1,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "AUTO",
        pos = vec2(790, 60),
        letter = vec2(32,57),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -5,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "FASTEST",
        pos = vec2(575, 100),
        letter = vec2(32,57),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -7,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "LAP",
        pos = vec2(145, 290),
        letter = vec2(32,57),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -7,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "_                      _",
        pos = vec2(410, 191),
        letter = vec2(13,47),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -7,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
	display.text({
        text = "_                      _",
        pos = vec2(410, 27),
        letter = vec2(13,47),
        font = 'fonts/german_led',
        alignment = 1,
        width = 60,
        spacing = -7,
	color =  rgbm(19/255, 47/255, 60/255, 1), 
    })
end

local function drawLapCount()
    display.text({
        text = string.format(car.lapCount),
        pos = vec2(205, 327),
        letter = vec2(64,160),
        font = 'fonts/digital_hks',
        alignment = 1,
        width = 50,
        spacing = -2,
	color =  rgbm(19/255, 47/255, 60/255, 1),
    })
end

local maxSpeed = 0
local function drawMaxSpeed()

	local currentSpeed = car.speedKmh 
        if currentSpeed > maxSpeed then
            maxSpeed = currentSpeed
        end
		display.text({text =string.format("%03d", math.floor(maxSpeed)), 
	pos = vec2(190, 110),
        letter = vec2(64,160),
        font = 'fonts/digital_hks',
        alignment = 1,
        width = 10,
        spacing = -2,
	color =  rgbm(19/255, 47/255, 60/255, 1),
	})
end

local function drawCurrentLap()
	local currentLapTime = car.lapTimeMs
	local lap = ac.lapTimeToString(currentLapTime)
		display.text({
			text = lap, 
			pos = vec2(325, 270),
       			letter = vec2(85,250),
        		font = 'fonts/digital_hks',
        		alignment = 1,
        		width = 1,
        		spacing = -15,
			color =  rgbm(19/255, 47/255, 60/255, 1),
		})
end

local function drawFastestLap()
	local currentLapTime = car.bestLapTimeMs
	local lap = ac.lapTimeToString(currentLapTime)
		display.text({
			text = lap, 
			pos = vec2(590, 145),
        		letter = vec2(40,120),
        		font = 'fonts/digital_hks',
        		alignment = 1,
        		width = 1,
        		spacing = -2,
			color =  rgbm(19/255, 47/255, 60/255, 1),
		})
end

local function drawBrakeBias()
	local brakeBias = car.brakeBias*100
	display.text({
			text = string.format("%02d", math.floor(brakeBias)), 
			pos = vec2(440, 115),
        		letter = vec2(45,120),
        		font = 'fonts/digital_hks',
        		alignment = 1,
        		width = 10,
        		spacing = -2,
			color =  rgbm(19/255, 47/255, 60/255, 1),
		})
end


function script.update(dt)
	drawTextTopSpeed()
	drawLapCount()
	drawMaxSpeed()
	drawCurrentLap()
	drawFastestLap()
	drawBrakeBias()
end