xxxxxxxxxx
var spongebobimage;
var sand;
var backgroundimg;
var gameover;
var isgameover;
var shell;
var yspeed;
var changey;
var xspeed, xspeed2, yspeed2;
var changey2, changex, changex2;
function preload() {
spongebobimage = loadImage('spongebob.png');
backgroundimg = loadImage('background.jpg');
shell = loadImage('shellimg.png');
sand = loadImage('sand.png');
gameover = loadImage('gameover.jpg');
}
function setup() {
createCanvas(windowWidth, windowHeight);
yspeed = 10;
changey = 400;
yspeed2 = 5;
xspeed = 5;
xspeed2 = -10;
changex = 60;
changey2 = 100;
changex2 = 900;
}
function draw() {
background(backgroundimg);
changey = changey + yspeed;
changey2 = changey2 + yspeed2;
changex = changex + xspeed;
changex2 = changex2 +xspeed2;
if(changex > 1185 || changex < 0) {
xspeed *= -1;
}
if(changey2 > windowHeight || changey2 < 70) {
yspeed2 *= -1;
}
image(sand, -50, 500, 5000, 500);
image(spongebobimage, 200,changey,50,100);
image(shell, changex2, 450,100,50);
if (changex2 == 200){
if (changey == 410)
{
isgameover = true;
}
}
if(changex2 < 0) {
changex2 = 2000;
}
if(changey > 405) {
yspeed = 0;
} else if(changey < 200) {
yspeed = 8;
}
if (isgameover == true)
{
background(0);
image(gameover, 0, 0, windowWidth, windowHeight);
}
}
function keyPressed() {
if(key == ' ') {
yspeed = -8;
}
}