Moved definition of what robots have which stats into the player interface
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"hackerbots.us/server"
|
||||
"hackerbots.us/vector"
|
||||
)
|
||||
|
||||
// Fraserbot is a bad ass motherfucker, that will fuck SHIT UUUUUP
|
||||
type Fraserbot struct {
|
||||
me server.Robot
|
||||
knownObstacles map[string]server.Obstacle
|
||||
nearestEnemy *server.OtherRobot
|
||||
fireat *vector.Point2d
|
||||
moveto *vector.Point2d
|
||||
speed float64
|
||||
stats server.StatsRequest
|
||||
name string
|
||||
}
|
||||
|
||||
// NewFraserbot simply returns a populated, usable *Fraserbot
|
||||
func NewFraserbot(name string, stats server.StatsRequest) *Fraserbot {
|
||||
return &Fraserbot{
|
||||
knownObstacles: make(map[string]server.Obstacle),
|
||||
stats: stats,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
// GetStats returns a map with an entry for each robot the player will control
|
||||
// containing the desired stats for that robot
|
||||
func (p *Fraserbot) GetStats() map[string]server.StatsRequest {
|
||||
s := make(map[string]server.StatsRequest)
|
||||
|
||||
s[fmt.Sprintf("%v_MAIN", p.name)] = server.StatsRequest{
|
||||
Hp: 10,
|
||||
Speed: 10,
|
||||
Acceleration: 10,
|
||||
ScannerRadius: 10,
|
||||
TurnSpeed: 10,
|
||||
FireRate: 10,
|
||||
WeaponRadius: 10,
|
||||
WeaponDamage: 10,
|
||||
WeaponSpeed: 10,
|
||||
}
|
||||
|
||||
s[fmt.Sprintf("%v_Jr", p.name)] = server.StatsRequest{
|
||||
Hp: 10,
|
||||
Speed: 10,
|
||||
Acceleration: 10,
|
||||
ScannerRadius: 10,
|
||||
TurnSpeed: 10,
|
||||
FireRate: 10,
|
||||
WeaponRadius: 10,
|
||||
WeaponDamage: 10,
|
||||
WeaponSpeed: 10,
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Update is our implementation of recieving and processing a server.Boardstate
|
||||
// from the server
|
||||
func (p *Fraserbot) Update(bs *server.Boardstate) map[string]server.Instruction {
|
||||
instructions := make(map[string]server.Instruction)
|
||||
for _, bot := range bs.MyRobots {
|
||||
p.me = bot
|
||||
p.speed = 1000
|
||||
|
||||
if p.moveto == nil {
|
||||
p.moveto = &p.me.Position
|
||||
}
|
||||
|
||||
if p.me.Position.Sub(*p.moveto).Mag() < 30 {
|
||||
p.moveto = p.randomDirection()
|
||||
}
|
||||
|
||||
instructions[bot.Id] = server.Instruction{
|
||||
MoveTo: p.moveto,
|
||||
TargetSpeed: &p.speed,
|
||||
FireAt: p.fireat,
|
||||
}
|
||||
}
|
||||
return instructions
|
||||
}
|
||||
|
||||
// randomDirection is a spot within 200 of the current position
|
||||
func (p *Fraserbot) randomDirection() *vector.Point2d {
|
||||
pt := vector.Vector2d{
|
||||
X: (rand.Float64() * 400) - 200 + p.me.Position.X,
|
||||
Y: (rand.Float64() * 400) - 200 + p.me.Position.Y,
|
||||
}.ToPoint()
|
||||
return &pt
|
||||
}
|
||||
Reference in New Issue
Block a user