package main import "github.com/veandco/go-sdl2/sdl" var letterOffsets = []int32{ 2, 10, 18, } var letterColors []uint32 // Map function to convert value from range [0, 6] to range [0, 88] func mapRange(x, minX, maxX, minY, maxY uint32) int32 { // Perform conversion to float64 to ensure proper division return int32((float64(x-minX)/float64(maxX-minX))*float64(maxY-minY) + float64(minY)) } var rects = [][]sdl.Rect{ // Define the rects with modified Y-values { {X: 5, Y: 0, W: 6, H: 1}, {X: 5, Y: 0, W: 1, H: 5}, {X: 5, Y: 2, W: 6, H: 1}, {X: 5, Y: 4, W: 6, H: 1}, }, { {X: 6, Y: 0, W: 4, H: 1}, // Top bar of "A" {X: 5, Y: 1, W: 1, H: 4}, // Left vertical line of "A" {X: 10, Y: 1, W: 1, H: 4}, // Right vertical line of "A" {X: 6, Y: 3, W: 4, H: 1}, // Middle bar of "A" }, { {X: 5, Y: 0, W: 6, H: 1}, {X: 5, Y: 0, W: 1, H: 3}, {X: 5, Y: 2, W: 6, H: 1}, {X: 10, Y: 2, W: 1, H: 3}, {X: 5, Y: 4, W: 6, H: 1}, }, } func initHud(surface *sdl.Surface) { letterColors = []uint32{ sdl.MapRGBA(surface.Format, 243, 235, 28, 255), sdl.MapRGBA(surface.Format, 255, 80, 40, 255), sdl.MapRGBA(surface.Format, 40, 243, 243, 255), } HUDColor := sdl.MapRGBA(surface.Format, 101, 101, 101, 255) surface.FillRect(nil, HUDColor) for letterIndex, letter := range rects { for _, letterRect := range letter { offsetRect := letterRect offsetRect.Y += letterOffsets[letterIndex] surface.FillRect(&offsetRect, letterColors[letterIndex]) } } } func renderHud(player *Player, surface *sdl.Surface) { for _, letterOffset := range letterOffsets { surface.FillRect(&sdl.Rect{X: 16, Y: letterOffset - 1, W: 90, H: 7}, 0) } HUDValues := []int32{ mapRange(player.energy, 0, serverConfig.MaxEnergy, 0, 88), mapRange(player.ammunition, 0, serverConfig.MaxAmmunition, 0, 88), mapRange(player.shields, 0, serverConfig.MaxShields, 0, 88), } for HUDValueIndex, HUDValue := range HUDValues { surface.FillRect( &sdl.Rect{ X: 17, Y: letterOffsets[HUDValueIndex], W: HUDValue, H: 5}, letterColors[HUDValueIndex]) } }