throw batons with animation
This commit is contained in:
parent
73bceedf56
commit
9c5fc0b08f
|
@ -13,7 +13,7 @@ func doCommand(cmd command, s State, teamID int) State {
|
||||||
da := 1
|
da := 1
|
||||||
//da += rand.Intn(3) - 1
|
//da += rand.Intn(3) - 1
|
||||||
|
|
||||||
b := activeBot(s.Teams[teamID])
|
b := ActiveBot(s.Teams[teamID])
|
||||||
if b == nil {
|
if b == nil {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@ import "log"
|
||||||
func UpdateState(s State, sOld State) State {
|
func UpdateState(s State, sOld State) State {
|
||||||
for i := range s.Teams {
|
for i := range s.Teams {
|
||||||
s = doCommand(chooseCommand(s, i), s, i)
|
s = doCommand(chooseCommand(s, i), s, i)
|
||||||
if b := activeBot(s.Teams[i]); b != nil {
|
if b := ActiveBot(s.Teams[i]); b != nil {
|
||||||
s = moveBot(s, i, *b)
|
s = moveBot(s, i, *b)
|
||||||
}
|
}
|
||||||
s = maybePassBaton(s, i)
|
s = maybePassBaton(s, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range s.Teams {
|
for _, t := range s.Teams {
|
||||||
if b := activeBot(t); b != nil && won(*b, s) {
|
if b := ActiveBot(t); b != nil && won(*b, s) {
|
||||||
log.Printf("team %d won", t.id)
|
log.Printf("team %d won", t.id)
|
||||||
s.GameOver = true
|
s.GameOver = true
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func UpdateState(s State, sOld State) State {
|
||||||
|
|
||||||
func maybePassBaton(s State, teamID int) State {
|
func maybePassBaton(s State, teamID int) State {
|
||||||
t := s.Teams[teamID]
|
t := s.Teams[teamID]
|
||||||
h := activeBot(t)
|
h := ActiveBot(t)
|
||||||
if h == nil {
|
if h == nil {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ func maybePassBaton(s State, teamID int) State {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func activeBot(t Team) *Bot {
|
func ActiveBot(t Team) *Bot {
|
||||||
for _, b := range t.Bots {
|
for _, b := range t.Bots {
|
||||||
if b.ID == t.Baton.HolderID {
|
if b.ID == t.Baton.HolderID {
|
||||||
return &b
|
return &b
|
||||||
|
|
|
@ -52,6 +52,6 @@ func collide(pos, lane int, s State) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
passDistance = 1
|
passDistance = 3
|
||||||
baseAccel = 1
|
baseAccel = 1
|
||||||
)
|
)
|
||||||
|
|
19
gfx/gfx.go
19
gfx/gfx.go
|
@ -17,7 +17,7 @@ type RenderState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window) RenderState {
|
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window) RenderState {
|
||||||
w.Clear(colornames.Peru)
|
w.Clear(colornames.Olivedrab)
|
||||||
|
|
||||||
tween := float64(rs.Frame) / float64(rs.Frames)
|
tween := float64(rs.Frame) / float64(rs.Frames)
|
||||||
|
|
||||||
|
@ -51,15 +51,20 @@ func renderBots(sOld, sNew game.State, tween float64, w *pixelgl.Window, colors
|
||||||
}
|
}
|
||||||
|
|
||||||
im.Push(pos)
|
im.Push(pos)
|
||||||
|
|
||||||
im.Clear()
|
im.Clear()
|
||||||
im.Circle(botWidth, 0)
|
im.Circle(botWidth, 0)
|
||||||
|
|
||||||
im.Draw(w)
|
im.Draw(w)
|
||||||
if t.Bots[j].ID == t.Baton.HolderID {
|
|
||||||
renderBaton(pos, w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldHolder, newHolder := game.ActiveBot(sOld.Teams[i]), game.ActiveBot(sNew.Teams[i])
|
||||||
|
oldPos := lanePos(oldHolder.Pos, oldHolder.Lane, botWidth, bounds)
|
||||||
|
newPos := lanePos(newHolder.Pos, newHolder.Lane, botWidth, bounds)
|
||||||
|
|
||||||
|
pos := pixel.Vec{
|
||||||
|
X: oldPos.X + tween*(newPos.X-oldPos.X),
|
||||||
|
Y: oldPos.Y + tween*(newPos.Y-oldPos.Y),
|
||||||
|
}
|
||||||
|
renderBaton(pos, w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +115,7 @@ func teamColors(ts []game.Team) map[*game.Team]pixel.RGBA {
|
||||||
case 2:
|
case 2:
|
||||||
c = colornames.Lavender
|
c = colornames.Lavender
|
||||||
case 3:
|
case 3:
|
||||||
c = colornames.Maroon
|
c = colornames.Rosybrown
|
||||||
}
|
}
|
||||||
m[&ts[i]] = pixel.ToRGBA(c)
|
m[&ts[i]] = pixel.ToRGBA(c)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue