All programs / bucketballs
bucketballs
“Crappy Basketball”: aim, set the power, shoot
Play bucketballs
How to play
Click Play. A/D swing the aiming line, W/S change the launch speed (20–100), and Space shoots. Hit the red hoop on the right as it bobs up and down. You have 10 seconds after shooting before the game decides you’ve lost.
The interesting idea
Physics in small steps. Every tick, projectilePhysics() moves the ball by its velocity times dt, then adds gravity to the vertical velocity (Euler integration). The launch velocity comes from the angle with speed·cos θ and −speed·sin θ. The minus sign is there because screen y points down.
Collision by asking the scene. collide() uses getElementAt to see what is just below the ball and whether the ball is inside the hoop. It removes the ball first and adds it back afterwards so the ball can’t detect itself. Bounces off the floor, walls and ceiling reverse velocity and keep 75% of it.
Small touches: the hoop drifts on cos(osc), the ball leaves a dotted trail, and holding a key works because keyDown/keyUp set flags that a 20 ms timer polls.
It plays exactly as on CodeHS, quirks included. playing == true compares instead of assigns, so pressing Space again mid-flight starts another physics timer and the ball speeds up. Timers also pile up across replays.
Original source
The file exactly as saved on CodeHS, read-only. Open the raw file.
Evidence: CodeHS history
Screenshots of CodeHS’s “My Code History” page, which logs every save with a timestamp and the reason for it (autosave, run, paste).