I'm trying to make a basketball Catcher game(// this is for code.org). I need help ASAP

I'm trying to make a basketball Catcher game(// this is for code.org). I need help ASAP
0.0 0

#1
var gameReset;
var score;
var lives;
var level;
var balls = [];
var num = 1;
var frames = 0;
var xSpeed;
var ySpeed;
var ballX;
var ballY;
var hoopSpeed;
var hoopX;
var hoopY = 350;
var hoopWidth = getXPosition("hoop") ;
var hoopHeight = getYPosition("hoop");
var slideLeft;
var slideRight;

onEvent("startButton", "click", function(event) {
 setScreen("game");
 score = 0;
 lives = 3;
 level = 1;
 reset();
 timedLoop(1000/60, function(){
     update();
     moveHoop();
     catchBall();
     if(frames % 100 === 0){
     addBall();
     }
     ballsDrop();
     frames++;
  });
});

function ballsDrop(){}
for (var i = 0; i < balls.length; i++){
  var ballsX = getXPosition(balls[i]);
  var ballsY = getYPosition(balls[i]);
  setPosition(balls[i], ballsX, ballsY + 3);
if(getYPosition(balls[i]) >= 209){
  if(catchBall(balls[i])) {
score ++;
    }else{
      score --;
    }
  }
}

onEvent("game", "keydown", function(event) {
  if (event.key == "Left") {slideLeft = true;}
  if (event.key == "Right") {
    slideRight = true;
  }
});
onEvent("game", "keyup", function(event) {
  if (event.key == "Left") {
    slideLeft = false;
  } else if ((event.key == "Right")) {
    slideRight = false;
  }
});
onEvent("game", "keypress", function(event) {
  if (event.key ==" " && gameReset ) {
    start();
  }
});
function update() {
  moveHoop();
  ballX += xSpeed;
  ballY += ySpeed;
  hoopX += hoopSpeed;
       //moves everything around on the screen
  setText("score", score);
  setText("lives", lives);
  setText("level", level);
  setPosition("ball", ballX, ballY);
  setPosition("hoop", hoopX, hoopY);
}
function moveHoop() {
  if ((slideLeft && !slideRight) && hoopX > 0) {
    hoopSpeed = -5;
  } else if (((slideRight && !slideLeft) && hoopX + hoopWidth < 220)) {
    hoopSpeed = 5;
  } else {
    hoopSpeed = 0;
  }
}
function catchBall(ball) {
  
}
function addBall(){
  var id = "ball" + num;
  balls.push(id);
  num++;
  
  image(id,"basketball.png");
  setPosition("ball",randomNumber(18,290), 63,60);
}
function reset() {
  xSpeed = 0;
  ySpeed = 0;
  hoopSpeed = 0;
  slideLeft = false;
  slideRight = false;
  gameReset = true;
  ballX = randomNumber(20, 315);
  ballY = 40;
  hoopX = 105;
  showElement("directions");
  if (score == -1) {
    end();
  }
}
onEvent("restart", "click", function() {
  reset();
});
function start() {
  while (xSpeed === 0) {
    xSpeed = 1;
  }
  ySpeed = randomNumber(3, 7);
  gameReset = false;
}
function end() {
  stopTimedLoop();
  setScreen("End");
  setText("endScoreLabel", score);
  num = 0;
}

#2

Im also new to this site lol


#3

Hey,

What is you problem exactly ?
Can you Preformatte your code ? (you can find the quotes clicking on ‘</>’ when you edit post :slight_smile:

Thanks


#5

did I do it correctly?

for the app/game the balls aren’t spawning properly. they come at huge sizes and do not fall as I programmed them to.


#6

Might want to tag someone who has a lot of coding or game experience by using @


#7

Hey,

Sorry I don’t know what’s wrong,
I don’t have this level yet


#8

OK, I’m not sure how this one sneaked passed me - I usually keep an eye out for JS examples.

But this isn’t going to work without the HTML and probably CSS. Can we see those?

And tell us exactly what it is or isn’t doing that isn’t the problem.