diff --git a/game/game.go b/game/game.go index dcf49db..a380de8 100644 --- a/game/game.go +++ b/game/game.go @@ -23,6 +23,7 @@ func NewState() State { bots = append(bots, b) } teams = append(teams, Team{ + id: i, Bots: bots, Baton: Baton{Holder: &bots[0]}, Lane: i, @@ -40,11 +41,20 @@ func NewState() State { Lane: 1, Pos: Steps * 2 / 3, }, + { + Lane: 2, + Pos: Steps / 2, + }, + { + Lane: 3, + Pos: Steps * 3 / 4, + }, }, } } type Team struct { + id int Bots []Bot Baton Baton won bool @@ -93,7 +103,7 @@ func maybePassBaton(t *Team) { continue } if abs(b.Pos-h.Pos) <= passDistance { - log.Printf("pass from %v to %v!", h.id, b.id) + log.Printf("team %v pass from %v to %v!", t.id, h.id, b.id) t.Baton.Holder.v = 0 t.Baton.Holder.a = 0 t.Baton.Holder = &t.Bots[i] @@ -119,8 +129,8 @@ func gameOver(s State) bool { const ( Steps = 50 numBots = 5 - NumTeams = 2 - NumLanes = 4 + NumTeams = 4 + NumLanes = 6 maxA = 3 maxV = 10 ) diff --git a/gfx/gfx.go b/gfx/gfx.go index 9674dca..c8caf2e 100644 --- a/gfx/gfx.go +++ b/gfx/gfx.go @@ -11,10 +11,24 @@ import ( "golang.org/x/image/colornames" ) -func Render(s game.State, w *pixelgl.Window, d time.Duration) { +type RenderState struct { + Animating bool + Frames int + frame int +} + +func Render(rs RenderState, s game.State, w *pixelgl.Window, d time.Duration) RenderState { + //tween := float64(rs.frame) / float64(rs.Frames) + colors := teamColors(s.Teams) renderBots(s, w, d, colors) renderObstacles(s, w) + + rs.frame++ + if rs.frame >= rs.Frames { + rs.Animating = false + } + return rs } func renderBots(s game.State, w *pixelgl.Window, d time.Duration, colors map[*game.Team]pixel.RGBA) { @@ -65,7 +79,7 @@ func renderObstacles(s game.State, w *pixelgl.Window) { im := imdraw.New(nil) for _, o := range s.Obstacles { - im.Color = pixel.RGB(1, 0, 1) + im.Color = pixel.RGB(0.1, 0.1, 0.2) pos := lanePos(o.Pos, o.Lane, botWidth, b) diff --git a/main.go b/main.go index c94a988..a0ac06f 100644 --- a/main.go +++ b/main.go @@ -31,13 +31,22 @@ func run() { for !w.Closed() && !s.GameOver { w.Clear(colornames.Peru) + + //sOld := s + switch { case w.JustPressed(pixelgl.KeyQ): return case w.JustPressed(pixelgl.KeySpace): s = game.UpdateState(s) } - gfx.Render(s, w, time.Since(start)) + rs := gfx.RenderState{ + Animating: true, + Frames: 10, + } + for rs.Animating { + rs = gfx.Render(rs, s, w, time.Since(start)) + } w.Update() } }