How to fix my scoring code and how to input a game over feature/screen when the ball hit the ground?

Just fixed the ball glitch for your character now your other problem is your game crash when the ball collides with the box. Sorry for the auto correction.

int xPos; //position
int yPos;

int gravity = 1; //gravity
int speedX = 3; //speed
int speedY; //speed

int friction = 1; //friction
int ballRadius = 25; //ball radius

int hatX; //hat collision
int hatY = 390; //hat collision
int hatW = 150; //hat collision
int hatH = 4; //hat collision

boolean collide;
int score;

int basketH;
int basketW;
int basketX;
int basketY;
boolean hide;
boolean hitFloor;


void setup() {
  size(640, 480); //game size
  ballRadius = 25;
  basketX = 500;
  basketY = 100;
  basketW = 100;
  basketH = 150;
  hide = false;
  hitFloor = false;
  score = 0;
}

void draw() {
  
  ballHitsHat();
  if( ballHitsBasket() ){
    hide = true;
    xPos = - 100;
    yPos = - 100;
  }
  if (!hide) { 
    updateBall(); //update the ball movement
    checkBall(); //checking ball movement
    drawBill(); //draw Bill
    drawBall(); //draw ball
  }
  drawScore();
  drawBasket();
  gameOver();
}

void updateBall() {
//ball speed
  speedY += gravity;
  
  xPos += speedX;
  yPos += speedY;
}

boolean ballHitsBasket() {
  // ball and basket collision detection
  if (xPos + ballRadius >= basketX && xPos <= basketX + basketW &&
    yPos + ballRadius >= basketY && yPos <= basketY + basketH) {
      score++;
    return true;
  }
  return false;
}

boolean ballHitsHat() {
  // ball and hat collision detection
  if (yPos + ballRadius > hatY && xPos + ballRadius > hatX && xPos 
  + ballRadius < hatX + hatW) {
    return true;
  }
  return false;
}

void checkBall() {

  if (ballHitsHat()) { //ball bouncing losing gravity
    yPos = hatY - ballRadius;
    speedY *= -1; 
  }
  
  if (xPos > width - ballRadius) {//ball speed and collision
    if (speedX > 0) speedX *= -1;
  } else if (xPos < ballRadius) {
    if (speedX < 0) speedX *= -1;
  }

  if (yPos > height - ballRadius - 34) {//ball speed and collision
    yPos = height - ballRadius - 34;
    speedY *= -friction;
  }
}

void drawBall() {//ball
  
  fill(180);
  stroke(0);
  ellipse(xPos, yPos, ballRadius*2, ballRadius*2);
}

void drawBill() {
  
  hatX = mouseX - 45;//bouncing hat
  background(44, 56, 245);//sky
  fill(2, 188, 34);
  noStroke();
  rect(0, 420, width, height);//grass

  fill(255, 224, 189);
  rect(mouseX, 400, 60, 50);//head

  fill(210, 105, 30);
  rect(mouseX+10, 420, 15, 5);  //left eye

  rect(mouseX+35, 420, 15, 5);  //right eye

  fill(0);
  ellipse(mouseX+30, 436, 10, 2); //mouth 

  fill(0);
  rect(mouseX-15, 390, 90, 10); //hat
  
  fill(165, 42, 42);
  rect(mouseX-3, 400, 65, 10); //hair


  fill(255, 0, 0);
  rect(mouseX+10, 450, 40, 20); //body

  fill(0);
  rect(mouseX+20, 470, 5, 10); //left leg
  rect(mouseX+35, 470, 5, 10); //right leg
}
void drawScore() {
  fill(255, 255, 0); 
  textSize(12);
  text("Score: "+score, 10, 50); //display the score
}
void drawBasket() {
  fill(165, 42, 42);//basket
  noStroke();
  rect(basketX, basketY, basketW, basketH);
}
void gameOver() {
  if (hitFloor) {
    fill(0, 255, 0);
    textSize(14);
    text("GAME OVER", width/2, 50); //display the score
  }
}

