The Cannon Lullaby Toy
Ian Parberry's "Introduction to Game Physics"
|
The Cannon Lullaby Toy plays the first seven notes of the classic lullaby "Twinkle Twinkle Little Star" using a cannon and three bells. The cannonballs leave trails of stars so that their parabolic trajectories are clearly visible. You can see how these trajectories change when you move the cannon or change the height of the flowers (however, the cannon will break if you drive it over the edge of the platform). The cannon barrel is fixed at about 45 degrees. "Twinkle Twinkle Little Star" is hard-coded as "CCGGAAG" played at about three beats per second, but this is pretty easy to change in the code.
The tricky bit is figuring out how to get the cannonballs to the right places at the right times when they are all fired from the cannon simultaneously. No worries though, it's not as hard as it might seem provided you grok relative velocity and the formulae \(s=ut+at^2/f\) and \(v=u+at\).
F1 | Help (this document) |
1 | Left flower up |
2 | Left flower down |
3 | Center flower up |
4 | Center flower down |
5 | Right flower up |
6 | Right flower down |
Space | Fire cannon |
Left arrow | Move cannon left |
Right arrow | Move cannon right |
S | Stop cannon |
PrtScr (hold down) | Save screenshot to a PNG file |
This code uses the LARC Engine and is part of the LARC Code Base.