Simple Collision Detection
This demonstration consists of a VERY minimal game. Click in the window to make it active, then try the up and down arrow keys (as well as left and right). You can dodge the zooming cannonball by ducking or jumping, depending whether it comes at head level or knee level. (You can also walk left or right, though there's no particular reason to do so in the current version.) Failing to dodge the cannonball is fatal.
This example was built on last week's keyboard-control example, adding the cannonball object, a new class to handle its behavior, and code in the sprite's class to detect collisions with the cannonball. On collision, the height of the cannonball is matched against the sprite's state. If the ball is high and the sprite is ducking, he survives. If the ball comes low and he is jumping, likewise. Any other state is fatal.
See the Code Resources page for source files, listed under 9-28-09.
|
|