Thanks for the help Robin. But still the ball make the game crash when it hit the basket and also how to fix the basket by putting it on the ground and also how to make another screen by just saying game over. And press the mouse to activate the game again. One last request is by spawning 5 balls and bounced them to the basket and make them into a loop. Also
The initial x-velocity of each pudding must be a random number between 1.15 and 1.2
The initial y-velocity of each pudding must be a random number between 0.2 and 1.2
I wonder how to put in those?

int xPos; //position
int yPos;

int gravity = 1; //gravity
int speedX = 3; //speed
int speedY; //speed

int friction = 1; //friction
int ballRadius = 25; //ball radius

int hatX; //hat collision
int hatY = 390; //hat collision
int hatW = 150; //hat collision
int hatH = 4; //hat collision

boolean collide;
int score;

int basketH;
int basketW;
int basketX;
int basketY;
boolean hide;
boolean hitFloor;


void setup() {
  size(640, 480); //game size
  ballRadius = 25;
  basketX = 500;
  basketY = 100;
  basketW = 100;
  basketH = 150;
  hide = false;
  hitFloor = false;
  score = 0;
}

void draw() {
  
  ballHitsHat();
  if( ballHitsBasket() ){
    hide = true;
    xPos = - 100;
    yPos = - 100;
  }
  if (!hide) { 
    updateBall(); //update the ball movement
    checkBall(); //checking ball movement
    drawBill(); //draw Bill
    drawBall(); //draw ball
  }
  drawScore();
  drawBasket();
  gameOver();
}

void updateBall() {
//ball speed
  speedY += gravity;
  
  xPos += speedX;
  yPos += speedY;
}

boolean ballHitsBasket() {
  // ball and basket collision detection
  if (xPos + ballRadius >= basketX && xPos <= basketX + basketW &&
    yPos + ballRadius >= basketY && yPos <= basketY + basketH) {
      score++;
    return true;
  }
  return false;
}

boolean ballHitsHat() {
  // ball and hat collision detection
  if (yPos + ballRadius > hatY && xPos + ballRadius > hatX && xPos 
  + ballRadius < hatX + hatW) {
    return true;
  }
  return false;
}

void checkBall() {

  if (ballHitsHat()) { //ball bouncing losing gravity
    yPos = hatY - ballRadius;
    speedY *= -1; 
  }
  
  if (xPos > width - ballRadius) {//ball speed and collision
    if (speedX > 0) speedX *= -1;
  } else if (xPos < ballRadius) {
    if (speedX < 0) speedX *= -1;
  }

  if (yPos > height - ballRadius - 34) {//ball speed and collision
    yPos = height - ballRadius - 34;
    speedY *= -friction;
  }
}

void drawBall() {//ball
  
  fill(180);
  stroke(0);
  ellipse(xPos, yPos, ballRadius*2, ballRadius*2);
}

void drawBill() {
  
  hatX = mouseX - 45;//bouncing hat
  background(44, 56, 245);//sky
  fill(2, 188, 34);
  noStroke();
  rect(0, 420, width, height);//grass

  fill(255, 224, 189);
  rect(mouseX, 400, 60, 50);//head

  fill(210, 105, 30);
  rect(mouseX+10, 420, 15, 5);  //left eye

  rect(mouseX+35, 420, 15, 5);  //right eye

  fill(0);
  ellipse(mouseX+30, 436, 10, 2); //mouth 

  fill(0);
  rect(mouseX-15, 390, 90, 10); //hat
  
  fill(165, 42, 42);
  rect(mouseX-3, 400, 65, 10); //hair


  fill(255, 0, 0);
  rect(mouseX+10, 450, 40, 20); //body

  fill(0);
  rect(mouseX+20, 470, 5, 10); //left leg
  rect(mouseX+35, 470, 5, 10); //right leg
}
void drawScore() {
  fill(255, 255, 0); 
  textSize(12);
  text("Score: "+score, 10, 50); //display the score
}
void drawBasket() {
  fill(165, 42, 42);//basket
  noStroke();
  rect(basketX, basketY, basketW, basketH);
}
void gameOver() {
  if (hitFloor) {
    fill(0, 255, 0);
    textSize(14);
    text("GAME OVER", width/2, 50); //display the score
  }
}

