Ballistic is an unfinished game that you are supposed to finish. You fire from two cannons (in turns) and the cannon balls should fly according to the laws of physics - that is obviously not the case at the current stage of development. Please do the following things:
- Apply laws of physics to model a realistic trajectory for the cannon balls.
- Detect when the ball hits the ground or a cannon, and also control the situation when the ball leaves the screen far above the ground.
- Calculate score for all the canons hits and change turns so that two players could play the game.
Most things are to be done within the CannonBall class. This is a Sprite subclass. It already draws itself (the onDraw function) and uses its default onUpdate behaviour to apply some generic motion. This motion is currently linear and infinite what obviously is not what we want to get.
Any object thrown has two velocity components. One of them, horizontal, is constant and is equal to the horizontal component at the moment of firing. According to Newton's 1st law this velocity does not change. Real objects subject to the air resistance and in fact their horizontal component is slightly delayed, but we will ignore this. Objects fall with acceleration of g=9.81 m/s2 (close to the Earth surface). If thrown, they also get some initial vertical component of velocity, that is constant. This initial velocity is gradually changed over the time. The general formula is:
v = v0 + gt
where v0 is the initial velocity (vertical), g is Earth acceleration and t is the time.
Notice that the sign of v0 may be different than that of g. In that case the acceleration first causes the motion to delay until it stops, and then a regular fall begins, until the object hits the ground!
You can use your ball Sprite to read all its current params including position, velocity and its componnents, etc. The array called silhouette contains a set of values defining the shape of the ground (that brown mountain) and therefore may be used to detect if the ball hits the ground. Lastly, you can use cannon[0] and cannon[1] to determine the position of the left and the right cannon, respectively.
Hint: CannonBall.onUpdate is a good place to put most of your code (why?)
Good luck!
No comments:
Post a Comment