public static InformationPacket Update(Puck p, Puck c, Table table, double delta_time)
{
double offset = p.Velocity.Speed * delta_time;
double x = offset * Math.Cos(p.Velocity.Direction);
double y = offset * Math.Sin(p.Velocity.Direction);
PointD ghost_puck_location = p.Location.Offset(x, y);
//Collect debugging information as we loop through the collision algorithm
InformationPacket info = new InformationPacket();
info.Points.Add(ghost_puck_location);
//Collision correction
CollisionData data;
while ((data = GetClosestCollisionData(p, offset, ghost_puck_location, c, table)) != null) {
p.Location = data.collision_point;
p.Velocity.Direction = p.Velocity.Direction.Reflect(data.projection_line.Perpendicular(data.collision_point).Angle) + Angle._180;
PointD translation_reflection_point = data.projection_line.IntersectionWith(data.projection_line.Perpendicular(ghost_puck_location));
ghost_puck_location = translation_reflection_point.Offset(translation_reflection_point.X - ghost_puck_location.X, translation_reflection_point.Y - ghost_puck_location.Y);
offset = ghost_puck_location.DistanceTo(p.Location);
if (energy_loss_enabled)
p.Velocity.Speed *= .8;
info.Points.Add(ghost_puck_location);
}
//Shazam (physics calculations are complete)
p.Location = ghost_puck_location;
if (energy_loss_enabled) {
p.Velocity.Speed -= delta_time * table.Friction;
if (p.Velocity.Speed < 0) { p.Velocity.Speed = 0; }
}
return info;
}