Just eliminated the problem but having another problem is the collision with the basket. The ball make the game crash when it hit the basket and also how to fix the basket by putting it on the ground and also how to make another screen by just saying game over. And press the mouse to activate the game again. One last request is by spawning 5 balls and bounced them to the basket and make them into a loop. Also
The initial x-velocity of each balls must be a random number between 1.15 and 1.2
The initial y-velocity of each balls must be a random number between 0.2 and 1.2
I wonder how to put in those?

int xPos; //position
int yPos;

int gravity = 1; //gravity
int speedX = 3; //speed
int speedY; //speed

int friction = 1; //friction
int ballRadius = 25; //ball radius

int hatX; //hat collision
int hatY = 390; //hat collision
int hatW = 150; //hat collision
int hatH = 4; //hat collision

boolean collide;
int score;

int basketH;
int basketW;
int basketX;
int basketY;
boolean hide;
boolean hitFloor;


void setup() {
  size(640, 480); //game size
  ballRadius = 25;
  basketX = 500;
  basketY = 100;
  basketW = 100;
  basketH = 150;
  hide = false;
  hitFloor = false;
  score = 0;
}

void draw() {
  
  ballHitsHat();
  if( ballHitsBasket() ){
    hide = true;
    xPos = - 100;
    yPos = - 100;
  }
  if (!hide) { 
    updateBall(); //update the ball movement
    checkBall(); //checking ball movement
    drawBill(); //draw Bill
    drawBall(); //draw ball
  }
  drawScore();
  drawBasket();
  gameOver();
}

void updateBall() {
//ball speed
  speedY += gravity;
  
  xPos += speedX;
  yPos += speedY;
}

boolean ballHitsBasket() {
  // ball and basket collision detection
  if (xPos + ballRadius >= basketX && xPos <= basketX + basketW &&
    yPos + ballRadius >= basketY && yPos <= basketY + basketH) {
      score++;
    return true;
  }
  return false;
}

boolean ballHitsHat() {
  // ball and hat collision detection
  if (yPos + ballRadius > hatY && xPos + ballRadius > hatX && xPos 
  + ballRadius < hatX + hatW) {
    return true;
  }
  return false;
}

void checkBall() {

  if (ballHitsHat()) { //ball bouncing losing gravity
    yPos = hatY - ballRadius;
    speedY *= -1; 
  }
  
  if (xPos > width - ballRadius) {//ball speed and collision
    if (speedX > 0) speedX *= -1;
  } else if (xPos < ballRadius) {
    if (speedX < 0) speedX *= -1;
  }

  if (yPos > height - ballRadius - 34) {//ball speed and collision
    yPos = height - ballRadius - 34;
    speedY *= -friction;
  }
}

void drawBall() {//ball
  
  fill(180);
  stroke(0);
  ellipse(xPos, yPos, ballRadius*2, ballRadius*2);
}

void drawBill() {
  
  hatX = mouseX - 45;//bouncing hat
  background(44, 56, 245);//sky
  fill(2, 188, 34);
  noStroke();
  rect(0, 420, width, height);//grass

  fill(255, 224, 189);
  rect(mouseX, 400, 60, 50);//head

  fill(210, 105, 30);
  rect(mouseX+10, 420, 15, 5);  //left eye

  rect(mouseX+35, 420, 15, 5);  //right eye

  fill(0);
  ellipse(mouseX+30, 436, 10, 2); //mouth 

  fill(0);
  rect(mouseX-15, 390, 90, 10); //hat
  
  fill(165, 42, 42);
  rect(mouseX-3, 400, 65, 10); //hair


  fill(255, 0, 0);
  rect(mouseX+10, 450, 40, 20); //body

  fill(0);
  rect(mouseX+20, 470, 5, 10); //left leg
  rect(mouseX+35, 470, 5, 10); //right leg
}
void drawScore() {
  fill(255, 255, 0); 
  textSize(12);
  text("Score: "+score, 10, 50); //display the score
}
void drawBasket() {
  fill(165, 42, 42);//basket
  noStroke();
  rect(basketX, basketY, basketW, basketH);
}
void gameOver() {
  if (hitFloor) {
    fill(0, 255, 0);
    textSize(14);
    text("GAME OVER", width/2, 50); //display the score
  }
}

