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 {
@ -177,35 +180,55 @@ func NewState() State {
} }
return State{ return State{
Teams: teams, Teams: teams,
Obstacles: []Obstacle{ Obstacles: randomObstacles(),
{ }
Position: Position{ }
Lane: 0,
Pos: Steps / 3, 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),
}, },
{ })
Position: Position{ }
Lane: 1,
Pos: Steps * 2 / 3, return os
}, }
var (
staticObstacles = []Obstacle{
{
Position: Position{
Lane: 0,
Pos: Steps / 3,
}, },
{ },
Position: Position{ {
Lane: 2, Position: Position{
Pos: Steps / 2, Lane: 1,
}, Pos: Steps * 2 / 3,
}, },
{ },
Position: Position{ {
Lane: 3, Position: Position{
Pos: Steps * 3 / 4, Lane: 2,
}, Pos: Steps / 2,
},
},
{
Position: Position{
Lane: 3,
Pos: Steps * 3 / 4,
}, },
}, },
} }
} )
const ( const (
Steps = 40 Steps = 40