xxxxxxxxxx
51
// posições
var x =70;
var yChao = 200;
var y = yChao;
var h = 0;
var tempo = 0;
var tempoMaxPulo = 20;
var estaPulando = false;
function alturaPulo(t){
return (1)*(t)*(t - tempoMaxPulo);
}
function setup() {
createCanvas(400, 300);
frameRate(30);
}
function draw() {
// desenha cenário
background(30);
stroke(255);
fill(100);
rect(0,yChao+5,400,100);
fill(230)
ellipse(x,y+h,30,40);
// controle das teclas
if (keyIsDown(RIGHT_ARROW)){
x = x + 6;
}
if (keyIsDown(LEFT_ARROW)){
x = x - 6;
}
if ( keyIsDown(UP_ARROW) && ! estaPulando ) {
estaPulando = true;
}
if ( estaPulando ) {
h = alturaPulo(tempo);
tempo++;
console.log(h+" "+tempo);
if (tempo >= tempoMaxPulo){
estaPulando = false;
h = 0;
tempo = 0;
}
}
}