loop forever
This commit is contained in:
parent
316adfedf9
commit
114ef447b2
|
@ -1,7 +1,5 @@
|
||||||
package game
|
package game
|
||||||
|
|
||||||
import "log"
|
|
||||||
|
|
||||||
func chooseCommand(s State, teamID int) command {
|
func chooseCommand(s State, teamID int) command {
|
||||||
t := s.Teams[teamID]
|
t := s.Teams[teamID]
|
||||||
h := t.BatonHolder()
|
h := t.BatonHolder()
|
||||||
|
@ -23,7 +21,6 @@ func chooseCommand(s State, teamID int) command {
|
||||||
if nextBot != nil {
|
if nextBot != nil {
|
||||||
if h.Lane != nextBot.Lane {
|
if h.Lane != nextBot.Lane {
|
||||||
if abs(nextBot.Pos-h.Pos) < h.v {
|
if abs(nextBot.Pos-h.Pos) < h.v {
|
||||||
log.Println("WHOOOOOOA")
|
|
||||||
return slowDown
|
return slowDown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
gfx/gfx.go
13
gfx/gfx.go
|
@ -2,7 +2,6 @@ package gfx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"log"
|
|
||||||
"relay/game"
|
"relay/game"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -19,8 +18,6 @@ type RenderState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, d time.Duration) RenderState {
|
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, d time.Duration) RenderState {
|
||||||
// log.Printf("ENTER render sOld: %+v", sOld)
|
|
||||||
// log.Printf("ENTER render sNew: %+v", sNew)
|
|
||||||
w.Clear(colornames.Peru)
|
w.Clear(colornames.Peru)
|
||||||
|
|
||||||
tween := float64(rs.Frame) / float64(rs.Frames)
|
tween := float64(rs.Frame) / float64(rs.Frames)
|
||||||
|
@ -36,12 +33,10 @@ func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, d time.Dur
|
||||||
return rs
|
return rs
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, d time.Duration, colors map[*game.Team]pixel.RGBA) {
|
func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, _ time.Duration, colors map[*game.Team]pixel.RGBA) {
|
||||||
bounds := w.Bounds()
|
bounds := w.Bounds()
|
||||||
im := imdraw.New(nil)
|
im := imdraw.New(nil)
|
||||||
|
|
||||||
//log.Println("sOld.Teams:", sOld.Teams)
|
|
||||||
|
|
||||||
for i, t := range sNew.Teams {
|
for i, t := range sNew.Teams {
|
||||||
for j, bot := range t.Bots {
|
for j, bot := range t.Bots {
|
||||||
c := colors[&sNew.Teams[i]]
|
c := colors[&sNew.Teams[i]]
|
||||||
|
@ -50,14 +45,9 @@ func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, d time.
|
||||||
im.Color = c
|
im.Color = c
|
||||||
|
|
||||||
oldBot := sOld.Teams[i].Bots[j]
|
oldBot := sOld.Teams[i].Bots[j]
|
||||||
//log.Printf("oldBot: %+v", oldBot)
|
|
||||||
//log.Printf("newBot: %+v", bot)
|
|
||||||
oldPos := lanePos(oldBot.Pos, oldBot.Lane, botWidth, bounds)
|
oldPos := lanePos(oldBot.Pos, oldBot.Lane, botWidth, bounds)
|
||||||
newPos := lanePos(bot.Pos, bot.Lane, botWidth, bounds)
|
newPos := lanePos(bot.Pos, bot.Lane, botWidth, bounds)
|
||||||
|
|
||||||
log.Println("oldPos:", oldPos)
|
|
||||||
log.Println("newPos:", newPos)
|
|
||||||
|
|
||||||
pos := pixel.Vec{
|
pos := pixel.Vec{
|
||||||
X: oldPos.X + tween*(newPos.X-oldPos.X),
|
X: oldPos.X + tween*(newPos.X-oldPos.X),
|
||||||
Y: oldPos.Y + tween*(newPos.Y-oldPos.Y),
|
Y: oldPos.Y + tween*(newPos.Y-oldPos.Y),
|
||||||
|
@ -72,7 +62,6 @@ func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, d time.
|
||||||
if t.Bots[j].ID == t.Baton.HolderID {
|
if t.Bots[j].ID == t.Baton.HolderID {
|
||||||
renderBaton(pos, w)
|
renderBaton(pos, w)
|
||||||
}
|
}
|
||||||
//log.Println("sOld.Teams[i].Bots[j]:", sOld.Teams[i].Bots[j])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
main.go
8
main.go
|
@ -39,11 +39,15 @@ func run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case w.JustPressed(pixelgl.KeyQ):
|
case w.Pressed(pixelgl.KeyQ):
|
||||||
return
|
return
|
||||||
case w.JustPressed(pixelgl.KeySpace):
|
case w.JustPressed(pixelgl.KeySpace) || true:
|
||||||
rs.Animating = true
|
rs.Animating = true
|
||||||
s = game.UpdateState(s, sOld)
|
s = game.UpdateState(s, sOld)
|
||||||
|
if s.GameOver {
|
||||||
|
s = game.NewState()
|
||||||
|
sOld = s
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for rs.Animating {
|
for rs.Animating {
|
||||||
rs = gfx.Render(rs, sOld, s, w, time.Since(start))
|
rs = gfx.Render(rs, sOld, s, w, time.Since(start))
|
||||||
|
|
Loading…
Reference in New Issue