Hey so dass ich zur Zeit ein Flugzeug zu bekommen versuchen, auf einem Fenster zu bewegen, von jedem Ende zum anderes, in dieser Reihenfolge anschließen: von oben links nach oben rechts, von rechts oben nach rechts unten, von unten rechts nach unten links nach oben links nach links gefolgt zu senken. Dieses Projekt wird gezwungen, eine beschleunigte Bewegung von rechts oben nach rechts unten zu haben und von unten links nach oben links. Ich habe nur einen Schalter Fall, wie ich in Java würde, aber es scheint nicht zu stoppen, wenn die Ebene, die die maximale Breite Fenster trifft .. jede Hilfe würde geschätzt ...ein noob Programmierer versucht zuerst
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);
}