|
|
@ -94,43 +94,49 @@ func (p *player) nudge(g *game) { |
|
|
|
if current_heading.Mag() == 0 { |
|
|
|
// We may have been stopped before this and had no heading
|
|
|
|
current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize() |
|
|
|
log.Printf("Heading WAS zero, is now %v", current_heading) |
|
|
|
} |
|
|
|
|
|
|
|
// Where do we WANT to be heading?
|
|
|
|
new_heading := p.Robot.MoveTo.Sub(p.Robot.Position).Normalize() |
|
|
|
|
|
|
|
// Is our direction change too much? Hard coding to 5 degrees/s for now
|
|
|
|
angle := v.Angle(current_heading, new_heading) * v.Rad2deg |
|
|
|
dir := 1.0 |
|
|
|
if angle < 0 { |
|
|
|
dir = -1.0 |
|
|
|
} |
|
|
|
if new_heading.Mag() > 0 { |
|
|
|
// Is our direction change too much? Hard coding to 5 degrees/s for now
|
|
|
|
angle := v.Angle(current_heading, new_heading) * v.Rad2deg |
|
|
|
|
|
|
|
// Max turn radius in this case is 100 degrees per second
|
|
|
|
if math.Abs(angle) > (100 * delta) { |
|
|
|
// New heading should be a little less, take current heading and
|
|
|
|
// rotate by the max turn radius per frame.
|
|
|
|
rot := (100 * delta) * v.Deg2rad |
|
|
|
dir := 1.0 |
|
|
|
if angle < 0 { |
|
|
|
dir = -1.0 |
|
|
|
} |
|
|
|
|
|
|
|
new_heading = current_heading.Rotate(rot * dir) |
|
|
|
} |
|
|
|
// Max turn radius in this case is in degrees per second
|
|
|
|
if math.Abs(angle) > (float64(p.Robot.Stats.TurnSpeed) * delta) { |
|
|
|
// New heading should be a little less, take current heading and
|
|
|
|
// rotate by the max turn radius per frame.
|
|
|
|
rot := (float64(p.Robot.Stats.TurnSpeed) * delta) * v.Deg2rad |
|
|
|
|
|
|
|
move_vector := new_heading.Scale(p.Robot.Speed * delta) |
|
|
|
collision, _ := p.checkCollisions(g, move_vector) |
|
|
|
if collision { |
|
|
|
// p.Robot.Position = intersection_point
|
|
|
|
p.Robot.Speed = 0 |
|
|
|
p.Robot.MoveTo = &p.Robot.Position |
|
|
|
p.Robot.Health -= 5 |
|
|
|
p.Robot.Heading = v.Vector2d{X: 0, Y: 0} |
|
|
|
} else { |
|
|
|
p.Robot.Position = p.Robot.Position.Add(move_vector) |
|
|
|
if new_heading.Mag() > 0 { |
|
|
|
p.Robot.Heading = new_heading |
|
|
|
new_heading = current_heading.Rotate(rot * dir) |
|
|
|
} |
|
|
|
|
|
|
|
move_vector := new_heading.Scale(p.Robot.Speed * delta) |
|
|
|
collision, _ := p.checkCollisions(g, move_vector) |
|
|
|
if collision { |
|
|
|
// p.Robot.Position = intersection_point
|
|
|
|
p.Robot.Health -= int(p.Robot.Speed / 10.0) |
|
|
|
p.Robot.MoveTo = &p.Robot.Position |
|
|
|
p.Robot.Speed = 0 |
|
|
|
p.Robot.Heading = v.Vector2d{X: 0, Y: 0} |
|
|
|
} else { |
|
|
|
log.Printf("Zero Heading %v", new_heading) |
|
|
|
p.Robot.Position = p.Robot.Position.Add(move_vector) |
|
|
|
if new_heading.Mag() > 0 { |
|
|
|
p.Robot.Heading = new_heading |
|
|
|
// log.Printf("%v %v %v", new_heading, current_heading, angle)
|
|
|
|
} else { |
|
|
|
log.Printf("Zero Heading %v", new_heading) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func (p *player) scan(players map[*player]bool) { |
|
|
@ -152,22 +158,22 @@ func (p *player) scan(players map[*player]bool) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (p *player) fire(projectiles map[*Projectile]bool) *Projectile { |
|
|
|
// XXX: is this to prevent us from having multiple projectiles from the
|
|
|
|
// same bot?
|
|
|
|
for proj := range projectiles { |
|
|
|
if proj.Id == p.Robot.Id { |
|
|
|
return nil |
|
|
|
} |
|
|
|
func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile { |
|
|
|
// Throttle the fire rate
|
|
|
|
time_since_fired := (float64(turn) * (delta * 1000)) - (float64(p.Robot.LastFired) * (delta * 1000)) |
|
|
|
if time_since_fired < float64(p.Robot.Stats.FireRate) { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
p.Robot.LastFired = turn |
|
|
|
|
|
|
|
return &Projectile{ |
|
|
|
Id: p.Robot.Id, |
|
|
|
Position: p.Robot.Position, |
|
|
|
MoveTo: *p.Robot.FireAt, |
|
|
|
Damage: 10, |
|
|
|
Radius: p.Robot.Stats.WeaponRadius, |
|
|
|
Speed: float64(p.Robot.Stats.Speed * 2), |
|
|
|
Speed: float64(p.Robot.Stats.Speed * 3), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|