let cvs = document.getElementById("canvas");
ctx = cvs.getContext("2d");
bird = new Image();
bg = new Image();
pipeUp = new Image();
pipeBottom = new Image();
fg = new Image();
bird.src = "flappy_bird_bird.png";
bg.src = "flappy_bird_bg.png";
pipeUp.src = "flappy_bird_pipeUp.png";
pipeBottom.src = "flappy_bird_pipeBottom.png";
fg.src = "flappy_bird_fg.png";
xPos = 10;
yPos = 150;
grav = 2;
gap = 90;
pipe = [];
pipe[0] = {
x: cvs.width,
y: 0
}
console.log(pipe.length)
document.addEventListener("keydown", moveUp);
function moveUp() {
yPos -= 20
}
function draw() {
ctx.drawImage(bg, 0, 0);
for(let i = 0; i < pipe.length; i++) {
ctx.drawImage(pipeUp, pipe[i].x, pipe[i].y);
ctx.drawImage(pipeBottom, pipe[i].x, pipe[i].y + pipeUp.height + gap)
pipe[i].x--;
if(pipe[i].x === 125) {
pipe.push({
x: cvs.width,
y: Math.floor(Math.random() * pipeUp.height) - pipeUp.height
});
}
}
ctx.drawImage(fg, 0, cvs.height - fg.height);
ctx.drawImage(bird, xPos, yPos);
yPos += grav;
requestAnimationFrame(draw)
}
fg.onload = draw;
Мне 11, учу программирование гдето месяц. Можете пожалуйста обьяснить как работает этот цикл
for(let i = 0; i < pipe.length; i++) {
ctx.drawImage(pipeUp, pipe[i].x, pipe[i].y);
ctx.drawImage(pipeBottom, pipe[i].x, pipe[i].y + pipeUp.height + gap)
pipe[i].x--;
if(pipe[i].x === 125) {
pipe.push({
x: cvs.width,
y: Math.floor(Math.random() * pipeUp.height) - pipeUp.height
});
}
}