Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 15th, 2012  |  syntax: JavaScript  |  size: 0.66 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function jump() {
  2.         var time = 0;
  3.         var velocity = 50;
  4.         var startpos = 1;
  5.         var acceleration = -20;
  6.         console.log("start jump");
  7.         startpos = startpos + (velocity * time) + (Math.pow(acceleration * time, 2) / 2);
  8.         if (startpos >= archery && time != 0) {
  9.                 down = true;
  10.                 ctx.clearRect(0, 0, c.width, c.height);
  11.                 ctx.drawImage(archer, archerx, archery);
  12.                 ctx.drawImage(square, squarex, squarey);               
  13.         } else {
  14.                 ctx.clearRect(0, 0, c.width, c.height);
  15.                 ctx.drawImage(archer, archerx, (archery - startpos));
  16.                 ctx.drawImage(square, squarex, squarey);
  17.         }
  18.         if (!down) {
  19.                 time += 1;
  20.                 timerID = self.setTimeout("jump()", delayJump);
  21.         } else {
  22.                 down = false;
  23.         }
  24. }