xxxxxxxxxx
143
var tela = 1
let img, img2, img3, img4
var gato;
var screen = 0;
var y=-20;
var x=200;
var speed = 2;
var score= 0;
var imgQueijo;
var xBotao = 300
function preload(){
// menu
img = loadImage('fundo.jpeg')
// jogo
img2 = loadImage ('instruções.jpeg')
// instruções
img3 = loadImage ('credits.jpeg')
// créditos
img4 = loadImage ('fundo.jpeg')
// sprites
imgQueijo = loadImage ('queijo.png')
gato = loadImage('Gato.jpg');
}
function setup() {
createCanvas(600, 400);
}
function draw() {
if (tela === 1){
menu()
}
if (tela === 2){
play()
}
if (tela === 3){
rules()
}
if (tela === 4){
credits()
}
if (tela == 5){
endScreen();
}
}
function menu() {
image(img4, 0, 0, 600, 400)
rectMode(CORNER)
fill (25, 25, 112);
if ( mouseX >= 100 && mouseX <= 300 && mouseY >= 100 && mouseY <= 150){
fill (55)
if (mouseIsPressed){
tela = 2
}
}
rect (200, 100, 200, 50, 10)
fill (25, 25, 112);
if ( mouseX >= 100 && mouseX <= 300 && mouseY >= 200 && mouseY <= 250){
fill (55)
if (mouseIsPressed){
tela = 3
}
}
rect (200, 200, 200, 50, 10)
fill (25, 25, 112);
if ( mouseX >= 100 && mouseX <= 300 && mouseY >= 300 && mouseY <= 350){
fill (55)
if (mouseIsPressed){
tela = 4
}
}
rect (200, 300, 200, 50, 10)
textSize (26)
textAlign (CENTER)
fill (200, 200, 200)
text ("Jogar", 300, 135)
text ("Instruções", 300, 235)
text ("Créditos", 300, 335)
}
function play(){
background('fundo.jpeg')
text("score = " + score, 70,20)
image(imgQueijo, x,y,30,30)
rectMode(CENTER)
image(gato,mouseX,height-50,50,50)
y+= speed;
if(y>height){
tela = 5
}
if(y>height-10 && x>mouseX-20 && x<mouseX+20){
y=-20
speed+= 0.4
score+= 1
}
if(y==-20){
x = random(0,width)
}
}
function endScreen(){
background(150)
textAlign(CENTER);
text('GAME OVER', width / 2, height / 2)
text("SCORE = " + score, width / 2, height / 2 + 20)
//tela = 1
}
function reset(){
score=0;
speed=2;
y=-20;
}
function rules(){
background (img2)
}
function credits(){
background (img3)
}
function keyPressed(enter){
if (tela === 2 || tela === 3 || tela ===4 ){
if (keyCode === ESCAPE){
tela = 1
}
}
if ( tela === 5 ){
if (keyCode === ESCAPE){
tela = 1
reset()
}
}
}