xxxxxxxxxx
112
var screen = 0;
var y=-20;
var x=200;
var speed = 2;
var score= 0;
var fish;
var shark;
var sea;
var jaws;
var sharksize;
function preload() {
soundFormats('mp3', 'ogg');
fish = loadImage('Water_Droplet_Pin.png');
shark = loadImage('Picture1.png');
sea = loadImage('grassland.jpeg');
jaws = loadSound('mixkit-light-rain-loop-2393.wav');
}
function setup() {
createCanvas(600, 400);
jaws.play();
}
function draw() {
if(screen == 0){
startScreen()
}else if(screen == 1){
gameOn()
}else if(screen==2){
endScreen()
}
}
function startScreen(){
jaws.pause();
background(96, 157, 255)
image(sea,0,0,600,500)
fill(255)
textAlign(CENTER);
textSize(25)
text('WELCOME TO OUR AWARENESS GAME!', width / 2, height / 2)
text('click to start', width / 2, height / 2 + 30);
reset();
}
function gameOn(){
imageMode(CENTER);
// jaws.setVolume(0.1);
image(sea,width/2,height/2,600,500)
textSize(15)
text("growth = " + score, 50,20)
rectMode(CENTER)
// rect(mouseX,height-10,50,30)
image(shark,mouseX,height-50,70,100)
// ellipse(x,y,20,20)
image(fish,x,y,60,50)
y+= speed;
if(y>height){
screen =2
jaws.stop();
}
if(y>height-50 && x>mouseX-35 && x<mouseX+35){
y=-20
speed+=.5
score+= 1
}
if(y==-20){
pickRandom();x
}
}
function pickRandom(){
x= random(20,width-20)
}
function endScreen(){
background(150)
textAlign(CENTER);
text('GAME OVER', width / 2, height / 2)
text("SCORE = " + score, width / 2, height / 2 + 20)
text('click to play again', width / 2, height / 2 + 40);
}
function winScreen(){
background(255)
textAlign(CENTER);
text('Hurray!!!, You Won', width / 2, height / 2)
text('click to play again', width / 2, height / 2 + 40);
}
function mousePressed(){
if(screen==0){
screen=1
jaws.loop();
}else if(screen==2){
screen=0
}
}
function reset(){
score=0;
speed=2;
y=-20;
}