local function drawMain()

        local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
        if car.gear == -1 then
            gearText = "R"
        end
        if car.gear == 0 then
            gearText = "N"
        end
        
        display.text {
            text = gearText,
            pos = vec2(105, 300),
            letter = vec2(50, 130),
            font = "german_led",
            width = 0,
            alignment = 0,
            spacing = 0
        }    
    
        local temperature = ac.getSimState().ambientTemperature
	
            display.text{
                text = math.floor(temperature),
                pos = vec2(180, 52),
                letter = vec2(20, 50),
                font = "b",
                width = -1,
                spacing = -8,
                color = rgbm(5,5,5,1)  
                
            }  
            
            display.text{
                text = string.format("%06.0f", car.distanceDrivenTotalKm),
                clampMax = 999999,
                pos = vec2(77, 454),
                letter = vec2(22, 45),
                font = "b",
                color = rgbm(5,5,5,1), 
                width = 200,
                spacing = -6,
                alignment = 0
            }

            local value = math.saturate (car.fuel / 210)
	        display.rect {  
                pos = vec2(206, 428),
                size = vec2(21 , 510 * - value),
		        color = rgbm.from0255(150,150,190,1)
	        }
            
            local value = math.saturate (car.waterTemperature)
            display.rect {  
                pos = vec2(26, 428),
                size = vec2(21 , 80 * - value),
		        color = rgbm.from0255(150,150,190,1)
            }

end

local function drawTrip()
    local integerNumber, floatNumber = math.modf(car.distanceDrivenSessionKm)
        display.text({
            text = math.min(999,string.format("%03d",integerNumber)),
            pos = vec2(-30, 190),
            letter = vec2(22, 45),
            font = 'b',
            color = rgbm(5,5,5,1),
            alignment = 1,
            width = 200,
            spacing = -4
        })            
end

function script.update(dt)
        drawTrip()
        drawMain()
end


