Vary team colors.

This commit is contained in:
Luke Meyers 2020-02-05 00:22:46 -08:00
parent d4d78078f8
commit b0f98c233a
1 changed files with 30 additions and 8 deletions

38
main.go
View File

@ -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
)