support setting heading in instructions
This commit is contained in:
parent
3f40fe4603
commit
c7d5e4be87
@ -69,6 +69,9 @@ func (p *player) recv() {
|
|||||||
if msg.MoveTo != nil {
|
if msg.MoveTo != nil {
|
||||||
r.MoveTo = msg.MoveTo
|
r.MoveTo = msg.MoveTo
|
||||||
}
|
}
|
||||||
|
if msg.Heading != nil {
|
||||||
|
r.DesiredHeading = msg.Heading
|
||||||
|
}
|
||||||
if msg.FireAt != nil {
|
if msg.FireAt != nil {
|
||||||
r.FireAt = msg.FireAt
|
r.FireAt = msg.FireAt
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
v "bitbucket.org/hackerbots/vector"
|
||||||
"code.google.com/p/go.net/websocket"
|
"code.google.com/p/go.net/websocket"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
@ -203,6 +204,7 @@ func addPlayer(ws *websocket.Conn) {
|
|||||||
Id: idg.Hash(),
|
Id: idg.Hash(),
|
||||||
Name: name,
|
Name: name,
|
||||||
Health: 10,
|
Health: 10,
|
||||||
|
Heading: v.Vector2d{1, 0},
|
||||||
Scanners: make([]Scanner, 0)}
|
Scanners: make([]Scanner, 0)}
|
||||||
r.Health = r.Stats.Hp
|
r.Health = r.Stats.Hp
|
||||||
log.Printf("Adding Robot: %v", r)
|
log.Printf("Adding Robot: %v", r)
|
||||||
|
61
robot.go
61
robot.go
@ -8,26 +8,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Robot struct {
|
type Robot struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Message string `json:"-"`
|
Message string `json:"-"`
|
||||||
Stats Stats `json:"-"`
|
Stats Stats `json:"-"`
|
||||||
TargetSpeed float32 `json:"-"`
|
TargetSpeed float32 `json:"-"`
|
||||||
Speed float32 `json:"speed"`
|
Speed float32 `json:"speed"`
|
||||||
Health int `json:"health"`
|
Health int `json:"health"`
|
||||||
RepairCounter float32 `json:"repair"`
|
RepairCounter float32 `json:"repair"`
|
||||||
ScanCounter float32 `json:"scan_bonus"`
|
ScanCounter float32 `json:"scan_bonus"`
|
||||||
ActiveScan bool `json:"-"`
|
ActiveScan bool `json:"-"`
|
||||||
Position v.Point2d `json:"position"`
|
Position v.Point2d `json:"position"`
|
||||||
Heading v.Vector2d `json:"heading"`
|
Heading v.Vector2d `json:"heading"`
|
||||||
MoveTo *v.Point2d `json:"-"`
|
DesiredHeading *v.Vector2d `json:"-"`
|
||||||
FireAt *v.Point2d `json:"-"`
|
MoveTo *v.Point2d `json:"-"`
|
||||||
Scanners []Scanner `json:"scanners"`
|
FireAt *v.Point2d `json:"-"`
|
||||||
LastFired int `json:"-"`
|
Scanners []Scanner `json:"scanners"`
|
||||||
Collision bool `json:"collision"`
|
LastFired int `json:"-"`
|
||||||
Hit bool `json:"hit"`
|
Collision bool `json:"collision"`
|
||||||
Probe *v.Point2d `json:"probe"`
|
Hit bool `json:"hit"`
|
||||||
ProbeResult *v.Point2d `json:"probe_result"`
|
Probe *v.Point2d `json:"probe"`
|
||||||
|
ProbeResult *v.Point2d `json:"probe_result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the subset of data we send to players about robots
|
// This is the subset of data we send to players about robots
|
||||||
@ -153,13 +154,14 @@ func DeriveStats(request StatsRequest) Stats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Instruction struct {
|
type Instruction struct {
|
||||||
Message *string `json:"message,omitempty"`
|
Message *string `json:"message,omitempty"`
|
||||||
MoveTo *v.Point2d `json:"move_to,omitempty"`
|
MoveTo *v.Point2d `json:"move_to,omitempty"`
|
||||||
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
Heading *v.Vector2d `json:"heading,omitempty"`
|
||||||
Probe *v.Point2d `json:"probe,omitempty"`
|
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
||||||
TargetSpeed *float32 `json:"target_speed,omitempty"`
|
Probe *v.Point2d `json:"probe,omitempty"`
|
||||||
Repair *bool `json:"repair,omitempty"`
|
TargetSpeed *float32 `json:"target_speed,omitempty"`
|
||||||
Scan *bool `json:"scan,omitempty"`
|
Repair *bool `json:"repair,omitempty"`
|
||||||
|
Scan *bool `json:"scan,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2d, *Robot) {
|
func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2d, *Robot) {
|
||||||
@ -229,6 +231,11 @@ func (r *Robot) Tick(g *game) {
|
|||||||
new_heading = r.MoveTo.Sub(r.Position).Normalize()
|
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 {
|
if new_heading.Mag() > 0 {
|
||||||
// Is our direction change too much? Hard coding to 5 degrees/s for now
|
// Is our direction change too much? Hard coding to 5 degrees/s for now
|
||||||
angle := v.Angle(current_heading, new_heading) * v.Rad2deg
|
angle := v.Angle(current_heading, new_heading) * v.Rad2deg
|
||||||
|
Loading…
Reference in New Issue
Block a user