Convert to 32-bit to save space in the serialization

This commit is contained in:
Fraser Graham
2013-10-19 00:00:51 -07:00
parent c074397c1f
commit f9b18eb253
6 changed files with 47 additions and 46 deletions
+9 -9
View File
@@ -110,12 +110,12 @@ func (p *player) nudge(g *game) {
}
// Max turn radius in this case is in degrees per second
if math.Abs(angle) > (float64(p.Robot.Stats.TurnSpeed) * delta) {
if float32(math.Abs(float64(angle))) > (float32(p.Robot.Stats.TurnSpeed) * delta) {
// New heading should be a little less, take current heading and
// rotate by the max turn radius per frame.
rot := (float64(p.Robot.Stats.TurnSpeed) * delta) * v.Deg2rad
rot := (float32(p.Robot.Stats.TurnSpeed) * delta) * v.Deg2rad
new_heading = current_heading.Rotate(rot * dir)
new_heading = current_heading.Rotate(rot * float32(dir))
}
move_vector := new_heading.Scale(p.Robot.Speed * delta)
@@ -146,7 +146,7 @@ func (p *player) scan(players map[*player]bool) {
continue
}
dist := v.Distance(player.Robot.Position, p.Robot.Position)
if dist < float64(p.Robot.Stats.ScannerRadius) {
if dist < float32(p.Robot.Stats.ScannerRadius) {
s := Scanner{
Position: v.Point2d{
X: player.Robot.Position.X,
@@ -160,8 +160,8 @@ func (p *player) scan(players map[*player]bool) {
func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile {
// Throttle the fire rate
time_since_fired := (float64(turn) * (delta * 1000)) - (float64(p.Robot.LastFired) * (delta * 1000))
if time_since_fired < float64(p.Robot.Stats.FireRate) {
time_since_fired := (float32(turn) * (delta * 1000)) - (float32(p.Robot.LastFired) * (delta * 1000))
if time_since_fired < float32(p.Robot.Stats.FireRate) {
return nil
}
@@ -173,14 +173,14 @@ func (p *player) fire(projectiles map[*Projectile]bool, turn int) *Projectile {
MoveTo: *p.Robot.FireAt,
Damage: 10,
Radius: p.Robot.Stats.WeaponRadius,
Speed: float64(p.Robot.Stats.Speed * 3),
Speed: float32(p.Robot.Stats.Speed * 3),
}
}
func (p *player) reset() {
start_pos := v.Point2d{
X: rand.Float64() * *width,
Y: rand.Float64() * *height,
X: rand.Float32() * float32(*width),
Y: rand.Float32() * float32(*height),
}
p.Robot.MoveTo = &start_pos
p.Robot.Position = start_pos