first pass at repair mode

This commit is contained in:
Fraser Graham 2013-11-06 22:50:59 -08:00
parent cfd3d91942
commit 082b737805
2 changed files with 52 additions and 25 deletions

View File

@ -39,6 +39,18 @@ func (p *player) recv() {
log.Print("problem receiving JSON from player: ", err)
break
}
if msg.Repair != nil {
p.Robot.TargetSpeed = 0
p.Robot.FireAt = nil
p.Robot.MoveTo = nil
if p.Robot.RepairCounter <= 0 {
p.Robot.RepairCounter = 3.0
}
} else {
p.Robot.RepairCounter = 0
// Reapiring halts all other activity
if msg.MoveTo != nil {
p.Robot.MoveTo = msg.MoveTo
}
@ -52,6 +64,8 @@ func (p *player) recv() {
p.Robot.TargetSpeed = p.Robot.Stats.Speed
}
}
}
log.Printf("player %s: recv close", p.Robot.Id)
p.ws.Close()
}
@ -116,8 +130,11 @@ func (p *player) Tick(g *game) {
current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
}
new_heading := current_heading
if p.Robot.MoveTo != nil {
// Where do we WANT to be heading?
new_heading := p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
new_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
}
if new_heading.Mag() > 0 {
// Is our direction change too much? Hard coding to 5 degrees/s for now
@ -165,6 +182,14 @@ func (p *player) Tick(g *game) {
}
}
if math.Abs(float64(p.Robot.Speed)) < v.Epsilon && p.Robot.RepairCounter > 0 {
p.Robot.RepairCounter -= delta
if p.Robot.RepairCounter < 0 {
p.Robot.Health += 5
p.Robot.RepairCounter = 3.0
}
}
if p.Robot.FireAt != nil {
proj := p.fire(g.projectiles, g.turn)
if proj != nil {

View File

@ -11,6 +11,7 @@ type Robot struct {
TargetSpeed float32 `json:"-"`
Speed float32 `json:"speed"`
Health int `json:"health"`
RepairCounter float32 `json:"repair"`
Position v.Point2d `json:"position"`
Heading v.Vector2d `json:"heading"`
MoveTo *v.Point2d `json:"-"`
@ -157,5 +158,6 @@ type Instruction struct {
MoveTo *v.Point2d `json:"move_to,omitempty"`
FireAt *v.Point2d `json:"fire_at,omitempty"`
TargetSpeed *float32 `json:"target_speed,omitempty"`
Repair *bool `json:"repair,omitempty"`
Stats Stats `json:"stats"`
}