// Find the ball closest to the impulse and within a reasonable // range, apply new velocity to the ball. func (gn *Engine) applyImpulse(impulse *model.Ball) { if gn.chatty { log.Printf("Got impulse: %s", impulse.String()) } closest, ball := gn.closestDsq(impulse.GetPos()) if ball == nil { if gn.chatty { log.Printf("No ball to punch.") } return } if gn.chatty { log.Printf("DSQ to ball: %f.1\n", closest) } if closest <= gn.maxDistSqForImpulse { if gn.chatty { log.Printf("Punching ball.\n") } ball.SetVel(impulse.GetVel().X, impulse.GetVel().Y) } else { if gn.chatty { log.Printf("Ball further than %f.1\n", gn.maxDistSqForImpulse) } } }
func serializeBall(b *model.Ball) ifc.Ball { wp := ifc.Player{int32(b.Owner().Id())} return ifc.Ball{ wp, b.GetPos().X, b.GetPos().Y, b.GetVel().X, b.GetVel().Y} }