Projectile Time to Collision
We start the collision computation in the Projectile class. The path of the projectile is a straight line originating at the weapon's center and at the angle of the weapon. From this information, we can easily write the parametric equations for the path of the projectile. Next, the path of the moving target is a horizontal line and, in turn, its path is describe by a single parametric equation of the form y = constant. Further, the constant is set at compile time. Using this constant in the parametric equations for the projectile's path, we determine the x-coordinate of the intersection point.
Next, we compute in the Projectile class the time taken to reach the intersection point. Also, we provide the time as frames since that is our unit of measure. Thus, we have the Projectile class report the x-coordinate of the point of intersection and the frame count to reach that point. This information is passed to the MovingTarget class.