Example #1
0
// 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)
		}
	}
}