From b0f98c233af54494f5df565a3d700d040f46517e Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Wed, 5 Feb 2020 00:22:46 -0800 Subject: [PATCH] Vary team colors. --- main.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 35d6577..dc3311f 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "image/color" "log" "time" @@ -23,13 +24,14 @@ func run() { } s := newState() + colors := teamColors(s.teams) start := time.Now() for !w.Closed() && !s.gameOver { w.Clear(colornames.Peru) s = updateState(s) - render(s, w, time.Since(start)) + render(s, w, time.Since(start), colors) w.Update() } } @@ -38,26 +40,27 @@ func main() { pixelgl.Run(run) } -func render(s state, w *pixelgl.Window, d time.Duration) { +func render(s state, w *pixelgl.Window, d time.Duration, colors map[*team]pixel.RGBA) { b := w.Bounds() im := imdraw.New(nil) hOffset := b.Size().X / steps vOffset := b.Size().Y / (numTeams + 1) + width := 20 for i, t := range s.teams { for j, bot := range t.bots { if &t.bots[j] == t.baton.holder { im.Color = pixel.RGB(0, 1, 0) } else { - im.Color = pixel.RGB(1, 0, 0) + im.Color = colors[&s.teams[i]] } - from := pixel.V(b.Min.X+25, b.Min.Y+float64(i+1)*vOffset) + from := pixel.V(b.Min.X+float64(width)/2, b.Min.Y+float64(i+1)*vOffset) pos := from.Add(pixel.V(float64(bot.pos)*hOffset, 0)) im.Push(pos) im.Clear() - im.Circle(50, 0) + im.Circle(float64(width), 0) im.Draw(w) } @@ -87,6 +90,25 @@ func newState() state { } } +func teamColors(ts []team) map[*team]pixel.RGBA { + m := make(map[*team]pixel.RGBA) + for i := range ts { + var c color.RGBA + switch i { + case 0: + c = colornames.Cyan + case 1: + c = colornames.Gold + case 2: + c = colornames.Lavender + case 3: + c = colornames.Indigo + } + m[&ts[i]] = pixel.ToRGBA(c) + } + return m +} + type team struct { bots []bot baton baton @@ -147,7 +169,7 @@ func gameOver(s state) bool { } const ( - steps = 150 - numBots = 5 - numTeams = 2 + steps = 250 + numBots = 10 + numTeams = 4 )