xxxxxxxxxx
let x=400;
let y=400;
let a=300;
let b=500;
let ia=6;
let ib=7;
let c=600;
let d=400;
let ic=7;
let id=6;
let g=550;
let h=200;
let ig=6;
let ih=7;
let SpriteR = [];
let SpriteL = [];
let SpriteU = [];
let SpriteD = [];
let i=0;
let bgSound;
let winSound;
let gameoverSound;
let countdownSound;
let hitSound;
let imgDOWN;
let imgENEMY;
let imgBG;
let points=200;
let BeenHit=false;
let BeenHit2=false;
let BeenHit3=false;
let pauseSound=false;
let speed=1;
let time=0;
let levelNumber=0;
function preload(){
SpriteR[0] = loadImage("goblinr1.png");
SpriteR[1] = loadImage("goblinr2.png");
SpriteR[2] = loadImage("goblinr3.png");
SpriteR[3] = loadImage("goblinr4.png");
SpriteR[4] = loadImage("goblinr5.png");
SpriteR[5] = loadImage("goblinr6.png");
SpriteR[6] = loadImage("goblinr7.png");
SpriteL[0] = loadImage("goblinl1.png");
SpriteL[1] = loadImage("goblinl2.png");
SpriteL[2] = loadImage("goblinl3.png");
SpriteL[3] = loadImage("goblinl4.png");
SpriteL[4] = loadImage("goblinl5.png");
SpriteL[5] = loadImage("goblinl6.png");
SpriteL[6] = loadImage("goblinl7.png");
SpriteU[0] = loadImage("goblinu1.png");
SpriteU[1] = loadImage("goblinu2.png");
SpriteU[2] = loadImage("goblinu3.png");
SpriteU[3] = loadImage("goblinu4.png");
SpriteU[4] = loadImage("goblinu5.png");
SpriteU[5] = loadImage("goblinu6.png");
SpriteU[6] = loadImage("goblinu7.png");
SpriteD[0] = loadImage("goblind1.png");
SpriteD[1] = loadImage("goblind2.png");
SpriteD[2] = loadImage("goblind03.png");
SpriteD[3] = loadImage("goblind4.png");
SpriteD[4] = loadImage("goblind5.png");
SpriteD[5] = loadImage("goblind6.png");
SpriteD[6] = loadImage("goblind7.png");
bgSound = loadSound('Lotus Flower.mp3');
gameoverSound = loadSound('game-over-heavy-sound.m4a');
hitSound = loadSound('hitsound.m4a');
winSound = loadSound('win-sound01.m4a');
countdownSound = loadSound('321gosound.m4a');
imgENEMY = loadImage('fireball01.png');
imgDOWN = loadImage('goblind5.png');
imgBG = loadImage('forestground02.png');
//goSound = loadSound('gameoverpixie.m4a');
soundFormats('mp3', 'm4a');
}
function setup(){
createCanvas(600,600);
frameRate(25);
bgSound.play();
}
function draw(){
background(imgBG);
Gameover();
TimeCounter();
Levelcount();
if(levelNumber==0){
fill(0,99);
rect(0,0,600,600)
fill(255);
textSize(50);
textFont('Merriweather');
textAlign(CENTER);
text("Goblin & The Fire", width/2,height/2-50);
textSize(20);
text("~Instructions~", width/2, height/2-10);
textSize(16);
text("Goblin wants to become good. Save him from the evil spirits of the fire!", width/2,height/2+10);
text("Use the left, right, up & down arrow keys to escape the fire.", width/2,height/2+30);
text("NOTE: With every fire hit, you loose 50 points",width/2,height/2+250);
//displayEnemy01();
// score01();
}
if(levelNumber==1){
// fill(0);
// rect(30,73,150,40,30);
fill(255);
textSize(18);
textAlign(CENTER);
textFont('Merriweather');
text("LEVEL 1", width/2,height/2-252);
speed=1;
displayEnemy01();
score01();
}
if(levelNumber==2){
// fill(0);
// rect(30,73,150,40,30);
fill(255);
textSize(18);
textAlign(CENTER);
textFont('Merriweather');
text("LEVEL 2", width/2,height/2-252);
speed=2;
displayEnemy01();
displayEnemy02();
score01();
score02();
}
if(levelNumber==3){
// fill(0);
// rect(30,73,150,40,30);
fill(255);
textSize(18);
textAlign(CENTER);
textFont('Merriweather');
text("LEVEL 3", width/2,height/2-252);
speed=3;
displayEnemy01();
displayEnemy02();
displayEnemy03();
score01();
score02();
score03();
}
if(levelNumber==4){
textSize(40);
textFont('Merriweather');
winSound.play();
textAlign(CENTER);
text("WIN!",width/2,height/2);
bgSound.stop();
noLoop();
}
if (keyIsPressed==false){
displayCharacterIDLE();
}
if(keyIsDown(LEFT_ARROW)){
displayCharacterLEFT();
}
if(keyIsDown(RIGHT_ARROW)){
displayCharacterRIGHT();
}
if(keyIsDown(UP_ARROW)){
displayCharacterUP();
}
if(keyIsDown(DOWN_ARROW)){
displayCharacterDOWN();
}
}
function displayCharacterIDLE(){
image(imgDOWN,x,y,100,100);
}
function displayCharacterRIGHT(){
x+=12;
if(i<=5){i++}else{i=0}
image(SpriteR[i],x,y,100,100);
}
function displayCharacterLEFT(){
x-=12;
if(i<=5){i++}else{i=0}
image(SpriteL[i],x,y,100,100);
}
function displayCharacterUP(){
y-=12;
if(i<=5){i++}else{i=0}
image(SpriteU[i],x,y,100,100);
}
function displayCharacterDOWN(){
y+=12;
if(i<=5){i++}else{i=0}
image(SpriteD[i],x,y,100,100);
}
function displayEnemy01(){
image(imgENEMY,a=a+ia*speed,b=b+ib*speed,100,100);
if(a>width||a<0){
ia= ia*(-1);
}
if(b>height||b<0){
ib= ib*(-1);
}
a=a+ia;
b=b+ib;
}
function score01(){
fill(100);
rect(30,23,125,35,25);
fill(255);
textSize(18);
textAlign(LEFT);
textFont('Merriweather');
text("SCORE: " + points,width/2-254, height/2-252);
let distance01 = dist(x,y,a,b);
if((distance01<70)&&(BeenHit==false)){
points=points-50;
BeenHit=true;
} //else {points=points+1}
if(distance01>70){
BeenHit=false;
}
}
function displayEnemy02(){
image(imgENEMY,c=c+ic*speed,d=d+id*speed,100,100);
if(c>width||c<0){
ic= ic*(-1);
}
if(d>height||d<0){
id= id*(-1);
}
c=c+ic;
d=d+id;
}
function score02(){
fill(100);
rect(30,23,125,35,25);
fill(255);
textSize(18);
textAlign(LEFT);
textFont('Merriweather');
text("SCORE: " + points,width/2-254, height/2-252);
let distance02 = dist(x,y,c,d);
if((distance02<70)&&(BeenHit2==false)){
points=points-50;
BeenHit2=true;
} //else {points=points+1}
if(distance02>70){
BeenHit2=false;
}
}
function displayEnemy03(){
image(imgENEMY,g=g+ig*speed,h=h+ih*speed,100,100);
if(g>width||g<0){
ig= ig*(-1);
}
if(h>height||h<0){
ih= ih*(-1);
}
g=g+ig;
h=h+ih;
}
function score03(){
fill(100);
rect(30,23,125,35,25);
fill(255);
textSize(18);
textAlign(LEFT);
textFont('Merriweather');
text("SCORE: " + points,width/2-254, height/2-252);
let distance03 = dist(x,y,g,h);
if((distance03<70)&&(BeenHit3==false)){
points=points-50;
BeenHit3=true;
} //else {points=points+1}
if(distance03>70){
BeenHit3=false;
}
}
function Gameover(){
if(points<=-4){
fill(0);
rect(0,0,800,800);
fill(255);
textSize(25);
textAlign(CENTER);
textFont('Merriweather');
text("Game Over!",width/2,height/2);
gameoverSound.play();
bgSound.stop();
noLoop();
}
}
function TimeCounter(){
time=time+1;
text(time,530,50);
}
function Levelcount(){
if(time>200){
levelNumber=levelNumber+1;
time=0;
}
}