Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
//3 POINTER BY STEVIE RAY HUNTER//
//SETTING VARIABLES

//FLOATS
float xpos, ypos;  // Starting position of hoop 
float xspeed = 7.0; // Speed of the hoop
float yspeed = 2.2; // Speed of the hoop
float thr = 50.0; // How much force the ball is thrown with
float blposY = 320.0; //ball starting value
float blxpos = mouseX;
float gravity = 12.5; //Gravity for returing the ball to the player


//INTS
int bcount = 10; // Amount of shots     
int score = 0;  //Score counter
int rad = 90; // Width of the shape
int blreset = 320;  //Ball Reset
int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom


//BOOLEANS
boolean gameover = false;


//SETTING WINDOW SIZE & FACTORS
void setup () {
size (400, 400);
noFill();
noStroke();
frameRate(60);
rectMode(RADIUS);
ellipseMode(RADIUS);  
//SETTING START POSITION 
  xpos = width/2;
  ypos = height/2;  
}

//DRAW SCENE
void draw () { 
  if (gameover == false) {
   xpos = xpos + ( xspeed * xdirection ); //Setting boundaries for Hoop Movement
     if (xpos > width-rad || xpos < rad) {
        xdirection *= -1;
}
//BACKGROUND WALL & SHADOW   
noStroke(); 
  fill (238,182,90);
    rect (0,0,width, height);
      stroke(231,232,170);
        strokeWeight(3);
line (0,100,400,100);
          
//COURT LINES
stroke(59,38,37);
line (130,30,270,30);
    strokeWeight(2);
line (110,50,290,50);
    strokeWeight(3);
line (90,70,310,70);
    strokeWeight(4);
line (60,100,330,100);
    strokeWeight(5);
line (20,140,370,140);

//WALL SHADOW
noStroke();
   fill(170,121,76);
rect(0,0,width,20);
    fill(92,58,39);
rect(0,10,width,10);
    fill(213,146,74,100);
rect(0,20,width,40);
rect(0,20,width,30);
rect(0,20,width,20);
rect(0,20,width,10);

//COURT CENTRE SQUARE
   fill (219,102,55);
   stroke(59,38,37);
   strokeWeight(5);
quad (150,20,80,200,320,200,250,20);
//SHADOW SQUARE
noStroke();
    fill(181,55,23,45);
quad (155,23,155,120,245,120,245,23);

//COURT FRONT CURVE
noFill();
    stroke(59,38,37);
      strokeWeight(5);
arc(200,200, 240, 175, 0, PI);
arc(200,200, 240/2, 175, 0, PI); 
 
//3 POINTER LINE  
noFill();
    stroke(59,38,37);
      strokeWeight(10);
arc (200,350, width,10,0,PI);  

//SPOTLIGHTS
noStroke();
  fill (random(255),100,50,150);
    ellipseMode(CENTER); // reseting ellipse mode
    
ellipse (40,80,40,20); //left-outer spotlight ring
ellipse (40,80,20,10); //left-middle spotlight ring
ellipse (40,80,10,5); //left-inner spotlight ring

ellipse (360,80,40,20); //right-outer spotlight ring
ellipse (360,80,20,10); //right-middle spotlight ring
ellipse (360,80,10,5); //right-inner spotlight ring

//SPOTLIGHT RADIUS EFFECT
for (int i = 0; i < 400; i = i+5) {
noFill();
  strokeWeight(1);
   stroke(255,255,255,80);
line(i, 320, 40, 80);
line(i, 320, 360, 80);
}

//REMAINING SHOTS (HUD)
noStroke();
fill(220,110,20);
ellipse (10,5, 10,10);
ellipse (30,5, 10,10);
ellipse (50,5, 10,10);
ellipse (70,5, 10,10);
ellipse (90,5, 10,10);
ellipse (110,5, 10,10);
ellipse (130,5, 10,10);
ellipse (150,5, 10,10);
ellipse (170,5, 10,10);
ellipse (190,5, 10,10);

//DRAW BACBOARD & HOOP
//BACKBOARD
fill(255);
  noStroke();
    fill(162,162,162,220);
rect (xpos,(ypos -145), 60, 45);
    fill(234,216,194);
rect(xpos,(ypos -145),50,35);
  noStroke();
    fill(111,107,112);
rect(xpos,(ypos-105), 10, 24);
rect((xpos -60),(ypos -125),5,25);
rect((xpos +60),(ypos -125),5,25);
    fill(196,199,203);
ellipse((xpos -45),(ypos -180),10,10);
ellipse((xpos +45),(ypos -180),10,10);
 
  
//HOOP
noStroke();
fill(202,226,205,185);
quad((xpos -45),(ypos -105),(xpos -35),(ypos -20),(xpos +35),(ypos -20),(xpos +45),(ypos -105));
  fill(198,79,79);
ellipse(xpos, (ypos -107), rad,10);
  fill(219,102,55);
ellipse(xpos, (ypos -110), rad,10);
  
//BALL  
fill(220,110,20); 
ellipse(mouseX,blposY,45,45);
  stroke(0);
  strokeWeight(1.5);
line ((mouseX -10),(blposY -19),(mouseX -10),(blposY +19));
line ((mouseX+10),(blposY -19),(mouseX +10),(blposY +19));
 
//HANDS 
noStroke();  
  fill(117,84,58);
rect ((mouseX -27),blreset,5,15);
rect ((mouseX +27),blreset,5,15);   
  fill(95,71,56);  
rect (mouseX+22,blreset-15,10,3);  
rect (mouseX-22,blreset-15,10,3);    
  fill(130,84,58);
rect (mouseX+20,blreset-10,10,3);
rect (mouseX-20,blreset-10,10,3);

//BALL THROW FUCNTION  
if (mousePressed == true) { //activate on mouse click
  blposY = (blposY - thr); //subtracts positional values to launch the ball
    } 
  
//BALL SCORING SYSTEM  
if (blposY < blreset) { //compares balls current position to ball reset value
   blposY = blposY + gravity; //adds gravity value to balls position until its equal to ball reset value
 }
if (blposY > ((ypos -107))-2.5 && blposY < (ypos -107)+2.5 && mouseX > (xpos -45)+3.0 && mouseX >(xpos -45) -3.0) { //adds points if you make the shot
 score = score +3;
 println ("Your current score is :");
 println (score); 
 }
   
 //BALL COUNTER SYSTEM
if (blposY < blreset -20 && blposY > blreset -30) { //check to see if the ball has been tossed
 bcount = bcount-1;   
}

if (bcount < 10) {
noStroke();
  fill(183,124,74);
ellipse (10,5, 10,10);
}

if (bcount < 9) {
noStroke();
  fill(183,124,74);
ellipse (30,5, 10,10);
}

if (bcount < 8) {
noStroke();
  fill(183,124,74);
ellipse (50,5, 10,10);
}

if (bcount < 7) {
noStroke();
  fill(183,124,74);
ellipse (70,5, 10,10);
}

if (bcount < 6) {
noStroke();
  fill(183,124,74);
ellipse (90,5, 10,10);
}

if (bcount < 5) {
noStroke();
  fill(183,124,74);
ellipse (110,5, 10,10);

}
if (bcount < 4) {
noStroke();
  fill(183,124,74);
ellipse (130,5, 10,10);

}

if (bcount < 3) {
noStroke();
  fill(183,124,74);
ellipse (150,5, 10,10);

}

if (bcount < 2) {
noStroke();
  fill(183,124,74);
ellipse (170,5, 10,10);

}

if (bcount < 1) {
noStroke();
  fill(183,124,74);
ellipse (190,5, 10,10);

gameover = true; // Draws game over screen
println ("GAMEOVER");
println ("FINAL SCORE");
println (score);
  }
  
// LOSE STATE FUNCTION  
} else { 
 noStroke();
 fill (210,92,58);
 rect (0,0, width, height); 
  } 
}
//GAME OVER