Just eliminated the problem but having another problem is the collision with the basket. The ball make the game crash when it hit the basket and also how to fix the basket by putting it on the ground and also how to make another screen by just saying game over. And press the mouse to activate the game again. One last request is by spawning 5 balls and bounced them to the basket and make them into a loop. Also
The initial x-velocity of each ball must be a random number between 1.15 and 1.2
The initial y-velocity of each ball must be a random number between 0.2 and 1.2
I wonder how to put in those?

int xPos; //position
int yPos;

int gravity = 1; //gravity
int speedX = 3; //speed
int speedY; //speed

int friction = 1; //friction
int ballRadius = 25; //ball radius

int hatX; //hat collision
int hatY = 390; //hat collision
int hatW = 150; //hat collision
int hatH = 4; //hat collision

boolean collide;
int score;

int basketH;
int basketW;
int basketX;
int basketY;
boolean hide;
boolean hitFloor;


void setup() {
  size(640, 480); //game size
  ballRadius = 25;
  basketX = 500;
  basketY = 100;
  basketW = 100;
  basketH = 150;
  hide = false;
  hitFloor = false;
  score = 0;
}

void draw() {
  
  ballHitsHat();
  if( ballHitsBasket() ){
    hide = true;
    xPos = - 100;
    yPos = - 100;
  }
  if (!hide) { 
    updateBall(); //update the ball movement
    checkBall(); //checking ball movement
    drawBill(); //draw Bill
    drawBall(); //draw ball
  }
  drawScore();
  drawBasket();
  gameOver();
}

void updateBall() {
//ball speed
  speedY += gravity;
  
  xPos += speedX;
  yPos += speedY;
}

boolean ballHitsBasket() {
  // ball and basket collision detection
  if (xPos + ballRadius >= basketX && xPos <= basketX + basketW &&
    yPos + ballRadius >= basketY && yPos <= basketY + basketH) {
      score++;
    return true;
  }
  return false;
}

boolean ballHitsHat() {
  // ball and hat collision detection
  if (yPos + ballRadius > hatY && xPos + ballRadius > hatX && xPos 
  + ballRadius < hatX + hatW) {
    return true;
  }
  return false;
}

void checkBall() {

  if (ballHitsHat()) { //ball bouncing losing gravity
    yPos = hatY - ballRadius;
    speedY *= -1; 
  }
  
  if (xPos > width - ballRadius) {//ball speed and collision
    if (speedX > 0) speedX *= -1;
  } else if (xPos < ballRadius) {
    if (speedX < 0) speedX *= -1;
  }

  if (yPos > height - ballRadius - 34) {//ball speed and collision
    yPos = height - ballRadius - 34;
    speedY *= -friction;
  }
}

void drawBall() {//ball
  
  fill(180);
  stroke(0);
  ellipse(xPos, yPos, ballRadius*2, ballRadius*2);
}

