obstacle support
This commit is contained in:
@@ -83,10 +83,20 @@ func (p *player) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point
|
||||
}
|
||||
}
|
||||
|
||||
// Check Obstacles
|
||||
for _, obj := range g.obstacles {
|
||||
collision, _, pos := v.RectIntersection(obj.Bounds, p.Robot.Position, move_vector)
|
||||
if collision {
|
||||
log.Printf("Object Collision %v hit %v, rect:%v", p.Robot.Position, move_vector, obj.Bounds)
|
||||
return collision, pos, nil
|
||||
}
|
||||
}
|
||||
|
||||
return collision, intersection_point, nil
|
||||
}
|
||||
|
||||
func (p *player) Tick(g *game) {
|
||||
p.Robot.Collision = false
|
||||
p.scan(g.players)
|
||||
|
||||
// Adjust Speed
|
||||
@@ -129,15 +139,16 @@ func (p *player) Tick(g *game) {
|
||||
move_vector := new_heading.Scale(p.Robot.Speed * delta)
|
||||
collision, _, hit_player := p.checkCollisions(g, move_vector)
|
||||
if collision {
|
||||
p.Robot.Collision = true
|
||||
if hit_player != nil {
|
||||
hit_player.Robot.Health -= int(p.Robot.Speed / 10.0)
|
||||
hit_player.Robot.Speed = (hit_player.Robot.Speed * 0.5)
|
||||
hit_player.Robot.Speed = (hit_player.Robot.Speed * 0.1)
|
||||
hit_player.Robot.Heading = p.Robot.Heading
|
||||
}
|
||||
// p.Robot.Position = intersection_point
|
||||
//p.Robot.Position = intersection_point
|
||||
p.Robot.Health -= int(p.Robot.Speed / 10.0)
|
||||
p.Robot.MoveTo = &p.Robot.Position
|
||||
p.Robot.Speed = (p.Robot.Speed * 0.5)
|
||||
p.Robot.Speed = (p.Robot.Speed * 0.1)
|
||||
p.Robot.Heading = p.Robot.Heading.Scale(-1.0)
|
||||
} else {
|
||||
p.Robot.Position = p.Robot.Position.Add(move_vector)
|
||||
@@ -197,12 +208,26 @@ func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *player) reset() {
|
||||
start_pos := v.Point2d{
|
||||
X: rand.Float32() * float32(*width),
|
||||
Y: rand.Float32() * float32(*height),
|
||||
func (p *player) reset(g *game) {
|
||||
for {
|
||||
start_pos := v.Point2d{
|
||||
X: rand.Float32() * float32(*width),
|
||||
Y: rand.Float32() * float32(*height),
|
||||
}
|
||||
p.Robot.MoveTo = &start_pos
|
||||
p.Robot.Position = start_pos
|
||||
p.Robot.Health = p.Robot.Stats.Hp
|
||||
|
||||
// Check Obstacles
|
||||
retry := false
|
||||
for _, obj := range g.obstacles {
|
||||
_, inside, _ := v.RectIntersection(obj.Bounds, p.Robot.Position, v.Vector2d{0, 0})
|
||||
if inside {
|
||||
retry = true
|
||||
}
|
||||
}
|
||||
if !retry {
|
||||
break
|
||||
}
|
||||
}
|
||||
p.Robot.MoveTo = &start_pos
|
||||
p.Robot.Position = start_pos
|
||||
p.Robot.Health = p.Robot.Stats.Hp
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user