random obstacles as a service

This commit is contained in:
Luke Meyers 2020-02-07 20:24:13 -08:00
parent 791fffdebb
commit 5b45dad1bb
1 changed files with 47 additions and 24 deletions

View File

@ -1,6 +1,9 @@
package game package game
import "log" import (
"log"
"math/rand"
)
func UpdateState(s State, sOld State) State { func UpdateState(s State, sOld State) State {
for i := range s.Teams { for i := range s.Teams {
@ -178,7 +181,28 @@ func NewState() State {
return State{ return State{
Teams: teams, Teams: teams,
Obstacles: []Obstacle{ Obstacles: randomObstacles(),
}
}
func randomObstacles() []Obstacle {
var os []Obstacle
const numObstacles = 4 * NumTeams
for i := 0; i < numObstacles; i++ {
os = append(os, Obstacle{
Position: Position{
Pos: rand.Intn(Steps-8) + 4,
Lane: rand.Intn(NumLanes),
},
})
}
return os
}
var (
staticObstacles = []Obstacle{
{ {
Position: Position{ Position: Position{
Lane: 0, Lane: 0,
@ -203,9 +227,8 @@ func NewState() State {
Pos: Steps * 3 / 4, Pos: Steps * 3 / 4,
}, },
}, },
},
} }
} )
const ( const (
Steps = 40 Steps = 40