// Define this if you want the run to return a score://AB.world.getScore = function()//{// return ( 0 ); //};// ----------------------P5 code --------------------var screen =0;var y=-20;var x=200;var speed =1;var score=0;// setting the grid that the game will be played on to be the full height and width of the windowfunction setup(){
createCanvas(windowWidth, windowHeight);}function draw(){// if screen = 0 than run start functionif(screen ==0){
start()// if screen = 1 then run game}elseif(screen ==1){
startGame()// if screen = 2 then run end function}elseif(screen==2){
end()}}function start(){// setting ther background colour for the start screen
background(96,100,200)
fill(255)// making the text appear in the center
textAlign(CENTER);// the text for the beginning of the game
text('Catch All The Snowballs by moving the mouse To Win!!', width /2, height /2)
text('click to start', width /2, height /2+20);
reset();}function startGame(){// setting ther background colour for the game
background(100,0,100)// setting the score board
text("Snowballs caught = "+ score,30,20)
ellipse(x,y,20,20)// setting the white bucket to catch the snowballs, to the center of the screen
rectMode(CENTER)// defining the dimension of the bucket and how to move it with the mouse along the x axis
rect(mouseX,height-10,100,30)
y+= speed;if(y>height){// end game screen appears if you do not catch a snow ball
screen =2}if(y>height-10&& x>mouseX-20&& x<mouseX+20){
y=-20// if snowball caught successfully then we increase the spead of the next falling snowball
speed+=1// and we increase the scoreboard by 1
score+=1}// also if the snowball is caught successfully then the next ball drops from a random locationif(y==-20){
pickRandom();}}// the function for randomly placing where the snowballs will fall fromfunction pickRandom(){
x= random(20,width-20)}function end(){// setting ther background colour for the end screen
background(150)// making the end of game text centered
textAlign(CENTER);
text('GAME OVER', width /2, height /2)// telling the player what their final score was
text("Snowballs Caught = "+ score, width /2, height /2+20)
text('click to play again', width /2, height /2+40);}// mouse functionfunction mousePressed(){// if on the starting screen and mouse is pressed then the game beginsif(screen ==0){
screen=1// if on the ending screen and the mouse is pressed then return to starter screen}elseif(screen==2){
screen=0}}function reset(){// resets the score to o
score=0;// resets the speed to 1
speed=1;
y=-20;}