first pass at repair mode
This commit is contained in:
parent
cfd3d91942
commit
082b737805
49
player.go
49
player.go
@ -39,18 +39,32 @@ func (p *player) recv() {
|
|||||||
log.Print("problem receiving JSON from player: ", err)
|
log.Print("problem receiving JSON from player: ", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if msg.MoveTo != nil {
|
|
||||||
p.Robot.MoveTo = msg.MoveTo
|
if msg.Repair != nil {
|
||||||
}
|
p.Robot.TargetSpeed = 0
|
||||||
if msg.FireAt != nil {
|
p.Robot.FireAt = nil
|
||||||
p.Robot.FireAt = msg.FireAt
|
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
|
||||||
|
}
|
||||||
|
if msg.FireAt != nil {
|
||||||
|
p.Robot.FireAt = msg.FireAt
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.TargetSpeed != nil {
|
||||||
|
p.Robot.TargetSpeed = float32(*msg.TargetSpeed)
|
||||||
|
} else {
|
||||||
|
p.Robot.TargetSpeed = p.Robot.Stats.Speed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.TargetSpeed != nil {
|
|
||||||
p.Robot.TargetSpeed = float32(*msg.TargetSpeed)
|
|
||||||
} else {
|
|
||||||
p.Robot.TargetSpeed = p.Robot.Stats.Speed
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log.Printf("player %s: recv close", p.Robot.Id)
|
log.Printf("player %s: recv close", p.Robot.Id)
|
||||||
p.ws.Close()
|
p.ws.Close()
|
||||||
@ -116,8 +130,11 @@ func (p *player) Tick(g *game) {
|
|||||||
current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
|
current_heading = p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where do we WANT to be heading?
|
new_heading := current_heading
|
||||||
new_heading := p.Robot.MoveTo.Sub(p.Robot.Position).Normalize()
|
if p.Robot.MoveTo != nil {
|
||||||
|
// Where do we WANT to be heading?
|
||||||
|
new_heading = p.Robot.MoveTo.Sub(p.Robot.Position).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
|
||||||
@ -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 {
|
if p.Robot.FireAt != nil {
|
||||||
proj := p.fire(g.projectiles, g.turn)
|
proj := p.fire(g.projectiles, g.turn)
|
||||||
if proj != nil {
|
if proj != nil {
|
||||||
|
28
robot.go
28
robot.go
@ -5,19 +5,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Robot struct {
|
type Robot struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
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"`
|
||||||
Position v.Point2d `json:"position"`
|
RepairCounter float32 `json:"repair"`
|
||||||
Heading v.Vector2d `json:"heading"`
|
Position v.Point2d `json:"position"`
|
||||||
MoveTo *v.Point2d `json:"-"`
|
Heading v.Vector2d `json:"heading"`
|
||||||
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:"-"`
|
||||||
|
Collision bool `json:"collision"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the subset of data we send to players about robots
|
// This is the subset of data we send to players about robots
|
||||||
@ -157,5 +158,6 @@ type Instruction struct {
|
|||||||
MoveTo *v.Point2d `json:"move_to,omitempty"`
|
MoveTo *v.Point2d `json:"move_to,omitempty"`
|
||||||
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
||||||
TargetSpeed *float32 `json:"target_speed,omitempty"`
|
TargetSpeed *float32 `json:"target_speed,omitempty"`
|
||||||
|
Repair *bool `json:"repair,omitempty"`
|
||||||
Stats Stats `json:"stats"`
|
Stats Stats `json:"stats"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user