void drawBill() {
  
  hatX = mouseX - 45;//bouncing hat
  background(44, 56, 245);//sky
  fill(2, 188, 34);
  noStroke();
  rect(0, 420, width, height);//grass

  fill(255, 224, 189);
  rect(mouseX, 400, 60, 50);//head

  fill(210, 105, 30);
  rect(mouseX+10, 420, 15, 5);  //left eye

  rect(mouseX+35, 420, 15, 5);  //right eye

  fill(0);
  ellipse(mouseX+30, 436, 10, 2); //mouth 

  fill(0);
  rect(mouseX-15, 390, 90, 10); //hat
  
  fill(165, 42, 42);
  rect(mouseX-3, 400, 65, 10); //hair


  fill(255, 0, 0);
  rect(mouseX+10, 450, 40, 20); //body

  fill(0);
  rect(mouseX+20, 470, 5, 10); //left leg
  rect(mouseX+35, 470, 5, 10); //right leg
}
void drawScore() {
  fill(255, 255, 0); 
  textSize(12);
  text("Score: "+score, 10, 50); //display the score
}
void drawBasket() {
  fill(165, 42, 42);//basket
  noStroke();
  rect(basketX, basketY, basketW, basketH);
}
void gameOver() {
  if (hitFloor) {
    fill(0, 255, 0);
    textSize(14);
    text("GAME OVER", width/2, 50); //display the score
  }
}
1 Like

It would be better when you find your own solution

People should not post full sketches but give advice and snippets instead

I think we are now in a situation where you don’t fully understand your program anymore because other people wrote so much in it…

Please read the sketch carefully and find solutions instead for asking for them

As for the different screens, like the game over screen :

Make a global variable int state that says on what screen you are. Each screen has a number like 0 for welcome screen, 1 for game screen etc.

In draw evaluate state with switch () or if(state==0) {…} else if…

and in each section draw the according screen

Nothing is allowed in draw() outside this if…else if… section

In keypressed and mousePressed also make such a section (nothing outside of it in each function allowed) and make the checking of key and mouse appropriate to state

Get familiar with your own program again please…

I just came up with an idea of instead of switching screen why not make a drawing or display showing the word game over instead of making another screen. As I’ve used
void mousePressed(){ setup(); }
this code make me restart the game and the game over text disappeared.

Good idea

Please proceed

Sorry to disappoint you by not make a drawing or display showing the word game over instead of making another screen. But I’ve manage to fix the crashing glitch by changing the

