random obstacles as a service
This commit is contained in:
parent
791fffdebb
commit
5b45dad1bb
31
game/game.go
31
game/game.go
|
@ -1,6 +1,9 @@
|
|||
package game
|
||||
|
||||
import "log"
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
func UpdateState(s State, sOld State) State {
|
||||
for i := range s.Teams {
|
||||
|
@ -178,7 +181,28 @@ func NewState() State {
|
|||
|
||||
return State{
|
||||
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{
|
||||
Lane: 0,
|
||||
|
@ -203,9 +227,8 @@ func NewState() State {
|
|||
Pos: Steps * 3 / 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
Steps = 40
|
||||
|
|
Loading…
Reference in New Issue