Cannon is easy
You just have to define the initial speed of the bullet and then change it over time with predefined values.
Something like this:
var spdX,spdY,gravityMod;
Define the gravityMod with some value.
Then when the cannonball is shot you define the starting speed. I recomend looking up the move based on rotation method.
Then you just change the coordinates by the speed value and then change speed on predefined values. like this:
this.x+=spdX;
this.y+=spdY;
spdY-=gravityMod;
This way your ball will start falling down over time.
You could also add air friction and wind as an additional parameters and modify speed some more.
CATapult and slingshot are harder, because you have to calculate how the ball moves before it leaves the … ummm… however the thing that holds the ball is called… sling? I cant say anything on this part.
But after that in a free flight its pretty much the same.
I hope i helped at least a little. Godspeed.
|