float32 -> float64
This commit is contained in:
parent
db28bfea11
commit
8f7ef5aa1a
@ -16,11 +16,12 @@ import (
|
|||||||
// by a Controller.
|
// by a Controller.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Tick int `json:"tick"` // ms
|
Tick int `json:"tick"` // ms
|
||||||
Timescale float32 `json:"timescale"`
|
Timescale float64 `json:"timescale"`
|
||||||
Delta float32 `json:"delta"`
|
Delta float64 `json:"delta"`
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
ObstacleCount int `json:"obstacle_count"`
|
ObstacleCount int `json:"obstacle_count"`
|
||||||
|
Obstacles []Obstacle `json:'obstacles'`
|
||||||
MaxPoints int `json:"max_points"`
|
MaxPoints int `json:"max_points"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
}
|
}
|
||||||
@ -69,7 +70,7 @@ func LoadConfig(filename string) (Config, error) {
|
|||||||
return c, errors.New(fmt.Sprintf("config parse error: %s", err))
|
return c, errors.New(fmt.Sprintf("config parse error: %s", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Delta = (float32(c.Tick) / 1000.0) * float32(c.Timescale)
|
c.Delta = float64(c.Tick) / 1000.0 * c.Timescale
|
||||||
log.Printf("final config: %+v", c)
|
log.Printf("final config: %#v", c)
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
|
|||||||
log.Println("asked to create a game")
|
log.Println("asked to create a game")
|
||||||
|
|
||||||
requested_game_name := c.Idg.Hash()
|
requested_game_name := c.Idg.Hash()
|
||||||
width, height := float32(c.Conf.Width), float32(c.Conf.Height)
|
width, height := float64(c.Conf.Width), float64(c.Conf.Height)
|
||||||
obstacleCount := 0
|
obstacleCount := 0
|
||||||
maxPoints := c.Conf.MaxPoints
|
maxPoints := c.Conf.MaxPoints
|
||||||
mode := "deathmatch"
|
mode := "deathmatch"
|
||||||
@ -87,8 +87,8 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
requested_game_name = cfg.Name
|
requested_game_name = cfg.Name
|
||||||
width = float32(cfg.Width)
|
width = float64(cfg.Width)
|
||||||
height = float32(cfg.Height)
|
height = float64(cfg.Height)
|
||||||
obstacleCount = cfg.ObstacleCount
|
obstacleCount = cfg.ObstacleCount
|
||||||
maxPoints = cfg.MaxPoints
|
maxPoints = cfg.MaxPoints
|
||||||
mode = cfg.Mode
|
mode = cfg.Mode
|
||||||
|
8
game.go
8
game.go
@ -65,14 +65,14 @@ type Game struct {
|
|||||||
unregister chan *Player
|
unregister chan *Player
|
||||||
turn int
|
turn int
|
||||||
players_remaining int
|
players_remaining int
|
||||||
width, height float32
|
width, height float64
|
||||||
maxPoints int
|
maxPoints int
|
||||||
spectators map[*Spectator]bool
|
spectators map[*Spectator]bool
|
||||||
sregister chan *Spectator
|
sregister chan *Spectator
|
||||||
sunregister chan *Spectator
|
sunregister chan *Spectator
|
||||||
kill chan bool
|
kill chan bool
|
||||||
repair_hp int
|
repair_hp int
|
||||||
repair_rate float32
|
repair_rate float64
|
||||||
tick_duration int
|
tick_duration int
|
||||||
stats GameStats
|
stats GameStats
|
||||||
mode GameMode
|
mode GameMode
|
||||||
@ -87,7 +87,7 @@ type GameMode interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewGame Poplulates a Game struct and starts the bandwidth calculator.
|
// NewGame Poplulates a Game struct and starts the bandwidth calculator.
|
||||||
func NewGame(id string, width, height float32, obstacles, tick, maxPoints int, mode string) (*Game, error) {
|
func NewGame(id string, width, height float64, obstacles, tick, maxPoints int, mode string) (*Game, error) {
|
||||||
bw, err := bandwidth.NewBandwidth(
|
bw, err := bandwidth.NewBandwidth(
|
||||||
[]int{1, 10, 60},
|
[]int{1, 10, 60},
|
||||||
1*time.Second,
|
1*time.Second,
|
||||||
@ -263,7 +263,7 @@ func (g *Game) sendUpdate(payload *Boardstate) {
|
|||||||
|
|
||||||
// Filter objects
|
// Filter objects
|
||||||
for _, ob := range g.obstacles {
|
for _, ob := range g.obstacles {
|
||||||
if ob.distance_from_point(r.Position) < float32(r.Stats.ScannerRadius)+r.ScanCounter {
|
if ob.distance_from_point(r.Position) < float64(r.Stats.ScannerRadius)+r.ScanCounter {
|
||||||
player_payload.Objects = append(
|
player_payload.Objects = append(
|
||||||
player_payload.Objects, ob.minify())
|
player_payload.Objects, ob.minify())
|
||||||
}
|
}
|
||||||
|
14
obstacle.go
14
obstacle.go
@ -13,7 +13,7 @@ type Obstacle struct {
|
|||||||
Hp int `json:"-"`
|
Hp int `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Obstacle) distance_from_point(p v.Point2d) float32 {
|
func (o Obstacle) distance_from_point(p v.Point2d) float64 {
|
||||||
dist := math.MaxFloat32
|
dist := math.MaxFloat32
|
||||||
|
|
||||||
dist = math.Min(dist, float64(p.Sub(o.Bounds.A).Mag()))
|
dist = math.Min(dist, float64(p.Sub(o.Bounds.A).Mag()))
|
||||||
@ -21,7 +21,7 @@ func (o Obstacle) distance_from_point(p v.Point2d) float32 {
|
|||||||
dist = math.Min(dist, float64(p.Sub(v.Point2d{X: o.Bounds.A.X, Y: o.Bounds.B.Y}).Mag()))
|
dist = math.Min(dist, float64(p.Sub(v.Point2d{X: o.Bounds.A.X, Y: o.Bounds.B.Y}).Mag()))
|
||||||
dist = math.Min(dist, float64(p.Sub(v.Point2d{X: o.Bounds.B.X, Y: o.Bounds.A.Y}).Mag()))
|
dist = math.Min(dist, float64(p.Sub(v.Point2d{X: o.Bounds.B.X, Y: o.Bounds.A.Y}).Mag()))
|
||||||
|
|
||||||
return float32(dist)
|
return dist
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Obstacle) minify() [4]int {
|
func (o Obstacle) minify() [4]int {
|
||||||
@ -41,13 +41,13 @@ func MinifyObstacles(o []Obstacle) [][4]int {
|
|||||||
|
|
||||||
// GenerateObstacles returns a slice of (count) obstacles within a region
|
// GenerateObstacles returns a slice of (count) obstacles within a region
|
||||||
// bounded by width, height.
|
// bounded by width, height.
|
||||||
func GenerateObstacles(count int, width, height float32) []Obstacle {
|
func GenerateObstacles(count int, width, height float64) []Obstacle {
|
||||||
out := []Obstacle{}
|
out := []Obstacle{}
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
x := rand.Float32() * (width - (width / 10))
|
x := rand.Float64() * (width - (width / 10))
|
||||||
y := rand.Float32() * (height - (height / 10))
|
y := rand.Float64() * (height - (height / 10))
|
||||||
w := rand.Float32() * (width / 10)
|
w := rand.Float64() * (width / 10)
|
||||||
h := rand.Float32() * (height / 10)
|
h := rand.Float64() * (height / 10)
|
||||||
out = append(
|
out = append(
|
||||||
out,
|
out,
|
||||||
Obstacle{
|
Obstacle{
|
||||||
|
@ -159,7 +159,7 @@ func (p *Player) Recv() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if msg.TargetSpeed != nil {
|
if msg.TargetSpeed != nil {
|
||||||
r.TargetSpeed = float32(*msg.TargetSpeed)
|
r.TargetSpeed = *msg.TargetSpeed
|
||||||
} else {
|
} else {
|
||||||
r.TargetSpeed = r.Stats.Speed
|
r.TargetSpeed = r.Stats.Speed
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,10 @@ type Projectile struct {
|
|||||||
Position v.Point2d `json:"position"`
|
Position v.Point2d `json:"position"`
|
||||||
MoveTo v.Point2d `json:"-"`
|
MoveTo v.Point2d `json:"-"`
|
||||||
Radius int `json:"-"`
|
Radius int `json:"-"`
|
||||||
Speed float32 `json:"-"`
|
Speed float64 `json:"-"`
|
||||||
Damage int `json:"-"`
|
Damage int `json:"-"`
|
||||||
Owner *Robot `json:"-"`
|
Owner *Robot `json:"-"`
|
||||||
Delta float32
|
Delta float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Projectile.Tick is called every game tick and moves projectiles along,
|
// Projectile.Tick is called every game tick and moves projectiles along,
|
||||||
@ -98,7 +98,7 @@ func (p *Projectile) Tick(g *Game) {
|
|||||||
for player := range g.players {
|
for player := range g.players {
|
||||||
for _, r := range player.Robots {
|
for _, r := range player.Robots {
|
||||||
dist := v.Distance(r.Position, p.Position)
|
dist := v.Distance(r.Position, p.Position)
|
||||||
if dist < float32(p.Radius) {
|
if dist < float64(p.Radius) {
|
||||||
if r.Health > 0 {
|
if r.Health > 0 {
|
||||||
r.Health -= p.Damage
|
r.Health -= p.Damage
|
||||||
r.Hit = true
|
r.Hit = true
|
||||||
|
@ -71,8 +71,8 @@ func (config ClientConfig) Valid(max int) bool {
|
|||||||
|
|
||||||
// BoardSize is the response containing the geometry of the requested game.
|
// BoardSize is the response containing the geometry of the requested game.
|
||||||
type BoardSize struct {
|
type BoardSize struct {
|
||||||
Width float32 `json:"width"`
|
Width float64 `json:"width"`
|
||||||
Height float32 `json:"height"`
|
Height float64 `json:"height"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GameParam is sent to the client to tell them of the geometry of the game
|
// GameParam is sent to the client to tell them of the geometry of the game
|
||||||
@ -175,8 +175,8 @@ func (c *Controller) AddPlayer(ws *websocket.Conn) {
|
|||||||
var err error
|
var err error
|
||||||
game, err = NewGame(
|
game, err = NewGame(
|
||||||
gid.Id,
|
gid.Id,
|
||||||
float32(c.Conf.Width),
|
float64(c.Conf.Width),
|
||||||
float32(c.Conf.Height),
|
float64(c.Conf.Height),
|
||||||
c.Conf.ObstacleCount,
|
c.Conf.ObstacleCount,
|
||||||
c.Conf.Tick,
|
c.Conf.Tick,
|
||||||
c.Conf.MaxPoints,
|
c.Conf.MaxPoints,
|
||||||
|
100
robot.go
100
robot.go
@ -15,11 +15,11 @@ type Robot struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Message string `json:"-"`
|
Message string `json:"-"`
|
||||||
Stats Stats `json:"-"`
|
Stats Stats `json:"-"`
|
||||||
TargetSpeed float32 `json:"-"`
|
TargetSpeed float64 `json:"-"`
|
||||||
Speed float32 `json:"speed"`
|
Speed float64 `json:"speed"`
|
||||||
Health int `json:"health"`
|
Health int `json:"health"`
|
||||||
RepairCounter float32 `json:"repair"`
|
RepairCounter float64 `json:"repair"`
|
||||||
ScanCounter float32 `json:"scan_bonus"`
|
ScanCounter float64 `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"`
|
||||||
@ -33,7 +33,7 @@ type Robot struct {
|
|||||||
Probe *v.Point2d `json:"probe"`
|
Probe *v.Point2d `json:"probe"`
|
||||||
ProbeResult *Collision `json:"probe_result"`
|
ProbeResult *Collision `json:"probe_result"`
|
||||||
gameStats *BotStats `json:"-"`
|
gameStats *BotStats `json:"-"`
|
||||||
Delta float32 `json:"-"`
|
Delta float64 `json:"-"`
|
||||||
idg *IdGenerator
|
idg *IdGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,14 +101,14 @@ func (s AllRobotSorter) Less(i, j int) bool {
|
|||||||
// Stats is the point allocation for a Robot.
|
// Stats is the point allocation for a Robot.
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
Hp int `json:"hp"`
|
Hp int `json:"hp"`
|
||||||
Speed float32 `json:"speed"`
|
Speed float64 `json:"speed"`
|
||||||
Acceleration float32 `json:"acceleration"`
|
Acceleration float64 `json:"acceleration"`
|
||||||
WeaponRadius int `json:"weapon_radius"`
|
WeaponRadius int `json:"weapon_radius"`
|
||||||
ScannerRadius int `json:"scanner_radius"`
|
ScannerRadius int `json:"scanner_radius"`
|
||||||
TurnSpeed int `json:"turn_speed"`
|
TurnSpeed int `json:"turn_speed"`
|
||||||
FireRate int `json:"fire_rate"`
|
FireRate int `json:"fire_rate"`
|
||||||
WeaponDamage int `json:"weapon_damage"`
|
WeaponDamage int `json:"weapon_damage"`
|
||||||
WeaponSpeed float32 `json:"weapon_speed"`
|
WeaponSpeed float64 `json:"weapon_speed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatsRequest is the struct used in comunication with the player. We request
|
// StatsRequest is the struct used in comunication with the player. We request
|
||||||
@ -131,41 +131,41 @@ func DeriveStats(request StatsRequest) Stats {
|
|||||||
s := Stats{}
|
s := Stats{}
|
||||||
|
|
||||||
// Conversion Tables
|
// Conversion Tables
|
||||||
var hp_min float32 = 20.0
|
hp_min := 20.0
|
||||||
var hp_max float32 = 200.0
|
hp_max := 200.0
|
||||||
s.Hp = int(((float32(request.Hp) / 100.0) * (hp_max - hp_min)) + hp_min)
|
s.Hp = int((float64(request.Hp) / 100.0 * (hp_max - hp_min)) + hp_min)
|
||||||
|
|
||||||
var speed_min float32 = 40.0
|
speed_min := 40.0
|
||||||
var speed_max float32 = 200.0
|
speed_max := 200.0
|
||||||
s.Speed = ((float32(request.Speed) / 100.0) * (speed_max - speed_min)) + speed_min
|
s.Speed = float64(request.Speed)/100.0*(speed_max-speed_min) + speed_min
|
||||||
|
|
||||||
var accel_min float32 = 20.0
|
accel_min := 20.0
|
||||||
var accel_max float32 = 200.0
|
accel_max := 200.0
|
||||||
s.Acceleration = ((float32(request.Acceleration) / 100.0) * (accel_max - accel_min)) + accel_min
|
s.Acceleration = ((float64(request.Acceleration) / 100.0) * (accel_max - accel_min)) + accel_min
|
||||||
|
|
||||||
var wep_rad_min float32 = 5.0
|
wep_rad_min := 5.0
|
||||||
var wep_rad_max float32 = 60.0
|
wep_rad_max := 60.0
|
||||||
s.WeaponRadius = int(((float32(request.WeaponRadius) / 100.0) * (wep_rad_max - wep_rad_min)) + wep_rad_min)
|
s.WeaponRadius = int(((float64(request.WeaponRadius) / 100.0) * (wep_rad_max - wep_rad_min)) + wep_rad_min)
|
||||||
|
|
||||||
var scan_rad_min float32 = 100.0
|
scan_rad_min := 100.0
|
||||||
var scan_rad_max float32 = 400.0
|
scan_rad_max := 400.0
|
||||||
s.ScannerRadius = int(((float32(request.ScannerRadius) / 100.0) * (scan_rad_max - scan_rad_min)) + scan_rad_min)
|
s.ScannerRadius = int(((float64(request.ScannerRadius) / 100.0) * (scan_rad_max - scan_rad_min)) + scan_rad_min)
|
||||||
|
|
||||||
var turn_spd_min float32 = 30.0
|
turn_spd_min := 30.0
|
||||||
var turn_spd_max float32 = 300.0
|
turn_spd_max := 300.0
|
||||||
s.TurnSpeed = int(((float32(request.TurnSpeed) / 100.0) * (turn_spd_max - turn_spd_min)) + turn_spd_min)
|
s.TurnSpeed = int(((float64(request.TurnSpeed) / 100.0) * (turn_spd_max - turn_spd_min)) + turn_spd_min)
|
||||||
|
|
||||||
var fire_rate_min float32 = 10.0
|
fire_rate_min := 10.0
|
||||||
var fire_rate_max float32 = 2000.0
|
fire_rate_max := 2000.0
|
||||||
s.FireRate = int(fire_rate_max+300.0) - int(((float32(request.FireRate)/100.0)*(fire_rate_max-fire_rate_min))+fire_rate_min)
|
s.FireRate = int(fire_rate_max+300.0) - int(((float64(request.FireRate)/100.0)*(fire_rate_max-fire_rate_min))+fire_rate_min)
|
||||||
|
|
||||||
var weapon_damage_min float32 = 0.0
|
weapon_damage_min := 0.0
|
||||||
var weapon_damage_max float32 = 20.0
|
weapon_damage_max := 20.0
|
||||||
s.WeaponDamage = int(((float32(request.WeaponDamage) / 100.0) * (weapon_damage_max - weapon_damage_min)) + weapon_damage_min)
|
s.WeaponDamage = int(((float64(request.WeaponDamage) / 100.0) * (weapon_damage_max - weapon_damage_min)) + weapon_damage_min)
|
||||||
|
|
||||||
var weapon_speed_min float32 = 80.0
|
weapon_speed_min := 80.0
|
||||||
var weapon_speed_max float32 = 600.0
|
weapon_speed_max := 600.0
|
||||||
s.WeaponSpeed = float32(((float32(request.WeaponSpeed) / 100.0) * (weapon_speed_max - weapon_speed_min)) + weapon_speed_min)
|
s.WeaponSpeed = float64(((float64(request.WeaponSpeed) / 100.0) * (weapon_speed_max - weapon_speed_min)) + weapon_speed_min)
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ type Instruction struct {
|
|||||||
Heading *v.Vector2d `json:"heading,omitempty"`
|
Heading *v.Vector2d `json:"heading,omitempty"`
|
||||||
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
FireAt *v.Point2d `json:"fire_at,omitempty"`
|
||||||
Probe *v.Point2d `json:"probe,omitempty"`
|
Probe *v.Point2d `json:"probe,omitempty"`
|
||||||
TargetSpeed *float32 `json:"target_speed,omitempty"`
|
TargetSpeed *float64 `json:"target_speed,omitempty"`
|
||||||
Repair *bool `json:"repair,omitempty"`
|
Repair *bool `json:"repair,omitempty"`
|
||||||
Scan *bool `json:"scan,omitempty"`
|
Scan *bool `json:"scan,omitempty"`
|
||||||
}
|
}
|
||||||
@ -187,12 +187,12 @@ type Instruction struct {
|
|||||||
func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *Robot) {
|
func (r *Robot) checkCollisions(g *Game, probe v.Vector2d) (bool, *v.Point2d, *Robot) {
|
||||||
finalCollision := false
|
finalCollision := false
|
||||||
collision := false
|
collision := false
|
||||||
closest := float32(math.Inf(1))
|
closest := math.Inf(1)
|
||||||
var intersection *v.Point2d
|
var intersection *v.Point2d
|
||||||
var finalRobot *Robot
|
var finalRobot *Robot
|
||||||
|
|
||||||
// TODO: this needs moved to the conf?
|
// TODO: this needs moved to the conf?
|
||||||
botSize := float32(5.0)
|
botSize := 5.0
|
||||||
botPolygon := v.OrientedSquare(r.Position, r.Heading, botSize)
|
botPolygon := v.OrientedSquare(r.Position, r.Heading, botSize)
|
||||||
|
|
||||||
// Check Walls
|
// Check Walls
|
||||||
@ -314,12 +314,12 @@ func (r *Robot) Tick(g *Game) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Max turn radius in this case is in degrees per second
|
// Max turn radius in this case is in degrees per second
|
||||||
if float32(math.Abs(float64(angle))) > (float32(r.Stats.TurnSpeed) * r.Delta) {
|
if math.Abs(angle) > float64(r.Stats.TurnSpeed)*r.Delta {
|
||||||
// New heading should be a little less, take current heading and
|
// New heading should be a little less, take current heading and
|
||||||
// rotate by the max turn radius per frame.
|
// rotate by the max turn radius per frame.
|
||||||
rot := (float32(r.Stats.TurnSpeed) * r.Delta) * v.Deg2rad
|
rot := (float64(r.Stats.TurnSpeed) * r.Delta) * v.Deg2rad
|
||||||
|
|
||||||
new_heading = current_heading.Rotate(rot * float32(dir))
|
new_heading = current_heading.Rotate(rot * dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
move_vector := new_heading.Scale(r.Speed * r.Delta)
|
move_vector := new_heading.Scale(r.Speed * r.Delta)
|
||||||
@ -386,9 +386,9 @@ func (r *Robot) Tick(g *Game) {
|
|||||||
|
|
||||||
// We are only allowed to scan when we're stopped
|
// We are only allowed to scan when we're stopped
|
||||||
if math.Abs(float64(r.Speed)) < v.Epsilon && r.ActiveScan {
|
if math.Abs(float64(r.Speed)) < v.Epsilon && r.ActiveScan {
|
||||||
r.ScanCounter += r.Delta * float32(r.Stats.ScannerRadius) * 0.1
|
r.ScanCounter += r.Delta * float64(r.Stats.ScannerRadius) * 0.1
|
||||||
} else if r.ScanCounter > 0 {
|
} else if r.ScanCounter > 0 {
|
||||||
r.ScanCounter -= r.Delta * float32(r.Stats.ScannerRadius) * 0.05
|
r.ScanCounter -= r.Delta * float64(r.Stats.ScannerRadius) * 0.05
|
||||||
if r.ScanCounter <= 0 {
|
if r.ScanCounter <= 0 {
|
||||||
r.ScanCounter = 0
|
r.ScanCounter = 0
|
||||||
}
|
}
|
||||||
@ -425,7 +425,7 @@ func (r *Robot) scan(g *Game) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dist := v.Distance(bot.Position, r.Position)
|
dist := v.Distance(bot.Position, r.Position)
|
||||||
if dist < float32(r.Stats.ScannerRadius+int(r.ScanCounter)) {
|
if dist < float64(r.Stats.ScannerRadius+int(r.ScanCounter)) {
|
||||||
s := Scanner{
|
s := Scanner{
|
||||||
Id: bot.Id,
|
Id: bot.Id,
|
||||||
Type: "robot",
|
Type: "robot",
|
||||||
@ -441,7 +441,7 @@ func (r *Robot) scan(g *Game) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dist := v.Distance(proj.Position, r.Position)
|
dist := v.Distance(proj.Position, r.Position)
|
||||||
if dist < float32(r.Stats.ScannerRadius+int(r.ScanCounter)) {
|
if dist < float64(r.Stats.ScannerRadius+int(r.ScanCounter)) {
|
||||||
s := Scanner{
|
s := Scanner{
|
||||||
Id: proj.Id,
|
Id: proj.Id,
|
||||||
Type: "projectile",
|
Type: "projectile",
|
||||||
@ -452,7 +452,7 @@ func (r *Robot) scan(g *Game) {
|
|||||||
|
|
||||||
for splo := range g.splosions {
|
for splo := range g.splosions {
|
||||||
dist := v.Distance(splo.Position, r.Position)
|
dist := v.Distance(splo.Position, r.Position)
|
||||||
if dist < float32(r.Stats.ScannerRadius+int(r.ScanCounter)) {
|
if dist < float64(r.Stats.ScannerRadius+int(r.ScanCounter)) {
|
||||||
s := Scanner{
|
s := Scanner{
|
||||||
Id: splo.Id,
|
Id: splo.Id,
|
||||||
Type: "explosion",
|
Type: "explosion",
|
||||||
@ -466,8 +466,8 @@ func (r *Robot) scan(g *Game) {
|
|||||||
// fire is called according to player instruction. XXX: There is a race here...
|
// fire is called according to player instruction. XXX: There is a race here...
|
||||||
func (r *Robot) fire(g *Game) *Projectile {
|
func (r *Robot) fire(g *Game) *Projectile {
|
||||||
// Throttle the fire rate
|
// Throttle the fire rate
|
||||||
time_since_fired := (float32(g.turn) * (r.Delta * 1000)) - (float32(r.LastFired) * (r.Delta * 1000))
|
time_since_fired := (float64(g.turn) * (r.Delta * 1000)) - (float64(r.LastFired) * (r.Delta * 1000))
|
||||||
if time_since_fired < float32(r.Stats.FireRate) {
|
if time_since_fired < float64(r.Stats.FireRate) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,8 +490,8 @@ func (r *Robot) fire(g *Game) *Projectile {
|
|||||||
func (r *Robot) reset(g *Game) {
|
func (r *Robot) reset(g *Game) {
|
||||||
for {
|
for {
|
||||||
start_pos := v.Point2d{
|
start_pos := v.Point2d{
|
||||||
X: rand.Float32() * float32(g.width),
|
X: rand.Float64() * float64(g.width),
|
||||||
Y: rand.Float32() * float32(g.height),
|
Y: rand.Float64() * float64(g.height),
|
||||||
}
|
}
|
||||||
r.MoveTo = &start_pos
|
r.MoveTo = &start_pos
|
||||||
r.Position = start_pos
|
r.Position = start_pos
|
||||||
|
Loading…
Reference in New Issue
Block a user