xxxxxxxxxx
87
//a game where you are suppose to catch the ball with the rectangle
let x = 150
let y = 30
let startScreen = true
let score = 0
let velocity = 2
let ScreenStart = 0
let backDrop = 0
let speed = 1
let isgameOver = false
let isgameWon = false
function setup(){
createCanvas (700,500)
}
function draw (){
if (isgameOver){
gameOver()
return
}
background ('skyblue')
if (startScreen) {
Screen()
return
}
startGame()
}
function Screen() {
if (mouseIsPressed === true) {
startScreen = false;
}
if (startScreen === true) {
fill("red");
textAlign(CENTER)
textSize(20)
text("Click the Mouse to Begin", width / 2, height / 2);
}
}
function startGame (){
text("score= " + score,40,20)
circle(x,y,30)
rect(mouseX,height - 30,68,50)
y+=velocity;
if (y>500&&(x>=mouseX&&x<=mouseX+68)){
x= random(0,700)
y=0
score += 1
if (score === 7) {
background ("black")
isgameOver= true
isgameWon = true
}
} else if(y>500){
x= random(0,700)
y=0
isgameOver = true
}
if (score >= 2 ){
velocity = 3;
}
}
function gameOver (){
if (isgameWon){
gameWin()
}
else {
text("You Lose", width / 2, height / 2)
}
}
function gameWin(){
text ("Game Over, You Win", width / 2, height / 2)
}