xxxxxxxxxx
103
var screen = 0;
var y = -20;
var x = 200;
var speed = 2;
var score = 0;
var fish;
var shark;
var sea;
var jaws;
function preload() {
soundFormats("mp3", "ogg");
fish = loadImage("fish2.png");
shark = loadImage("tree.jpg");
sea = loadImage("images.jfif");
jaws = loadSound("jaws.mp3");
chomp = loadSound("chomp.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 MY CATCHING 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("score = " + 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 += 0.5;
score += 1;
chomp.play();
}
if (y == -20) {
pickRandom();
}
}
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 mousePressed() {
if (screen == 0) {
screen = 1;
jaws.loop();
jaws.play();
} else if (screen == 2) {
screen = 0;
}
}
function reset() {
score = 0;
speed = 2;
y = -20;
}