ballHitsHat();
  if( ballHitsBasket() ){
    hide = false;//I've change this from true to false and the ball re spawn on it correct direction but the ball respawn a bit to high
    xPos = - 100;
    yPos = - 100;
1 Like

I put in the hide as you asked when the ball hits the basket it disappears and after the ball disappears it position is set to xPos = -100 and yPos = - 100 which means it will stay up there. If you have set the hide condition to false that means the ball won’t go invisible anymore but will only now have it’s xPos = -100 and yPos = -100 set to that and it iwlll start falling from there. You can remove those to get rid of the unfavorable behavior.

fixing scoring, and ‘click to respawn’

int xPos; //position
int yPos;

int gravity = 1; //gravity
int speedX = 3; //speed
int speedY; //speed

int friction = 1; //friction
int ballRadius = 25; //ball radius

int hatX; //hat collision
int hatY = 390; //hat collision
int hatW = 150; //hat collision
int hatH = 4; //hat collision

boolean collide;
int score;

int basketH;
int basketW;
int basketX;
int basketY;
boolean hide;
boolean hitFloor;
float py;

void setup() {
  size(640, 480); //game size
  py = yPos - ballRadius;
  ballRadius = 25;
  basketX = 500;
  basketY = 100;
  basketW = 100;
  basketH = 150;
  hide = false;
  hitFloor = false;
  score = 0;
}

void draw() {
  background(0);
  ballHitsHat();
  ballHitsBasket();

  if (!hide) {
    updateBall(); //update the ball movement
    checkBall(); //checking ball movement
  }
  drawBill(); //draw Bill
  drawBall(); //draw ball
  drawScore();
  drawBasket();
  gameOver();
}

void mousePressed() {
  if (hide) {
    respawn();
  }
}

void respawn() {
  hide = false;
  score = 0;
  xPos = 0;
  yPos = 0;
  speedX = 3;
  speedY = 0;
  hitFloor = false;
}

void updateBall() {
  //ball speed
  py = yPos;
  speedY += gravity;

  xPos += speedX;
  yPos += speedY;
}

boolean scoring = false;
void ballHitsBasket() {
  // ball and basket collision detection
  if (!scoring) {
    if (xPos > basketX && yPos > basketY && xPos < basketX + basketW && yPos < basketY + basketH) {
      scoring = true;
    }
  } else {
    if (yPos - ballRadius > basketY + basketH) {
      scoring = false;
      score++;
    }
  }
}

boolean ballHitsHat() {
  // ball and hat collision detection
  if (yPos + ballRadius > hatY && xPos + ballRadius > hatX && xPos 
    + ballRadius < hatX + hatW) {
    return true;
  }
  return false;
}

void checkBall() {

  if (ballHitsHat()) { //ball bouncing losing gravity
    yPos = hatY - ballRadius;
    speedY *= -1;
  }

  if (xPos > width - ballRadius) {//ball speed and collision
    if (speedX > 0) speedX *= -1;
  } else if (xPos < ballRadius) {
    if (speedX < 0) speedX *= -1;
  }

  if (yPos > height - ballRadius - 34) {//ball speed and collision
    yPos = height - ballRadius - 34;
    hitFloor = true;
    hide = true;
    speedY *= -friction;
  }
}

void drawBall() {//ball

  fill(180);
  stroke(0);
  ellipse(xPos, yPos, ballRadius*2, ballRadius*2);
}

void drawBill() {

  hatX = mouseX - 45;//bouncing hat
  background(44, 56, 245);//sky
  fill(2, 188, 34);
  noStroke();
  rect(0, 420, width, height);//grass

  fill(255, 224, 189);
  rect(mouseX, 400, 60, 50);//head

  fill(210, 105, 30);
  rect(mouseX+10, 420, 15, 5);  //left eye

  rect(mouseX+35, 420, 15, 5);  //right eye

  fill(0);
  ellipse(mouseX+30, 436, 10, 2); //mouth 

  fill(0);
  rect(mouseX-15, 390, 90, 10); //hat

  fill(165, 42, 42);
  rect(mouseX-3, 400, 65, 10); //hair


  fill(255, 0, 0);
  rect(mouseX+10, 450, 40, 20); //body

  fill(0);
  rect(mouseX+20, 470, 5, 10); //left leg
  rect(mouseX+35, 470, 5, 10); //right leg
}
void drawScore() {
  fill(255, 255, 0); 
  textSize(12);
  text("Score: "+score, 10, 50); //display the score
}
void drawBasket() {
  fill(165, 42, 42);//basket
  noStroke();
  rect(basketX, basketY, basketW, basketH);
}
void gameOver() {
  if (hitFloor) {
    fill(0, 255, 0);
    textSize(14);
    textAlign(CENTER);
    text("GAME OVER", width/2, 50); //display the score
    text("Click to respawn", width/2, 60); //display the score
    textAlign(LEFT);
  }
}

1 Like

You will need an array of ball object to spawn 5 balls

1 Like

By the way is there another way for the ball to respawn when the ball collide with the box and I’ve don’t want the ball to say game over when it hit the box, I just simply want the game to keep going until the game is over when the ball hit the ground? And when the ball hit the ground, I’ve want to display the whole screen red and it say game over, then after displaying it. Press the mouse then the game restart normally.

Also I’ve has to leave the box at this location as I’ve want to leave it like that instead of leaving the box in the air. When I’ve change the code the ball won’t score when it hit the box. But thanks for the help.

int xPos; //position
int yPos;

int gravity = 1; //gravity
int speedX = 3; //speed
int speedY; //speed

int friction = 1; //friction
int ballRadius = 25; //ball radius

int hatX; //hat collision
int hatY = 390; //hat collision
int hatW = 150; //hat collision
int hatH = 4; //hat collision

boolean collide;
int score;

int basketH;
int basketW;
int basketX;
int basketY;
boolean hide;
boolean hitFloor;
float py;

void setup() {
  size(640, 480); //game size
  py = yPos - ballRadius;
  ballRadius = 25;
  basketX = 500;
  basketY = 350;
  basketW = 200;
  basketH = 400;
  hide = false;
  hitFloor = false;
  score = 0;
}

void draw() {
  background(0);
  ballHitsHat();
  ballHitsBasket();

  if (!hide) {
    updateBall(); //update the ball movement
    checkBall(); //checking ball movement
  }
  drawBill(); //draw Bill
  drawBall(); //draw ball
  drawScore();
  drawBasket();
  gameOver();
}

void mousePressed() {
  if (hide) {
    respawn();
  }
}

void respawn() {
  hide = false;
  score = 0;
  xPos = 0;
  yPos = 0;
  speedX = 3;
  speedY = 0;
  hitFloor = false;
}

void updateBall() {
  //ball speed
  py = yPos;
  speedY += gravity;

  xPos += speedX;
  yPos += speedY;
}

boolean scoring = false;
void ballHitsBasket() {
  // ball and basket collision detection
  if (!scoring) {
    if (xPos > basketX && yPos > basketY && xPos < basketX + basketW && yPos < basketY + basketH) {
      scoring = true;
    }
  } else {
    if (yPos - ballRadius > basketY + basketH) {
      scoring = false;
      score++;
    }
  }
}

boolean ballHitsHat() {
  // ball and hat collision detection
  if (yPos + ballRadius > hatY && xPos + ballRadius > hatX && xPos 
    + ballRadius < hatX + hatW) {
    return true;
  }
  return false;
}

void checkBall() {

  if (ballHitsHat()) { //ball bouncing losing gravity
    yPos = hatY - ballRadius;
    speedY *= -1;
  }

  if (xPos > width - ballRadius) {//ball speed and collision
    if (speedX > 0) speedX *= -1;
  } else if (xPos < ballRadius) {
    if (speedX < 0) speedX *= -1;
  }

  if (yPos > height - ballRadius - 34) {//ball speed and collision
    yPos = height - ballRadius - 34;
    hitFloor = true;
    hide = true;
    speedY *= -friction;
  }
}

void drawBall() {//ball

  fill(180);
  stroke(0);
  ellipse(xPos, yPos, ballRadius*2, ballRadius*2);
}

void drawBill() {

  hatX = mouseX - 45;//bouncing hat
  background(44, 56, 245);//sky
  fill(2, 188, 34);
  noStroke();
  rect(0, 420, width, height);//grass

  fill(255, 224, 189);
  rect(mouseX, 400, 60, 50);//head

  fill(210, 105, 30);
  rect(mouseX+10, 420, 15, 5);  //left eye

  rect(mouseX+35, 420, 15, 5);  //right eye

  fill(0);
  ellipse(mouseX+30, 436, 10, 2); //mouth 

  fill(0);
  rect(mouseX-15, 390, 90, 10); //hat

  fill(165, 42, 42);
  rect(mouseX-3, 400, 65, 10); //hair


  fill(255, 0, 0);
  rect(mouseX+10, 450, 40, 20); //body

  fill(0);
  rect(mouseX+20, 470, 5, 10); //left leg
  rect(mouseX+35, 470, 5, 10); //right leg
}
void drawScore() {
  fill(255, 255, 0); 
  textSize(12);
  text("Score: "+score, 10, 50); //display the score
}
void drawBasket() {
  fill(165, 42, 42);//basket
  noStroke();
  rect(basketX, basketY, basketW, basketH);
}
void gameOver() {
  if (hitFloor) {
    fill(0, 255, 0);
    textSize(14);
    textAlign(CENTER);
    text("GAME OVER", width/2, 50); //display the score
    text("Click to respawn", width/2, 60); //display the score
    textAlign(LEFT);
  }
}


1 Like

Well you should figure it out by looking at the code ! Think about mess around and really understand
how your code is behaving. We can’ t give you all the answers !

1 Like