
function update(dt)

C = rgbm(1,1,1,1) 
    if car.rpm >= 6000 then
        C = rgbm(1,0.4,0,1)
    end

F = rgbm(1,1,1,1) 
    if car.fuel < 48 then
        F = rgbm(1,0.4,0,1)
    end   

ui.pathLineTo(vec2(212, 600))
ui.pathLineTo(vec2(212, 600 - (1850 * math.saturate(math.min(car.rpm, 800) / 9000))))
if car.rpm > 800 then
ui.pathLineTo(vec2(212 + (1150 * math.saturate((math.min(car.rpm, 2500)-800) / 9000)), 435 - (1000 * math.saturate((math.min(car.rpm, 2500)-800) / 8000))))
end
if car.rpm > 2500 then
ui.pathLineTo(vec2(431 + (1000 * math.saturate((math.min(car.rpm, 9000)-2500) / 9000)), 220))
end
if car.rpm > 3000 then
ui.pathLineTo(vec2(488 + (2000 * math.saturate((math.min(car.rpm, 9000)-3000) / 9000)), 220))
end
ui.pathStroke(rgbm(C), false, 245)

ui.pathLineTo(vec2(212, 654))
ui.pathLineTo(vec2(212, 654 + (600 * math.saturate(math.min(car.fuel, 8) / car.maxFuel)))) 
if car.fuel > 8 then
ui.pathLineTo(vec2(212 + (250 * math.saturate((math.min(car.fuel, 24) -8) / car.maxFuel)), 705 + (200 * math.saturate((math.min(car.fuel, 24) -8) / car.maxFuel))))
end
if car.fuel > 24 then
ui.pathLineTo(vec2(243 + (600 * math.saturate((math.min(car.fuel, 48) -24) / car.maxFuel)), 729 + (600 * math.saturate((math.min(car.fuel, 48) -24) / car.maxFuel))))
end
if car.fuel > 48 then
ui.pathLineTo(vec2(364 + (650 * math.saturate((math.min(car.fuel, 66) -48) / car.maxFuel)), 850 + (650 * math.saturate((math.min(car.fuel, 66) -48) / car.maxFuel))))
end
if car.fuel > 66 then
ui.pathLineTo(vec2(464 + (750 * math.saturate((math.min(car.fuel, 72) -66) / car.maxFuel)), 950 + (0 * math.saturate((math.min(car.fuel, 72) -66) / car.maxFuel))))
end
if car.fuel > 72 then
ui.pathLineTo(vec2(493 + (1130 * math.saturate((math.min(car.fuel, 120) -72) / car.maxFuel)), 950))
end
ui.pathStroke(rgbm(F), false, 170)

local W = rgbm(1,1,1,1)
    if car.oilPressure < 1.5 then
        W = rgbm(1,0.4,0,1)
    end

display.image {
    image = "assets/oil_pressure.dds",
    pos = vec2(700 + car.oilPressure * 74 , 370),
    size = vec2(568, 51),
    color = rgbm(W)
}

display.image {
    image = "assets/display.dds",
    pos = vec2(0, 0),
    size = vec2(2048, 1144)
}

local O = rgbm(1,1,1,1)
    if car.waterTemperature < 68 then
        O = rgbm(0,0,1,1)
    end

display.image {
    image = "assets/water_temp.dds",
    pos = vec2(1279 + ((math.max(car.waterTemperature, 55) -55) * 8), 530),
    size = vec2(50, 50),
    color = rgbm(O)
}

local geartextN = tostring(car.gear)
    if car.gear == 0 then
        geartextN = "N"
    end
    if car.gear == -1 then
        geartextN = "R" 
    end

ui.pushDWriteFont("Orbitron:assets/Orbitron-Bold.ttf")
ui.setCursorX(1040)
ui.setCursorY(700)
ui.dwriteTextAligned(string.format("%0d", car.poweredWheelsSpeed), 350, ui.Alignment.End, ui.Alignment.Center, vec2(860,400), false)
ui.dwriteDrawText(string.format("%2.1f", car.oilPressure), 75, vec2(1710, 270), rgbm(1,1,1,1))
ui.dwriteDrawText(string.format("%4d", car.waterTemperature), 75, vec2(1685, 438), rgbm(1,1,1,1))
ui.beginScale()
ui.dwriteDrawText(geartextN, 250, vec2(710, 430), rgbm(1,1,1,1))
ui.endScale(2)

end