The Pathetic Dot Game

by Nipperz

HTML

<canvas id="canvas"></canvas>

CSS

canvas {
  border: 1px solid #000;
}

JavaScript

(function() {
  var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  window.requestAnimationFrame = requestAnimationFrame;
})();

var canvas = document.getElementById("canvas"),
  ctx = canvas.getContext("2d"),
  width = 500,
  height = 300,
  player = {
    x: width / 2,
    y: 0,
    width: 5,
    height: 5,
    speed: 3,
    velX: 0,
    velY: 0,
    jumping: false,
    grounded: false
  },
  guy = {
    x: -75,
    y: 120,
    width: 5,
    height: 5,
    direction: "l",
    count: 0
  },
  //wall in front of client
  wall = {
    x: -60,
    y: -100,
    width: 10,
    height: 225,
    color: "transparent"
  },
  ground = {
    x: 0,
    y: 500,
    width: width,
    height: 30
  },
  elevator = {
    x: 100,
    y: 495,
    width: 40,
    height: 40,
    at_top: 0
  },
  briefcase = {
    x: 2900,
    y: 370,
    width: 20,
    height: 12,
    count: 0
  },

  keys = [],
  friction = 0.8,
  gravity = 0.2;

//court house door
door = {
  x: 6835,
  y: 175,
  width: 50,
  height: 75,
  color: "transparent"
};

//put random leaves on the tree
var leaves = []
for (i = 0; i < 12; i++) {
  leaves.push({
    x: Math.random() * (10 - -70) + -70,
    y: Math.random() * (140 - 40) + 40,
    size: Math.random() * (50 - 20) + 20
  });
}

var boxes = [];
// courthouse platform
boxes.push({
  x: 6500,
  y: 200,
  width: 30,
  height: 30
});
//courthouse base
boxes.push({
  x: 6600,
  y: 270,
  width: 500,
  height: 20
});
//tree platforms
boxes.push({
  x: -40,
  y: 250,
  width: 130,
  height: 15
});
boxes.push({
  x: 150,
  y: 180,
  width: 30,
  height: 30
});
//trunk
boxes.push({
  x: -30,
  y: 130,
  width: 7,
  height: 120
});
//top branch
boxes.push({
  x: -85,
  y: 125,
  width: 70,
  height: 7
});
//bottom branch
boxes.push({
  x: -24,
  y: 170,
  width: 20,
  height: 7
});
//player platform
boxes.push({
  x: 215,
  y: 150,
  width: 60,
  height:...