Shooting the ball
In this task, we create a hoop and allow the player to throw the ball by clicking the mouse button. The ball may or may not pass through the hoop based on the throwing angle and power.
Prepare for lift off
We remove the two bodies that were created in the first task. Those two bodies were just an experiment and we don't need them anymore.
Engage thrusters
In the following steps, we will create the core part of this project—shooting the ball:
- We will create a hoop and spawn a ball in the physics world. We create a function for these two tasks:
physics.createLevel = function() { this.createHoop(); // the first ball this.spawnBall(); };
- We are going to spawn many balls. We define the following method for this task. In this task, we hardcode the position, ball size, and fixture properties. The ball is spawned as a static object until the player throws the ball out:
physics.spawnBall = function() { var positionX = 300; var positionY = 200; var radius = 13;...