simple lane changes with weird effects
This commit is contained in:
parent
894c487390
commit
81e0dbe8d7
|
@ -73,6 +73,8 @@ func UpdateState(sOld State) State {
|
||||||
switch chooseCommand(t, sOld) {
|
switch chooseCommand(t, sOld) {
|
||||||
case speedUp:
|
case speedUp:
|
||||||
accelerate(t.Baton.Holder)
|
accelerate(t.Baton.Holder)
|
||||||
|
case left:
|
||||||
|
t.Baton.Holder.Lane++
|
||||||
}
|
}
|
||||||
|
|
||||||
moveBot(t.Baton.Holder, sOld)
|
moveBot(t.Baton.Holder, sOld)
|
||||||
|
@ -89,6 +91,10 @@ func UpdateState(sOld State) State {
|
||||||
}
|
}
|
||||||
|
|
||||||
func chooseCommand(t Team, s State) command {
|
func chooseCommand(t Team, s State) command {
|
||||||
|
h := t.Baton.Holder
|
||||||
|
if collide(h.Pos+1, h.Lane, s) {
|
||||||
|
return left
|
||||||
|
}
|
||||||
return speedUp
|
return speedUp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +102,7 @@ type command int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
speedUp command = iota
|
speedUp command = iota
|
||||||
|
left
|
||||||
)
|
)
|
||||||
|
|
||||||
func maybePassBaton(t *Team) {
|
func maybePassBaton(t *Team) {
|
||||||
|
|
|
@ -25,13 +25,13 @@ func accelerate(b *Bot) {
|
||||||
|
|
||||||
func moveBot(b *Bot, s State) {
|
func moveBot(b *Bot, s State) {
|
||||||
for i := 0; i < b.v; i++ {
|
for i := 0; i < b.v; i++ {
|
||||||
if !collide(b.id, b.Pos+1, b.Lane, s) {
|
if !collide(b.Pos+1, b.Lane, s) {
|
||||||
b.Pos++
|
b.Pos++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func collide(id, pos, lane int, s State) bool {
|
func collide(pos, lane int, s State) bool {
|
||||||
for _, o := range s.Obstacles {
|
for _, o := range s.Obstacles {
|
||||||
if o.Pos == pos && o.Lane == lane {
|
if o.Pos == pos && o.Lane == lane {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -29,7 +29,7 @@ func renderBots(s game.State, w *pixelgl.Window, d time.Duration, colors map[*ga
|
||||||
im.Color = colors[&s.Teams[i]]
|
im.Color = colors[&s.Teams[i]]
|
||||||
}
|
}
|
||||||
|
|
||||||
pos := lanePos(bot.Pos, i, botWidth, b)
|
pos := lanePos(bot.Pos, bot.Lane, botWidth, b)
|
||||||
|
|
||||||
im.Push(pos)
|
im.Push(pos)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue