xxxxxxxxxx
197
var fundo1,fundo, snd, snd1;
var tela = 0;
var largura = 200;
var altura = 50;
var xMenu = 100;
var yMenu1 = 185;
var yMenu2 = 245;
var yMenu3 = 305;
var tcanvas = 500; //tamnho canvas
var t = 10; //tamanho celda
var ncel = tcanvas/t //numero de celdas
var laberinto;
//posições jogador
var posx = 0;
var posy = 0;
function preload(){
soundFormats('mp3');
snd = loadSound('game-start-6104.mp3');
snd1 = loadSound('button-124476.mp3');
}
//background//
function setup() {
createCanvas(400, 400);
fundo1 = loadImage('abyrinth.jpg')
fundo = loadImage('fundo.jpg')
noStroke();
//crear array laberinto//
laberinto = [];
for(let x = 0; x<ncel; x+=1){
laberinto [x] = [];
for (let y=0; y<ncel;y+=1){
laberinto[x][y] = 0;
}
}
//definir laberinto
for(let x=0;x<ncel;x+=2){
for(let y=0;y<ncel;y+=2){
laberinto[x][y]=1;
let vecino = [];
if(x<ncel){vecino.push({x:x+1, y:y})}
if(y<ncel){vecino.push({x:x, y:y+1})}
if(vecino.length>0){
let ve = vecino[int(random(2))];
laberinto[ve.x][ve.y]=1
}
}
}
sorteioDestino();
}
function sorteioDestino() {
xd = int(random(ncel));
yd = int(random(ncel));
while (laberinto[xd][yd] == 0 ){
console.log(laberinto[xd][yd]);
xd = int(random(ncel));
yd = int(random(ncel));
}
laberinto[xd][yd] = 2;
}
function draw() {
textStyle(BOLD);
//menu
if (tela == 0){
background(fundo1,70)
//2 options menu//
//start
textAlign(CENTER);
textSize(28);
//rectangulo aparecer
if(mouseX > xMenu && mouseX < xMenu + largura && mouseY > yMenu1 && mouseY < yMenu1 + altura){
stroke(186,85,211);
fill(139,0,139); //color//
rect(xMenu, yMenu1, largura, altura, 15);
if (mouseIsPressed){ //cambiar cuando click
tela = 1;
}
}
fill(240);
noStroke();
text("Começar", 200, 220);//start button
//instructions
if(mouseX > xMenu && mouseX < xMenu + largura && mouseY > yMenu2 && mouseY < yMenu2 + altura){
stroke(186,85,211);
fill(139,0,139);
rect(xMenu, yMenu2, largura, altura, 15);
if(mouseIsPressed){
tela = 2
}
}
fill(240);
noStroke();
text("Instruções", 200, 280);
//creditos
if(mouseX > xMenu && mouseX < xMenu + largura && mouseY > yMenu3 && mouseY < yMenu3 + altura){
stroke(186,85,211);
fill(139,0,139); //color//
rect(xMenu, yMenu3, largura, altura, 15);
if (mouseIsPressed){ //cambiar cuando click
tela = 3
}
}
fill(240);
noStroke();
text("Créditos", 200, 340);//credits button
//game//
}if(tela == 1){
jogo();
//instruções//
}else if(tela == 2){
background(fundo,70);
textAlign(CENTER);
textSize(28);
fill(240);
text("Instruções", 200, 120);
textSize(20);
fill(240);
text("Utilizar as setas para\n movimentar o icone ao longo\n do laberinto até chegar\n na meta.",200, 220)
//créditos//
}else if (tela == 3){
background(fundo,70)
textAlign(LEFT);
textSize(20);
fill(240);
text("Lisandry Paola Azuaje Figuera.\nTurma 02C.\n2022.2", 20, 190);
}
if(tela === 1){
jogo();
}
}
function keyPressed(){
if (tela === 1 || tela === 2 || tela === 3){
if (keyCode === ESCAPE){
tela = 0;
snd1.play();
}
}
if (tela === 1) {
if(keyCode == LEFT_ARROW && posx>0){
if(laberinto[posx-1][posy]!=0){
posx -= 1;
}
}else if(keyCode == RIGHT_ARROW && posx<ncel-1){
if(laberinto[posx+1][posy]!=0){
posx += 1;
}
}else if(keyCode == UP_ARROW && posy>0){
if(laberinto[posx][posy-1]!=0){
posy -= 1;
}
}else if(keyCode == DOWN_ARROW && posy<ncel-1){
if(laberinto[posx][posy+1]!=0){
posy += 1;
}
}
if ( laberinto[posx][posy] == 2 ){
console.log("Chegou no destino!!");
}
}
}
function mouseClicked(){
if(mouseX > xMenu && mouseX < xMenu + largura && mouseY > yMenu1 && mouseY < yMenu1 + altura){
snd.play();
}else if(mouseX > xMenu && mouseX < xMenu + largura && mouseY > yMenu2 && mouseY < yMenu2 + altura|| mouseX > xMenu && mouseX < xMenu + largura && mouseY > yMenu3 && mouseY < yMenu3 + altura){
snd1.play();
}
}