Bootleg Pilot Training

Sve samo da ne radim RPPP

HTML

<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>Bootleg Pilot Training</title>
  </head>

  <body>
    <canvas id="bootleg-pilot-trainer"></canvas>
  </body>

</html>

JavaScript

var canvas = document.getElementById('bootleg-pilot-trainer');
var ctx = canvas.getContext('2d');

var width = 450;
var height = 450;

var wallThickness = 50;

var isGameRunning = false;
var gameStart;
var player;
var enemies;

function reset() {
  player = {
    x: 205,
    y: 205,
    width: 40,
    height: 40,
  };

  enemies = [{
    x: 270,
    y: 60,
    width: 60,
    height: 50,
    xVel: -125,
    yVel: 150,
  }, {
    x: 300,
    y: 330,
    width: 100,
    height: 20,
    xVel: -150,
    yVel: -250,
  }, {
    x: 70,
    y: 320,
    width: 30,
    height: 60,
    xVel: 187.5,
    yVel: -162.5,
  }, {
    x: 70,
    y: 70,
    width: 60,
    height: 60,
    xVel: 212.5,
    yVel: 137.5,
  }, ];

  isGameRunning = false;
}

var lastFrame = Date.now();

function doFrame() {
  var now = Date.now();
  var dt = (now - lastFrame) / 1000;
  lastFrame = now;

  if (dt > 1 / 20)
    dt = 1 / 20;

  if (isGameRunning)
    moveEnemies(dt);

  draw();

  if (isGameRunning)
    for (var i = 0; i < enemies.length; i++)
      if (areOverlapping(player, enemies[i]))
        lose();

  if (isGameRunning)
    if (player.x < wallThickness || player.x + player.width >= width - wallThickness ||
      player.y < wallThickness || player.y + player.height >= height - wallThickness)
      lose();

  requestAnimationFrame(doFrame);
}

function draw() {
  ctx.fillStyle = 'black';
  ctx.fillRect(0, 0, width, height);

  ctx.fillStyle = 'white';
  ctx.fillRect(wallThickness, wallThickness,
    width - 2 * wallThickness, height - 2 * wallThickness);

  ctx.fillStyle = '#009';
  for (var i = 0; i < enemies.length; i++)
    ctx.fillRect(enemies[i].x, enemies[i].y, enemies[i].width, enemies[i].height);

  ctx.fillStyle = '#900';
  ctx.fillRect(player.x, player.y, player.width, player.height);
}

function bounce(enemy) {
  if (enemy.x < 0) {
    enemy.x = -enemy.x;
    enemy.xVel = -enemy.xVel;
  } else if (enemy.x + enemy.width > width) {
    enemy.x = width * 2 - enemy.x - 2 *...