-2
こんにちは、私は現在、上の左から右上、右上から右下に、この順番に従って、各四肢から別の順に、飛行機をウィンドウ上に移動しようとしています。右下を左下に、右下を左下に移動します。このプロジェクトは、右上から右下へ、左下から左上への加速的な動きを強いられます。私はあなたが持っていると思いnoobプログラマーが最初に試してみましょう
var ctx;
var img;
var larg = 1200;
var alt = 560;
var xAviao = 0;
var yAviao = 0;
c = 1
// Parâmetros do movimento acelerado
var x0 = 0;
var y0 = 0;
var v0 = 0;
var a = 120; // 120 px/s2
var t = 0;
function init() {
canvas = document.getElementById("cvs");
ctx = canvas.getContext("2d");
canvas.setAttribute("width", larg);
canvas.setAttribute("height", alt);
img = new Image();
img.src = "aviao.png";
gameLoop();
}
function gameLoop() {
window.requestAnimationFrame(gameLoop);
update();
render();
}
function update() {
var direction = 1;
if(xAviao > (larg - img.Width))
{
y0 = 0;
a = 120;
t = 0;
xAviao = (larg - img.Width);
direcao = 2;
}
else if (yAviao > alt - img.Height)
{
yAviao = alt - aviao.Height;
direction = 3;
}
else if (xAviao < 0)
{
xAviao = 0;
t = 0;
y0 = yAviao;
a= -120;
direction = 4;
}
else if (yAviao < 0)
{
yAviao = 0;
direction = 1;
}
switch(direction){
case 1:
xAviao +=10 ;
console.log(c);
break;
case 2:
t += 1/60; // time increases 60 seconds per 60 frames
yAviao = Math.floor(y0 + v0*t + a*t*t);
break;
case 3:
xAviao -= 10;
break;
case 4:
t += 1/60; // time increases 60 seconds per 60 frames
yAviao = Math.floor(y0 + v0*t + a*t*t);
break;
}
}
function render() {
// Retângulo do fundo
ctx.fillStyle = "#FFA060";
ctx.beginPath();
ctx.rect(0,0,larg,alt);
ctx.fill();
// Desenha o avião
if(img != undefined)
ctx.drawImage(img, xAviao, yAviao);
}