Pig Eatin Time! One

Be a pig, and eat healthy, be rich, all you want with a pig here. Pig name: Mavice

by nukeboy212

HTML

<canvas id="poop05" width="630" height="450"></canvas>

<img src="http://pngimg.com/upload/green_leaves_PNG3678.png" id ="ii">
<img src="http://vignette3.wikia.nocookie.net/adventuretimewithfinnandjake/images/0/06/Pig_trans.png/revision/latest?cb=20120812082359" id = "one">

<h2 id="oi">
You are a delicate little fat pig you must live against horrible things (click to start)
</h2>

CSS

canvas {
  background-color: pink;
}

img {
  display: none;
}

h2 {
  color: Red;
}

JavaScript

console.log("Hello! Most people won't bother looking at this text!");

var canvas = document.getElementById("poop05");
var ctx = canvas.getContext("2d");
var enemies = [];
var money = 0;
var time = 60;

function Enemy(I) {
  I = I || {};
  I.active = true;
  I.age = Math.floor(Math.random() * 128);
  I.color = "red";
  I.x = Math.random() * 1000;
  I.y = 0;
  I.xVelocity = 0;
  I.yVelocity = 2;
  I.width = 50;
  I.height = 50;

  I.inBounds = function() {
    return I.x >= 0 && I.x <= 1000 && I.y >= 0 && I.y <= 1000;
  };

  I.draw = function() {
    //ctx.fillStyle = this.color;
    //ctx.fillRect(this.x, this.y, this.width, this.height);
    ctx.drawImage(ii, this.x, this.y, this.width, this.height);

  };

  I.update = function() {
    I.x += I.xVelocity;
    I.y += I.yVelocity;
    I.age++;

    I.xVelocity = 3 * Math.sin(I.age * Math.PI / 64);

    I.active = I.active && I.inBounds();

  };
  return I;

};

var player = {
  color: "yellow",
  height: 80,
  width: 100,
  x: canvas.width / 2,
  y: canvas.height - 100,

  draw: function() {
    //ctx.fillStyle = this.color;
    //ctx.fillRect(this.x, this.y, this.width, this.height);
    ctx.drawImage(one, this.x, this.y, this.width, this.height);
  }
};
function draw() {

  ctx.clearRect(0, 0, canvas.width, canvas.height);
  player.draw();
  enemies.forEach(function (enemy) {
  enemy.draw();
  
  });
drawscore();
timer();
//setInterval(timer,1000);


};

function update() {
  enemies.forEach(function(enemy) {
    enemy.update();
  });
  enemies = enemies.filter(function(enemy) {
    return enemy.active;
  });
  if (Math.random() < 0.05) {
    enemies.push(Enemy());
  }
  handleCollisions();
}

setInterval(function() {
  draw();
  update();
}, 1000 / 30);


$(document).on("keydown", function(event) {
  if (event.which === 68 && player.x < canvas.width - player.width) {
    player.x += 10;
  } else if (event.which === 65 && player.x > 0) {
    player.x -= 10;
  }
})

function collide(a, b)  {
return a.x < b.x +...