30 lines
596 B
Go
30 lines
596 B
Go
package main
|
|
|
|
import (
|
|
v "bitbucket.org/hackerbots/vector"
|
|
"math/rand"
|
|
)
|
|
|
|
type Obstacle struct {
|
|
Bounds v.Rect2d `json:"bounds"`
|
|
}
|
|
|
|
func GenerateObstacles(count int, width, height float32) []Obstacle {
|
|
out := []Obstacle{}
|
|
for i := 0; i < count; i++ {
|
|
x := rand.Float32() * (width - (width / 10))
|
|
y := rand.Float32() * (height - (height / 10))
|
|
w := rand.Float32() * (width / 10)
|
|
h := rand.Float32() * (height / 10)
|
|
out = append(
|
|
out,
|
|
Obstacle{
|
|
Bounds: v.Rect2d{
|
|
A: v.Point2d{X: x, Y: y},
|
|
B: v.Point2d{X: 20 + x + w, Y: 20 + y + h},
|
|
},
|
|
})
|
|
}
|
|
return out
|
|
}
|