//A program that lets the user shoot a basketball into a net. //Variables float gravityBallX = 100; float gravityBallY = 150; float accelerate = 0; float gravity = 0.2; float score = 0; //Sets up the regular settings void setup(){ size (400,400); ellipseMode (CENTER); rectMode (CORNERS); } //Draws all specified items void draw() { //background changes colour dependent on mouse location background (0, 170-mouseY/3,255-mouseY/2); //The Ground rect (0,400,400,390); //draws specified items TheCity(); drawgravityBall(); drawNet(); drawNetCatcher(); drawBall(); //if user gets the ball to the net it will output "Nice Shot!" if (gravityBallX > 290 && gravityBallX < 320 && gravityBallY >= 215 && gravityBallY >= 190 && gravityBallY >=220 && gravityBallY >=195) { println ("Nice Shot!"); } } //Draws the Net void drawNet(){ //Pole of the net fill(50); rect (350,150,330,390); //Backboard of the net fill(155); rect (310,150,370,220); fill(#FF9727); //looped clouds to shorten code fill(255); for (int i = 0; i < 8; i++){ noStroke(); ellipse (i * 90, 40,120,120); stroke(1);} } //Little building in the background void TheCity(){ fill(50); rect (50,390,125,200); rect (70,190,90,200); } //the net for the basketball void drawNetCatcher(){ fill(#D82B00); rect(290,215,320,220); noStroke(); rect(320,205,360,165); fill(#B7B7B7); quad(290,220,320,220,310,250,300,250); stroke(1); } void drawBall(){ fill(#FF9727); ellipse(gravityBallX,gravityBallY,20,20); } //gravity for the basketball void drawgravityBall(){ gravityBallY=gravityBallY+accelerate; accelerate = accelerate + gravity; //Code that allows the user to move the ball if (gravityBallY>height) { accelerate = accelerate * -1; gravityBallY = height; } if (key=='A' || key == 'a'){ gravityBallX = gravityBallX-3; } if (key=='D' || key == 'd'){ gravityBallX = gravityBallX+3; } }