package arcade import ( "fmt" "strings" lg "charm.land/lipgloss/v2" "thermal-snake/internal/game" ) const fieldWidth = 2 * game.Width var ( cold = lg.NewStyle().Foreground(lg.Color("#6E405D")).Background(lg.Color("#211322")) warm = lg.NewStyle().Foreground(lg.Color("#97536B")).Background(lg.Color("#30192B")) hotspot = lg.NewStyle().Foreground(lg.Color("#B06978")).Background(lg.Color("#3F2236")) foodStyles = [...]lg.Style{ lg.NewStyle().Bold(true).Foreground(lg.Color("#FFE7A5")).Background(lg.Color("#5F3243")), lg.NewStyle().Bold(true).Foreground(lg.Color("#FFF5C4")).Background(lg.Color("#894B49")), } bodyStyles = [...]lg.Style{ lg.NewStyle().Foreground(lg.Color("#FFAD7C")).Background(lg.Color("#49233A")), lg.NewStyle().Foreground(lg.Color("#FC7986")).Background(lg.Color("#49233A")), lg.NewStyle().Foreground(lg.Color("#D95685")).Background(lg.Color("#49233A")), lg.NewStyle().Foreground(lg.Color("#BB548C")).Background(lg.Color("#49233A")), } headStyle = lg.NewStyle().Bold(true).Foreground(lg.Color("#2C1727")).Background(lg.Color("#FFE7A5")) impactStyle = lg.NewStyle().Bold(true).Foreground(lg.Color("#291423")).Background(lg.Color("#FF836D")) overlayStyle = lg.NewStyle().Bold(true).Foreground(lg.Color("#FFE0A2")).Background(lg.Color("#522E46")) headGlyphs = [...]string{"▴", "▸", "▾", "◂"} ) // The lobby scan loops a single coil around the contours behind the live field. var displayCoil = game.Frame{ Body: []game.Point{ {X: 16, Y: 4}, {X: 15, Y: 4}, {X: 14, Y: 4}, {X: 13, Y: 4}, {X: 12, Y: 4}, {X: 12, Y: 5}, {X: 12, Y: 6}, {X: 12, Y: 7}, {X: 11, Y: 7}, {X: 10, Y: 7}, {X: 9, Y: 7}, {X: 8, Y: 7}, {X: 8, Y: 6}, {X: 8, Y: 5}, {X: 8, Y: 4}, {X: 7, Y: 4}, {X: 6, Y: 4}, {X: 5, Y: 4}, {X: 4, Y: 4}, {X: 4, Y: 5}, {X: 4, Y: 6}, {X: 4, Y: 7}, {X: 4, Y: 8}, {X: 4, Y: 9}, {X: 5, Y: 9}, {X: 6, Y: 9}, {X: 7, Y: 9}, {X: 8, Y: 9}, {X: 9, Y: 9}, {X: 10, Y: 9}, {X: 11, Y: 9}, {X: 12, Y: 9}, {X: 13, Y: 9}, {X: 14, Y: 9}, {X: 15, Y: 9}, {X: 16, Y: 9}, {X: 17, Y: 9}, {X: 17, Y: 8}, {X: 17, Y: 7}, {X: 17, Y: 6}, {X: 16, Y: 6}, {X: 15, Y: 6}, }, Food: game.Point{X: 19, Y: 4}, Direction: game.Right, } func (m *Model) field() []string { frame := displayCoil label := fmt.Sprintf("FIELD / %d × %d", game.Width, game.Height) art := m.screen == lobby if art { label = "CHAMBER SCAN" } else { frame = m.run.Frame() } cells := darkField if art { cells = scanField row := m.phase % game.Height cells[row] = scanLine[row] } if frame.Outcome != game.Clear { cells[frame.Food.Y][frame.Food.X] = foodStyles[m.phase%2].Render("◆ ") } for i, p := range frame.Body { shade := i * len(bodyStyles) / len(frame.Body) glyph := [...]string{"██", "██", "▓▓", "▒▒"}[shade] cells[p.Y][p.X] = bodyStyles[shade].Render(glyph) } head := frame.Body[0] cells[head.Y][head.X] = headStyle.Render(headGlyphs[frame.Direction] + " ") if frame.Outcome == game.Coil { cells[frame.Impact.Y][frame.Impact.X] = impactStyle.Render("××") } switch m.screen { case warmup: box(&cells, 1, fmt.Sprintf("SEEK HEAT IN %02d", m.countdown)) case paused: box(&cells, 5, "PAUSED") } top, bottom := -1, -1 if frame.Outcome == game.Wall { switch frame.Impact.Y { case -1: top = frame.Impact.X case game.Height: bottom = frame.Impact.X } } lines := []string{fieldEdge("╭", "╮", label, top)} for y, row := range cells { left, right := subtle.Render("│"), subtle.Render("│") if frame.Outcome == game.Wall && frame.Impact.Y == y { if frame.Impact.X < 0 { left = impactStyle.Render("×") } else { right = impactStyle.Render("×") } } lines = append(lines, left+strings.Join(row[:], "")+right) } return append(lines, fieldEdge("╰", "╯", "", bottom)) } func fieldEdge(left, right, label string, impact int) string { if impact >= 0 { cells := 2 * impact return subtle.Render(left+strings.Repeat("─", cells)) + impactStyle.Render("××") + subtle.Render(strings.Repeat("─", fieldWidth-cells-2)+right) } if label == "" { return subtle.Render(left + strings.Repeat("─", fieldWidth) + right) } prefix := subtle.Render(left + "─ ") title := " " + label + " " return prefix + accent.Render(title) + subtle.Render(" "+strings.Repeat("─", fieldWidth-3-lg.Width(title))+right) } var ( darkField = terrain(false, false) scanField = terrain(true, false) scanLine = terrain(true, true) ) func terrain(gallery, scanning bool) [game.Height][game.Width]string { var cells [game.Height][game.Width]string for y := range game.Height { for x := range game.Width { style, glyph := cold, " " if x%3 == 0 && y%2 == 0 { glyph = "· " } if gallery { dx, dy := x-10, y-6 radius := dx*dx + 3*dy*dy switch { case radius < 14: style, glyph = hotspot, "░░" case radius < 43: style, glyph = warm, "░░" case radius < 85: style, glyph = warm, "··" } } if scanning { style = style.Background(lg.Color("#4A2B43")) } cells[y][x] = style.Render(glyph) } } return cells } func box(cells *[game.Height][game.Width]string, y int, title string) { const width = 24 left := (fieldWidth - width) / 4 // One box row takes the place of twelve two-column field cells. for i := 0; i < 3; i++ { clear(cells[y+i][left : left+width/2]) } cells[y][left] = overlayStyle.Render("╭" + strings.Repeat("─", width-2) + "╮") cells[y+1][left] = overlayStyle.Render("│" + center(title, width-2) + "│") cells[y+2][left] = overlayStyle.Render("╰" + strings.Repeat("─", width-2) + "╯") }