dalnick
@dalnick
Нео-бразованный кододел

Где ошибка в коде js?

Плиз найдите ошибку
var cvs = document.getElementById("canvas");
var ctx = cvs.getContext("2d");

var bird = new Image();
var bg = new Image();
var fg = new Image();
var pipeUp = new Image();
var pipeBottom = new Image();
var devilButton = new Image();

bird.src = "img/bird.png";
bg.src = "img/bg.png";
fg.src = "img/fg.png";
pipeUp.src = "img/pipeUp.png";
pipeBottom.src = "img/pipeBottom.png";
devilButton.src = "img/devilButton.png";

// Звуковые файлы
var fly = new Audio();
var score_audio = new Audio();

fly.src = "audio/fly.mp3";
score_audio.src = "audio/score.mp3";

var gap = 200;

// При нажатии на какую-либо кнопку
function press (e) {
  if (e.keyCode === 38 /* up */ || e.keyCode === 87 /* w */){
    moveUp();
  }
  if (e.keyCode == 40 /* down */ || e.keyCode == 83 /* s */){
    moveDown();
  }
  if (e.keyCode == 39 /* down */ || e.keyCode == 68 /* s */){
    moveRight();
  }
  if (e.keyCode == 37 /* left */ || e.keyCode == 65 /* a */ ){
    moveLeft();
  }
} 
function moveUp() {
 yPos -= 15;
 yB -= 15;
}
function moveDown() {
 yPos += 15;
 yB += 15;
}
function moveRight() {
 xPos += 15;
 xB += 15;
}
function moveLeft() {
 xPos -= 15;
 xB -= 15;
}
function close() {
 gap = 0;
}
// Создание блоков
var pipe = [];
pipe[0] = {
 x : cvs.width/2,
 y : 2
};
var score = 0;
// Позиция птички
var xPos = 10;
var yPos = 150;
var xE, yE;
xE = xPos;
yE = yPos;
var xB = xPos;
var yB = yPos + 100;

function draw() {
 ctx.drawImage(bg, 0, 0);

 for(var 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
   });
 }

 // Отслеживание прикосновений
  if(xPos + bird.width >= pipe[i].x
  && xPos <= pipe[i].x + pipeUp.width
  && (yPos <= pipe[i].y + pipeUp.height
  || yPos + bird.height >= pipe[i].y + pipeUp.height + gap) || yPos + bird.height >= cvs.height - fg.height) {
  clearInterval(game); 
 }

 if(pipe[i].x == 5) {
 score++;
 score_audio.play();
 }
 }
 if(xPos < 0) {xPos = 0}
 if(yPos < 0) {yPos = 0} 
 if(xPos > 633) {xPos = 633}
 ctx.drawImage(fg, 0, cvs.height - fg.height);
 ctx.drawImage(bird, xPos, yPos);

 if(score == 4) {
   ctx.drawImage(devilButton, xE + 300, yE + 290);
   if(yB >= 410 && xB > 280 && xB < 340) {
    devilButton.src = "img/devilButton1.png";
    close();
   }
 }

 ctx.fillStyle = "#000";
 ctx.font = "24px Verdana";
 ctx.fillText("Счет: " + score, 10, cvs.height - 20);

 requestAnimationFrame(draw);
}
pipeBottom.onload = draw;
  • Вопрос задан
  • 172 просмотра
Решения вопроса 1
Dimastik86
@Dimastik86
(isset($brain))?: die;
dalnick, Code is syntactically valid. не переданы параметры, по синтаксису ок
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы