support setting heading in instructions

This commit is contained in:
Fraser Graham 2013-11-11 21:36:11 -08:00
parent 3f40fe4603
commit c7d5e4be87
3 changed files with 39 additions and 27 deletions

View File

@ -69,6 +69,9 @@ func (p *player) recv() {
if msg.MoveTo != nil {
r.MoveTo = msg.MoveTo
}
if msg.Heading != nil {
r.DesiredHeading = msg.Heading
}
if msg.FireAt != nil {
r.FireAt = msg.FireAt
}

View File

@ -1,6 +1,7 @@
package main
import (
v "bitbucket.org/hackerbots/vector"
"code.google.com/p/go.net/websocket"
"log"
)
@ -203,6 +204,7 @@ func addPlayer(ws *websocket.Conn) {
Id: idg.Hash(),
Name: name,
Health: 10,
Heading: v.Vector2d{1, 0},
Scanners: make([]Scanner, 0)}
r.Health = r.Stats.Hp
log.Printf("Adding Robot: %v", r)

View File

@ -20,6 +20,7 @@ type Robot struct {
ActiveScan bool `json:"-"`
Position v.Point2d `json:"position"`
Heading v.Vector2d `json:"heading"`
DesiredHeading *v.Vector2d `json:"-"`
MoveTo *v.Point2d `json:"-"`
FireAt *v.Point2d `json:"-"`
Scanners []Scanner `json:"scanners"`
@ -155,6 +156,7 @@ func DeriveStats(request StatsRequest) Stats {
type Instruction struct {
Message *string `json:"message,omitempty"`
MoveTo *v.Point2d `json:"move_to,omitempty"`
Heading *v.Vector2d `json:"heading,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
Probe *v.Point2d `json:"probe,omitempty"`
TargetSpeed *float32 `json:"target_speed,omitempty"`
@ -229,6 +231,11 @@ func (r *Robot) Tick(g *game) {
new_heading = r.MoveTo.Sub(r.Position).Normalize()
}
if r.DesiredHeading != nil {
// Where do we WANT to be heading?
new_heading = r.DesiredHeading.Normalize()
}
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