Thank you for all your help so far!
I am having trouble now with the reload when the game is finished and it returns to screen1.
Upon restarting the game the images do not behave as they did when the game was first played.
var aLoop, bLoop;
var cLoop;
var dLoop;
var eLoop;
var fLoop;
var gLoop;
onEvent(“staetbtn”, “click”, function( ) {
setScreen(“instruct”);
});
onEvent(“startGame”, “click”, function( ) {
setScreen(“screen2”);
});
onEvent(“startGame”, “click”, function( ) {
hideElement(“strawbelle”);
hideElement(“mangio”);
hideElement(“apple”);
hideElement(“boom”);
hideElement(“strawbelle2”);
hideElement(“strawbelle4”);
hideElement(“strawbelle3”);
movestrawbelle();
moveapple();
});
//delay start for strawbelle2
onEvent(“startGame”, “click”, function( ) {
var seconds = 0;
var interval1 = setInterval(function() {
seconds = seconds + 1;
console.log(seconds + " seconds have elapsed");
movestrawbelle2();
clearInterval(interval1);
}, 10000);
});
//delay start for boom
onEvent(“startGame”, “click”, function( ) {
var seconds = 0;
var interval1 = setInterval(function() {
seconds = seconds + 1;
console.log(seconds + " seconds have elapsed");
moveboom();
clearInterval(interval1);
}, 30000);
});
//delay start for mangio
onEvent(“startGame”, “click”, function( ) {
var seconds = 0;
var interval1 = setInterval(function() {
seconds = seconds + 1;
console.log(seconds + " seconds have elapsed");
movemangio();
clearInterval(interval1);
}, 22000);
});
//delay start for strawbelle3
onEvent(“startGame”, “click”, function( ) {
var seconds = 0;
var interval1 = setInterval(function() {
seconds = seconds + 1;
console.log(seconds + " seconds have elapsed");
movestrawbelle3();
clearInterval(interval1);
}, 15000);
});
//delay start for strawbelle4
onEvent(“startGame”, “click”, function( ) {
var seconds = 0;
var interval1 = setInterval(function() {
seconds = seconds + 1;
console.log(seconds + " seconds have elapsed");
movestrawbelle4();
clearInterval(interval1);
}, 25000);
});
//var aLoop = timedLoop;
function moveapple() {
var xPos=randomNumber(0,260);
setPosition(“apple”, xPos, -15);
showElement(“apple”);
aLoop = timedLoop(1000, function() { //added aLoop here
var yPos= getYPosition(“apple”);
setPosition(“apple”, xPos, yPos+5);
if (yPos>400){
stopTimedLoop(aLoop);
hideElement(“apple”);
moveapple();
}
});}
onEvent(“apple”, “click”, function( ) {
stopTimedLoop(aLoop);
hideElement(“apple”);
moveapple();
});
//var bLoop = timedLoop; removed this
function movestrawbelle() {
var xPos=randomNumber(0,300);
setPosition(“strawbelle”, xPos, -15);
showElement(“strawbelle”);
bLoop = timedLoop(1000, function() { //added bLoop here
var yPos= getYPosition(“strawbelle”);
setPosition(“strawbelle”, xPos, yPos+100);
if (yPos>400){
stopTimedLoop(bLoop);
hideElement(“strawbelle”);
movestrawbelle();
}
});}
onEvent(“strawbelle”, “click”, function( ) {
stopTimedLoop(bLoop);
hideElement(“strawbelle”);
movestrawbelle();
});
//var cLoop = timedLoop;
function movestrawbelle2() {
var xPos=randomNumber(0,300);
setPosition(“strawbelle2”, xPos, -15);
showElement(“strawbelle2”);
cLoop = timedLoop(1000, function() { //added cLoop here
var yPos= getYPosition(“strawbelle2”);
setPosition(“strawbelle2”, xPos, yPos+60);
if (yPos>400){
stopTimedLoop(cLoop);
hideElement(“strawbelle2”);
movestrawbelle2();
}
});}
onEvent(“strawbelle2”, “click”, function( ) {
stopTimedLoop(cLoop);
hideElement(“strawbelle2”);
movestrawbelle2();
});
//var dLoop = timedLoop;
function movestrawbelle3() {
var xPos=randomNumber(0,300);
setPosition(“strawbelle3”, xPos, -15);
showElement(“strawbelle3”);
dLoop = timedLoop(1000, function() { //added dLoop here
var yPos= getYPosition(“strawbelle3”);
setPosition(“strawbelle3”, xPos, yPos+120);
if (yPos>400){
stopTimedLoop(dLoop);
hideElement(“strawbelle3”);
movestrawbelle3();
}
});}
onEvent(“strawbelle3”, “click”, function( ) {
stopTimedLoop(dLoop);
hideElement(“strawbelle3”);
movestrawbelle3();
});
//var eLoop = timedLoop;
function movestrawbelle4() {
var xPos=randomNumber(0,300);
setPosition(“strawbelle4”, xPos, -15);
showElement(“strawbelle4”);
eLoop = timedLoop(1000, function() { //added eLoop here
var yPos= getYPosition(“strawbelle4”);
setPosition(“strawbelle4”, xPos, yPos+120);
if (yPos>400){
stopTimedLoop(eLoop);
hideElement(“strawbelle4”);
movestrawbelle4();
}
});}
onEvent(“strawbelle4”, “click”, function( ) {
stopTimedLoop(eLoop);
hideElement(“strawbelle4”);
movestrawbelle4();
});
//var fLoop = timedLoop;
function movemangio() {
var xPos=randomNumber(0,300);
setPosition(“mangio”, xPos, -15);
showElement(“mangio”);
fLoop = timedLoop(1000, function() { //added fLoop here
var yPos= getYPosition(“mangio”);
setPosition(“mangio”, xPos, yPos+25);
if (yPos>400){
stopTimedLoop(fLoop);
hideElement(“mangio”);
movemangio();
}
});}
onEvent(“mangio”, “click”, function( ) {
stopTimedLoop(fLoop);
hideElement(“mangio”);
movemangio();
});
//var gLoop = timedLoop;
function moveboom() {
var xPos=randomNumber(0,300);
setPosition(“boom”, xPos, -15);
showElement(“boom”);
gLoop = timedLoop(1000, function() { //added gLoop here
var yPos= getYPosition(“boom”);
setPosition(“boom”, xPos, yPos+25);
if (yPos>400){
stopTimedLoop(gLoop);
hideElement(“boom”);
moveboom();
}
});}
onEvent(“boom”, “click”, function( ) {
stopTimedLoop(gLoop);
setScreen(“screen3”);
var seconds = 0;
var interval1 = setInterval(function() {
seconds = seconds + 1;
console.log(seconds + " seconds have elapsed");
setScreen(“screen4”);
clearInterval(interval1);
}, 1600);
});
speed(100);
onEvent(“restart”, “click”, function() {
setScreen(“screen1”);
});