Vary team colors.
This commit is contained in:
parent
d4d78078f8
commit
b0f98c233a
38
main.go
38
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -23,13 +24,14 @@ func run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
s := newState()
|
s := newState()
|
||||||
|
colors := teamColors(s.teams)
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
for !w.Closed() && !s.gameOver {
|
for !w.Closed() && !s.gameOver {
|
||||||
w.Clear(colornames.Peru)
|
w.Clear(colornames.Peru)
|
||||||
s = updateState(s)
|
s = updateState(s)
|
||||||
render(s, w, time.Since(start))
|
render(s, w, time.Since(start), colors)
|
||||||
w.Update()
|
w.Update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,26 +40,27 @@ func main() {
|
||||||
pixelgl.Run(run)
|
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()
|
b := w.Bounds()
|
||||||
im := imdraw.New(nil)
|
im := imdraw.New(nil)
|
||||||
hOffset := b.Size().X / steps
|
hOffset := b.Size().X / steps
|
||||||
vOffset := b.Size().Y / (numTeams + 1)
|
vOffset := b.Size().Y / (numTeams + 1)
|
||||||
|
width := 20
|
||||||
|
|
||||||
for i, t := range s.teams {
|
for i, t := range s.teams {
|
||||||
for j, bot := range t.bots {
|
for j, bot := range t.bots {
|
||||||
if &t.bots[j] == t.baton.holder {
|
if &t.bots[j] == t.baton.holder {
|
||||||
im.Color = pixel.RGB(0, 1, 0)
|
im.Color = pixel.RGB(0, 1, 0)
|
||||||
} else {
|
} 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))
|
pos := from.Add(pixel.V(float64(bot.pos)*hOffset, 0))
|
||||||
|
|
||||||
im.Push(pos)
|
im.Push(pos)
|
||||||
|
|
||||||
im.Clear()
|
im.Clear()
|
||||||
im.Circle(50, 0)
|
im.Circle(float64(width), 0)
|
||||||
|
|
||||||
im.Draw(w)
|
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 {
|
type team struct {
|
||||||
bots []bot
|
bots []bot
|
||||||
baton baton
|
baton baton
|
||||||
|
@ -147,7 +169,7 @@ func gameOver(s state) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
steps = 150
|
steps = 250
|
||||||
numBots = 5
|
numBots = 10
|
||||||
numTeams = 2
|
numTeams = 4
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue