### Remove special case wall collisions, replace with generated objects

master
parent 78b1711cd9
commit ef33a17b6a
2 changed files with 27 additions and 31 deletions

#### 35 obstacle.go Unescape Escape View File

 `@ -49,24 +49,41 @@ func (o Obstacle) distance_from_point(p v.Point2d) float64 {` ` return dist` `}` ``` ``` `func obstacleFromValues(x, y, w, h float64, hp int) (o Obstacle) {` ` return Obstacle{` ` Bounds: v.AABB2d{` ` A: v.Point2d{X: x, Y: y},` ` B: v.Point2d{X: x + w, Y: y + h},` ` },` ` Hp: hp,` ` }` `}` ``` ``` ```// GenerateObstacles returns a slice of (count) obstacles within a region ``` ```// bounded by width, height. ``` `func GenerateObstacles(count int, width, height float64) []Obstacle {` ` out := []Obstacle{}` ``` ``` ``` // Create obstacles that cover the edges of the world, so we don't need to ``` ``` // special case collision at the edges ``` ``` // left wall ``` ` out = append(out, obstacleFromValues(0, 5, 5, height-10, 0))` ``` // // right wall ``` ` out = append(out, obstacleFromValues(width-5, 5, 5, height-10, 0))` ``` // // top wall ``` ` out = append(out, obstacleFromValues(0, height-5, width, 5, 0))` ``` // bottom wall ``` ` out = append(out, obstacleFromValues(0, 0, width, 5, 0))` ``` ``` ``` // Now create N random objects somewhere in the world ``` ` for i := 0; i < count; i++ {` ` x := rand.Float64() * (width - (width / 10))` ` y := rand.Float64() * (height - (height / 10))` ` w := rand.Float64() * (width / 10)` ` h := rand.Float64() * (height / 10)` ` w := rand.Float64()*(width/10) + 20` ` h := rand.Float64()*(height/10) + 20` ` out = append(` ` out,` ` Obstacle{` ` Bounds: v.AABB2d{` ` A: v.Point2d{X: x, Y: y},` ` B: v.Point2d{X: 20 + x + w, Y: 20 + y + h},` ` },` ` Hp: 10000,` ` })` ` obstacleFromValues(x, y, w, h, 10000))` ` }` ` return out` `}`

#### 23 robot.go Unescape Escape View File

 `@ -195,29 +195,8 @@ func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *R` ` botSize := 5.0` ` botPolygon := v.OrientedSquare(r.Position, r.Heading, botSize)` ``` ``` ` bounds := []Obstacle{` ` Obstacle{` ` Bounds: v.AABB2d{A: v.Point2d{0, 0}, B: v.Point2d{0, g.width}},` ` Hp: 0,` ` },` ` Obstacle{` ` Bounds: v.AABB2d{A: v.Point2d{0, 0}, B: v.Point2d{0, g.height}},` ` Hp: 0,` ` },` ` Obstacle{` ` Bounds: v.AABB2d{A: v.Point2d{g.width, g.height}, B: v.Point2d{0, g.height}},` ` Hp: 0,` ` },` ` Obstacle{` ` Bounds: v.AABB2d{A: v.Point2d{g.width, g.height}, B: v.Point2d{g.width, 0}},` ` Hp: 0,` ` },` ` }` ``` ``` ` obstacles := append(g.obstacles, bounds...)` ``` ``` ``` // Check Obstacles ``` ` for _, obj := range obstacles {` ` for _, obj := range g.obstacles {` ``` // collision due to motion: ``` ` collision, move_collision, translation := v.PolyPolyIntersection(` ` botPolygon, probe, obj.Bounds.ToPolygon())`