processing实现canvas万圣节捉鬼游戏代码

代码语言:html

所属分类:游戏

代码描述:processing实现canvas万圣节捉鬼游戏代码,这个游戏是基于Google涂鸦“2018万圣节”的主题。在游戏中,幽灵们组队竞争,看谁能在月亮消失之前收集到最多的游荡鬼火。但途中会有一些意外的转折...使用方向键或WASD键来移动和收集鬼火。你可以从敌人那里偷取鬼火,但要小心,他们也可以偷走你的。将鬼火带回你的基地可以获得积分。请注意,不同的鬼火会给你不同的能力。

代码标签: processing canvas 万圣节 捉鬼 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  
  
<style>
* {
  margin: 0;
  box-sizing: border-box;
  overflow: hidden;
}

body {
  background: #242424;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
body canvas {
  box-shadow: 0.2em 0.2em 2em #0008;
  border: none;
  outline: none;
}
</style>

  
</head>

<body translate="no">
  <canvas id="canvas"></canvas>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/processing.1.4.8.js"></script>
      <script  >
var sketchProc = function(processingInstance) {
     with (processingInstance) {
        size(600, 600);
       
        frameRate(60);
        
        smooth();
       
        var game;

      //Keys/Mouse
      {
          //Key|Button stuff
          var clicked = false;
          var hover = false;
          var keys = [];
          keyPressed = function () {
              keys[keyCode] = true;
          };
          keyReleased = function () {
              keys[keyCode] = false;
          };
          mouseClicked = function () {
              clicked = true;
          };
      }

      /** @created_by MKaelin368 (KWC) (c) 2018 */
      var setKALoopTimeout = function (ms) {
        var method_name = "KAInfiniteLoopSetTimeout";
        if (method_name in this) {
          this[method_name](ms >>> 0);
        }
      };

      var Button = function (config) {
          this.x = config.x || 0;
          this.y = config.y || 0;
          this.size = config.size || 100;
          this.content = config.content || "Home";
          this.page = config.page || "home";
          this.textSize = config.textSize || this.size / 5;
          this.borderColor = color(12, 31, 3, 20);
          this.backColor = color(70, 71, 71, 150);
          this.textColor = config.textColor || color(170, 170, 170);
          this.backColorHover = color(102, 105, 105, 150);
          this.textColorHover = color(130, 130, 130);
          this.growth = 0;
          this.func = config.func || function() {};

          this.draw = function () {
              pushStyle();
              textAlign(CENTER, CENTER);
              textSize(this.textSize + (this.growth * 0.1));
              noStroke();

              //shadow
              fill(20, 20, 20, 30);
              ellipse(this.x, this.y + this.size * 0.52, (this.size + this.growth) * 0.8, (this.size + this.growth) * 0.3);

              //circles
              if (dist(mouseX, mouseY, this.x, this.y) <= this.size / 2) { //hover
                  hover = true;
                  this.growth = constrain(this.growth + 0.5, 0, 10);
                  if (clicked) {
                      this.func();
                  }

                  fill(this.backColorHover);
                  stroke(this.borderColor);
                  noStroke();
                  ellipse(this.x, this.y, this.size + this.growth, this.size + this.growth);
                  fill(this.textColorHover);
                  switch(this.content) {
                      case "Play":
                          triangle(this.x + this.size*0.25, this.y, this.x - this.size*0.15, this.y - this.size*0.25, this.x - this.size*0.15, this.y + this.size*0.25);
                          break;
                      case "How":
                          pushStyle();
                              textSize(this.size*0.6);
                              text("?", this.x, this.y);
                          popStyle();
                          break;
                      case "Sound":
                          pushStyle();
                              noStroke();
                              fill(this.textColorHover);
                              triangle(this.x, this.y - this.size * 0.3, this.x, this.y + this.size * 0.3, this.x - this.size * 0.3, this.y);
                              rect(this.x - this.size * 0.3, this.y - this.size * 0.1, this.size * 0.3, this.size * 0.2);
                              if(game.sound) {
                                  noFill();
                                  stroke(this.textColorHover);
                                  strokeWeight(this.size/20);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.2, this.size * 0.2, -91, 90);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.4, this.size * 0.4, -81, 80);
                              }
                              else {
                                  noFill();
                                  stroke(this.textColorHover);
                                  strokeWeight(this.size/20);
                                  line(this.x + this.size * 0.1, this.y - this.size * 0.1, this.x + this.size * 0.25, this.y + this.size * 0.1);
                                  line(this.x + this.size * 0.1, this.y + this.size * 0.1, this.x + this.size * 0.25, this.y - this.size * 0.1);
                              }
                          popStyle();
                          break;
                      case "Story":
                          pushStyle();
                              noFill();
                              stroke(this.textColorHover);
                              strokeWeight(4);
                              line(this.x-this.size*0.23, this.y-this.size*0.2, this.x+this.size*0.23, this.y-this.size*0.2);
                              line(this.x-this.size*0.23, this.y, this.x+this.size*0.23, this.y);
                              line(this.x-this.size*0.23, this.y+this.size*0.2, this.x+this.size*0.23, this.y+this.size*0.2);
                          popStyle();
                          break;
                      case "Scoreboard":
                          pushStyle();
                              noFill();
                              stroke(this.textColorHover);
                              strokeWeight(this.size * 0.14);
                              strokeCap(SQUARE);

                              line(this.x, this.y + this.size * 0.25, this.x, this.y - this.size * 0.3);
                              line(this.x - this.size * 0.2, this.y + this.size * 0.25, this.x - this.size * 0.2, this.y - this.size * 0.1);
                              line(this.x + this.size * 0.2, this.y + this.size * 0.25, this.x + this.size * 0.2, this.y - this.size * 0.2);
                          popStyle();
                          break;
                      case "Back":
                          pushStyle();
                          beginShape();
                              vertex(this.x+this.size*0.25, this.y); //1
                              vertex(this.x+this.size*0.25, this.y+this.size*0.25); //2
                              vertex(this.x+this.size*0.07, this.y+this.size*0.25); //3
                              vertex(this.x+this.size*0.07, this.y+this.size*0.12); //4
                              vertex(this.x-this.size*0.07, this.y+this.size*0.12); //5
                              vertex(this.x-this.size*0.07, this.y+this.size*0.25); //6
                              vertex(this.x-this.size*0.25, this.y+this.size*0.25); //7
                              vertex(this.x-this.size*0.25, this.y); //8
                              vertex(this.x, this.y-this.size*0.2); //9
                              vertex(this.x+this.size*0.25, this.y); //10
                          endShape();
                          noFill();
                          stroke(this.textColorHover);
                          strokeWeight(this.size*0.05);
                          line(this.x-this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.15, this.y-this.size*0.19, this.x+this.size*0.15, this.y-this.size*0.25);
                          popStyle();
                          break;
                      case "Replay":
                          pushStyle();
                              noFill();
                              stroke(this.textColorHover);
                              strokeWeight(5);
                              pushMatrix();
                                  translate(this.x, this.y);
                                  rotate(radians(game.rate * 5));
                                  arc(0, 0, this.size * 0.6, this.size * 0.6, 1, 275);
                                  noStroke();
                                  fill(this.textColorHover);
                                  translate(this.size * 0.30, -this.size * 0.18);
                                  rotate(radians(-70));
                                  triangle(0, -this.size * 0.1, -this.size * 0.14, -this.size * 0.3, this.size * 0.14, -this.size * 0.3);
                              popMatrix();
                          popStyle();
                          break;
                      default:
                          text(this.content, this.x, this.y);
                  }
              }
              else { //not hover
                  this.growth = constrain(this.growth - 0.5, 0, 10);
                  fill(this.backColor);
                  strokeWeight(2);
                  stroke(this.borderColor, 100);
                  noStroke();
                  ellipse(this.x, this.y, this.size + this.growth, this.size + this.growth);
                  fill(this.textColor);
                  switch(this.content) {
                      case "Play":
                          triangle(this.x + this.size*0.25, this.y, this.x - this.size*0.15, this.y - this.size*0.25, this.x - this.size*0.15, this.y + this.size*0.25);
                          break;
                      case "How":
                          pushStyle();
                              textSize(this.size*0.6);
                              text("?", this.x, this.y);
                          popStyle();
                          break;
                      case "Sound":
                          pushStyle();
                              noStroke();
                              fill(this.textColor);
                              triangle(this.x, this.y - this.size * 0.3, this.x, this.y + this.size * 0.3, this.x - this.size * 0.3, this.y);
                              rect(this.x - this.size * 0.3, this.y - this.size * 0.1, this.size * 0.3, this.size * 0.2);
                              if(game.sound) {
                                  noFill();
                                  stroke(this.textColor);
                                  strokeWeight(this.size/20);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.2, this.size * 0.2, -91, 90);
                                  arc(this.x + this.size * 0.1, this.y, this.size * 0.4, this.size * 0.4, -81, 80);
                              }
                              else {
                                  noFill();
                                  stroke(this.textColor);
                                  strokeWeight(this.size/20);
                                  line(this.x + this.size * 0.1, this.y - this.size * 0.1, this.x + this.size * 0.25, this.y + this.size * 0.1);
                                  line(this.x + this.size * 0.1, this.y + this.size * 0.1, this.x + this.size * 0.25, this.y - this.size * 0.1);
                              }
                          popStyle();
                          break;
                      case "Story":
                          pushStyle();
                              noFill();
                              stroke(this.textColor);
                              strokeWeight(4);
                              line(this.x-this.size*0.23, this.y-this.size*0.2, this.x+this.size*0.23, this.y-this.size*0.2);
                              line(this.x-this.size*0.23, this.y, this.x+this.size*0.23, this.y);
                              line(this.x-this.size*0.23, this.y+this.size*0.2, this.x+this.size*0.23, this.y+this.size*0.2);
                          popStyle();
                          break;
                      case "Scoreboard":
                          pushStyle();
                              noFill();
                              stroke(this.textColor);
                              strokeWeight(this.size * 0.14);
                              strokeCap(SQUARE);

                              line(this.x, this.y + this.size * 0.25, this.x, this.y - this.size * 0.3);
                              line(this.x - this.size * 0.2, this.y + this.size * 0.25, this.x - this.size * 0.2, this.y - this.size * 0.1);
                              line(this.x + this.size * 0.2, this.y + this.size * 0.25, this.x + this.size * 0.2, this.y - this.size * 0.2);
                          popStyle();
                          break;
                      case "Back":
                          pushStyle();
                          beginShape();
                              vertex(this.x+this.size*0.25, this.y); //1
                              vertex(this.x+this.size*0.25, this.y+this.size*0.25); //2
                              vertex(this.x+this.size*0.07, this.y+this.size*0.25); //3
                              vertex(this.x+this.size*0.07, this.y+this.size*0.12); //4
                              vertex(this.x-this.size*0.07, this.y+this.size*0.12); //5
                              vertex(this.x-this.size*0.07, this.y+this.size*0.25); //6
                              vertex(this.x-this.size*0.25, this.y+this.size*0.25); //7
                              vertex(this.x-this.size*0.25, this.y); //8
                              vertex(this.x, this.y-this.size*0.2); //9
                              vertex(this.x+this.size*0.25, this.y); //10
                          endShape();
                          noFill();
                          stroke(this.textColor);
                          strokeWeight(this.size*0.05);
                          line(this.x-this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.27, this.y-this.size*0.05, this.x, this.y-this.size*0.27);
                          line(this.x+this.size*0.15, this.y-this.size*0.19, this.x+this.size*0.15, this.y-this.size*0.25);
                          popStyle();
                          break;
                      case "Replay":
                          pushStyle();
                              noFill();
                              stroke(this.textColor);
                              strokeWeight(5);
                              pushMatrix();
                                  translate(this.x, this.y);
                                  rotate(radians(sin(game.rate * 5) * 20));
                                  arc(0, 0, this.size * 0.6, this.size * 0.6, 1, 275);
                                  noStroke();
                                  fill(this.textColor);
                                  translate(this.size * 0.30, -this.size * 0.18);
                                  rotate(radians(-70));
                                  triangle(0, -this.size * 0.1, -this.size * 0.14, -this.size * 0.3, this.size * 0.14, -this.size * 0.3);
                              popMatrix();
                          popStyle();
                          break;
                      default:
                          text(this.content, this.x, this.y);
                  }
              }

              popStyle();
          };
      };

      var Avatar = function(config) {
          this.type = config.type || 0;
          this.draw = function() {
              switch(this.type) {
                  case 0: //Jade
                      pushMatrix();
                          pushStyle();
                              //face
                              noStroke();
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 5);
                                  bezierVertex(65, 4, 86, 15, 91, 34);
                                  bezierVertex(94, 58, 82, 72, 63, 79);
                                  bezierVertex(36, 82, 16, 72, 11, 52);
                                  bezierVertex(8, 32, 20, 12, 50, 5);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 3);
                                  bezierVertex(69, 3, 88, 8, 97, 32);
                                  bezierVertex(102, 58, 101, 82, 100, 101);
                                  bezierVertex(99, 110, 100, 115, 90, 118);
                                  bezierVertex(79, 116, 80, 109, 79, 103);
                                  bezierVertex(77, 110, 70, 117, 62, 119);
                                  bezierVertex(52, 119, 48, 114, 44, 106);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 3, 50, 3);
                              endShape(CLOSE);

                              //eyes
                              noStroke();
                              fill(0, 97, 0);
                              ellipse(39, 29, 25, 23);
                              ellipse(70, 26, 25, 23);

                              //eyeballs
                              fill(174, 255, 174);
                              ellipse(43, 30, 11, 10);
                              ellipse(66, 27, 11, 10);

                              //mouth
                              noFill();
                              stroke(0, 97, 0, 100);
                              strokeWeight(3);
                              bezier(39, 48, 44, 53, 54, 55, 59, 52);
                          popStyle();
                      popMatrix();
                      break;
                  case 1: //Sage
                      pushMatrix();
                          pushStyle();
                              //face
                              noStroke();
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 5);
                                  bezierVertex(65, 4, 86, 15, 91, 34);
                                  bezierVertex(98, 60, 87, 76, 74, 77);
                                  bezierVertex(32, 88, 12, 74, 11, 52);
                                  bezierVertex(8, 32, 20, 12, 50, 5);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 3);
                                  bezierVertex(69, 3, 88, 8, 97, 32);
                                  bezierVertex(102, 58, 101, 82, 100, 101);
                                  bezierVertex(99, 110, 100, 115, 90, 118);
                                  bezierVertex(79, 116, 80, 109, 78, 108);
                                  bezierVertex(77, 110, 70, 117, 62, 119);
                                  bezierVertex(52, 119, 48, 114, 44, 106);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 3, 50, 3);
                              endShape(CLOSE);

                              //glasses
                              noFill();
                              stroke(206, 114, 30);
                              strokeWeight(4);
                              beginShape();
                                  vertex(21, 15);
                                  bezierVertex(48, 12, 69, 9, 83, 6);
                                  bezierVertex(85, 18, 82, 23, 74, 26);
                                  bezierVertex(65, 27, 62, 22, 58, 15);
                                  bezierVertex(58, 22, 56, 33, 43, 34);
                                  bezierVertex(31, 34, 25, 25, 21, 16);
                              endShape(CLOSE);
                              strokeWeight(2);
                              line(24, 22, 58, 17);
                              line(28, 28, 56, 23);

                              line(61, 16, 84, 12);
                              line(63, 23, 83, 17);

                              //mouth
                              noFill();
                              stroke(0, 97, 0, 100);
                              strokeWeight(3);
                              bezier(23, 33, 32, 46, 44, 43, 49, 41);
                          popStyle();
                      popMatrix();
                      break;
                  case 2: //Kelly
                      pushMatrix();
                          pushStyle();
                              noStroke();

                              //face
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 5);
                                  bezierVertex(65, 4, 86, 15, 91, 34);
                                  bezierVertex(94, 58, 82, 68, 63, 73);
                                  bezierVertex(36, 77, 16, 72, 11, 52);
                                  bezierVertex(8, 32, 20, 12, 50, 5);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 3);
                                  bezierVertex(69, 3, 88, 8, 97, 32);
                                  bezierVertex(100, 58, 93, 82, 100, 101);
                                  bezierVertex(101, 110, 100, 115, 90, 118);
                                  bezierVertex(77, 116, 77, 109, 74, 103);
                                  bezierVertex(74, 110, 67, 117, 59, 119);
                                  bezierVertex(47, 119, 43, 114, 39, 96);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 3, 50, 3);
                              endShape(CLOSE);

                              //eyes
                              noStroke();
                              fill(0, 97, 0);
                              ellipse(44, 21, 21, 19);
                              ellipse(65, 20, 21, 19);

                              //eyeballs
                              fill(174, 255, 174);
                              ellipse(47, 22, 8, 7);
                              ellipse(62, 21, 8, 7);

                              //mouth
                              noStroke();
                              fill(0, 97, 0, 100);
                              beginShape();
                                  vertex(35, 33);
                                  bezierVertex(42, 33, 45, 44, 55, 43);
                                  bezierVertex(61, 43, 64, 49, 62, 54);
                                  bezierVertex(55, 60, 43, 57, 33, 52);
                                  bezierVertex(27, 43, 29, 36, 35, 33);
                              endShape(CLOSE);
                          popStyle();
                      popMatrix();
                      break;
                  case 3: //Olive
                      pushMatrix();
                          pushStyle();
                              //ears
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(67, 14);
                                  bezierVertex(72, 8, 79, 7, 85, 5);
                                  bezierVertex(89, 15, 91, 21, 90, 29);
                              endShape(CLOSE);

                              beginShape();
                                  vertex(37, 17);
                                  bezierVertex(30, 10, 22, 8, 15, 7);
                                  bezierVertex(11, 19, 17, 31, 20, 38);
                              endShape(CLOSE);

                              //face
                              noStroke();
                              fill(255, 255, 255);
                              beginShape();
                                  vertex(50, 12);
                                  bezierVertex(65, 10, 86, 15, 91, 34);
                                  bezierVertex(97, 58, 82, 68, 63, 71);
                                  bezierVertex(36, 74, 16, 68, 11, 52);
                                  bezierVertex(8, 32, 20, 17, 50, 12);
                              endShape(CLOSE);

                              //body
                              fill(131, 255, 174, 150);
                              stroke(20, 104, 26, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(50, 7);
                                  bezierVertex(69, 7, 88, 8, 97, 32);
                                  bezierVertex(102, 58, 101, 82, 100, 101);
                                  bezierVertex(99, 110, 100, 115, 90, 118);
                                  bezierVertex(79, 116, 80, 109, 79, 103);
                                  bezierVertex(77, 110, 70, 117, 62, 119);
                                  bezierVertex(52, 119, 48, 114, 44, 106);
                                  bezierVertex(42, 112, 32, 120, 20, 116);
                                  bezierVertex(13, 113, 9, 104, 9, 95);
                                  bezierVertex(11, 79, 6, 70, 5, 47);
                                  bezierVertex(4, 24, 23, 8, 50, 7);
                              endShape(CLOSE);

                              //eyes
                              noStroke();
                              fill(0, 97, 0);
                              ellipse(32, 28, 10, 9);
                              ellipse(74, 24, 10, 9);

                              //mouth
                              noFill();
                              stroke(0, 97, 0, 100);
                              strokeWeight(3);
                              bezier(46, 32, 48, 36, 53, 36, 55, 32);
                              bezier(55, 33, 58, 35, 62, 36, 63, 30);

                              //fish
                              //head
                              noStroke();
                              fill(127, 136, 117);
                              beginShape();
                                  vertex(55, 36);
                                  bezierVertex(67, 42, 74, 48, 71, 53);
                                  bezierVertex(60, 55, 50, 55, 46, 54);
                                  bezierVertex(45, 51, 51, 43, 55, 36);
                              endShape(CLOSE);
                              fill(177, 185, 157);
                              beginShape();
                                  vertex(55, 36);
                                  bezierVertex(67, 42, 74, 48, 71, 52);
                                  bezierVertex(56, 53, 59, 55, 55, 36);
                              endShape(CLOSE);

                              //eye
                              noStroke();
                              fill(61, 60, 61);
                              ellipse(52, 49, 5, 5);

                              //tail
                              fill(177, 185, 157);
                              beginShape();
                                  vertex(58, 71);
                                  bezierVertex(62, 71, 68, 73, 72, 77);
                                  bezierVertex(67, 78, 60, 77, 58, 71);
                              endShape(CLOSE);
                              fill(127, 136, 117);
                              beginShape();
                                  vertex(58, 71);
                                  bezierVertex(56, 77, 52, 80, 49, 80);
                                  bezierVertex(45, 79, 47, 74, 58, 71);
                              endShape(CLOSE);
                              //spine
                              noFill();
                              stroke(138, 135, 138);
                              strokeWeight(2);
                              line(58, 56, 58, 71);
                              strokeWeight(2);
                              line(49, 59, 66, 58);
                              line(49, 65, 64, 65);
                          popStyle();
                      popMatrix();
                      break;
                  case 4: //Plum
                      pushMatrix();
                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255);
                              beginShape();
                                  vertex(49, 8);
                                  bezierVertex(65, 9, 82, 15, 88, 31);
                                  bezierVertex(91, 55, 80, 70, 62, 79);
                                  bezierVertex(40, 83, 17, 74, 10, 48);
                                  bezierVertex(11, 24, 27, 12, 48, 8);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(49, 3);
                                  bezierVertex(63, 2, 80, 9, 89, 23);
                                  bezierVertex(102, 43, 95, 83, 91, 108);
                                  vertex(80, 92);
                                  vertex(58, 119);
                                  vertex(41, 106);
                                  vertex(29, 117);
                                  vertex(21, 104);
                                  vertex(12, 115);
                                  bezierVertex(7, 84, 2, 53, 6, 33);
                                  bezierVertex(12, 16, 29, 6, 49, 3);
                              endShape(CLOSE);

                              //eyes
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              beginShape();
                                  vertex(57, 25);
                                  vertex(80, 22);
                                  bezierVertex(82, 30, 77, 36, 72, 36);
                                  bezierVertex(63, 36, 61, 32, 57, 25);
                              endShape(CLOSE);
                              beginShape();
                                  vertex(21, 29);
                                  vertex(53, 26);
                                  bezierVertex(54, 35, 49, 42, 40, 43);
                                  bezierVertex(28, 42, 24, 36, 21, 29);
                              endShape(CLOSE);

                              //mouth
                              beginShape();
                                  vertex(58, 46);
                                  bezierVertex(62, 45, 68, 40, 73, 43);
                                  bezierVertex(76, 50, 74, 56, 68, 61);
                                  bezierVertex(61, 64, 52, 64, 46, 60);
                                  bezierVertex(42, 55, 41, 50, 42, 47);
                                  bezierVertex(46, 45, 49, 46, 57, 46);
                              endShape(CLOSE);

                              //teeth
                              line(56, 46, 53, 62);
                              line(63, 45, 70, 60);

                              //eyeballs
                              noStroke();
                              fill(173, 73, 254, 250);
                              arc(41, 27, 14, 15, -10, 181);
                              arc(68, 24, 12, 11, -14, 181);

                              //freckles
                              strokeWeight(2);
                              stroke(255, 255, 255, 150);
                              point(34, 48);
                              point(37, 55);
                              point(29, 52);
                              point(78, 42);
                              point(81, 49);
                              point(83, 40);
                          popStyle();
                      popMatrix();
                      break;
                  case 5: //Periwinkle
                      pushMatrix();
                          translate(-3, -5);
                          scale(1.05);

                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255, 150);
                              beginShape();
                                  vertex(48, 5);
                                  bezierVertex(64, 6, 78, 13, 88, 24);
                                  bezierVertex(94, 36, 96, 48, 96, 58);
                                  vertex(90, 55);
                                  vertex(89, 63);
                                  vertex(75, 41);
                                  vertex(68, 53);
                                  vertex(53, 37);
                                  vertex(46, 52);
                                  vertex(36, 43);
                                  vertex(28, 56);
                                  vertex(20, 44);
                                  vertex(6, 62);
                                  bezierVertex(5, 48, 5, 33, 11, 22);
                                  bezierVertex(19, 12, 32, 6, 48, 5);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(45, 15);
                                  bezierVertex(59, 13, 75, 24, 83, 42);
                                  bezierVertex(87, 65, 89, 89, 91, 105);
                                  vertex(83, 101);
                                  vertex(75, 109);
                                  vertex(67, 103);
                                  vertex(58, 109);
                                  vertex(51, 104);
                                  vertex(44, 112);
                                  vertex(37, 100);
                                  vertex(25, 109);
                                  vertex(18, 98);
                                  vertex(10, 103);
                                  bezierVertex(11, 83, 10, 60, 10, 44);
                                  bezierVertex(16, 27, 29, 18, 45, 15);
                              endShape(CLOSE);

                              //mouth
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              beginShape();
                                  vertex(48, 54);
                                  bezierVertex(55, 54, 61, 57, 61, 64);
                                  bezierVertex(59, 69, 49, 72, 39, 72);
                                  bezierVertex(33, 68, 31, 59, 31, 53);
                                  bezierVertex(37, 50, 40, 50, 48, 54);
                              endShape(CLOSE);

                              //tounge
                              noStroke();
                              fill(173, 73, 255, 100);
                              beginShape();
                                  vertex(32, 60);
                                  bezierVertex(35, 54, 39, 57, 44, 59);
                                  bezierVertex(46, 60, 50, 66, 52, 70);
                                  bezierVertex(48, 71, 42, 72, 38, 71);
                                  bezierVertex(33, 66, 33, 65, 33, 62);
                              endShape(CLOSE);

                              //freckles
                              strokeWeight(2);
                              stroke(255, 255, 255, 150);
                              point(21, 53);
                              point(17, 57);
                              point(25, 59);
                              point(70, 56);
                              point(75, 49);
                              point(78, 54);
                          popStyle();
                      popMatrix();
                      break;
                  case 6: //Iris
                      pushMatrix();
                          translate(-2, -3);
                          scale(1.05);

                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255, 150);
                              beginShape();
                                  vertex(50, 9);
                                  bezierVertex(63, 9, 81, 17, 88, 32);
                                  bezierVertex(92, 55, 81, 74, 65, 81);
                                  bezierVertex(44, 85, 26, 80, 17, 68);
                                  bezierVertex(10, 52, 9, 36, 15, 24);
                                  bezierVertex(25, 14, 36, 12, 50, 9);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(48, 4);
                                  bezierVertex(66, 4, 85, 12, 92, 26);
                                  bezierVertex(98, 44, 98, 68, 91, 88);
                                  vertex(77, 116);
                                  vertex(69, 104);
                                  vertex(59, 118);
                                  vertex(43, 104);
                                  vertex(28, 115);
                                  bezierVertex(15, 89, 9, 71, 6, 51);
                                  bezierVertex(6, 36, 8, 24, 17, 16);
                                  bezierVertex(28, 8, 36, 5, 48, 4);
                              endShape(CLOSE);

                              //eye
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              ellipse(57, 39, 40, 40);

                              fill(173, 73, 255, 200);
                              stroke(219, 81, 251, 70);
                              ellipse(58, 39, 20, 20);

                              noStroke();
                              fill(255, 255, 255, 200);
                              ellipse(54, 36, 6, 6);

                              //mouth
                              noFill();
                              stroke(255, 255, 255, 200);
                              arc(59, 62, 18, 16, -4, 174);

                              //headband
                              noStroke();
                              fill(173, 73, 255, 200);
                              beginShape();
                                  vertex(7, 24);
                                  bezierVertex(34, 17, 68, 12, 87, 15);
                                  vertex(94, 26);
                                  bezierVertex(56, 26, 21, 31, 4, 36);
                              endShape(CLOSE);
                          popStyle();
                      popMatrix();
                      break;
                  case 7: //Mulberry
                      pushMatrix();
                          pushStyle();
                              //head
                              noStroke();
                              fill(173, 73, 255, 150);
                              beginShape();
                                  vertex(38, 12);
                                  bezierVertex(52, 11, 66, 13, 74, 17);
                                  bezierVertex(78, 20, 80, 25, 78, 30);
                                  bezierVertex(77, 40, 71, 56, 64, 64);
                                  bezierVertex(55, 71, 40, 73, 21, 67);
                                  bezierVertex(8, 59, 6, 44, 9, 31);
                                  bezierVertex(14, 19, 27, 15, 36, 12);
                              endShape(CLOSE);

                              //body
                              fill(220, 123, 254, 150);
                              stroke(219, 81, 251, 70);
                              strokeWeight(8);
                              beginShape();
                                  vertex(96, 14);
                                  vertex(79, 39);
                                  bezierVertex(91, 57, 100, 90, 98, 112);
                                  vertex(74, 89);
                                  vertex(61, 116);
                                  vertex(36, 96);
                                  vertex(13, 115);
                                  bezierVertex(4, 92, 2, 73, 1, 48);
                                  bezierVertex(3, 31, 6, 13, 26, 7);
                                  bezierVertex(45, 1, 71, 4, 96, 14);
                              endShape(CLOSE);

                              //eyes
                              strokeWeight(2);
                              fill(255, 255, 255, 200);
                              ellipse(31, 28, 26, 26);
                              ellipse(56, 21, 21, 21);

                              //eyeballs
                              noStroke();
                              fill(173, 73, 254, 250);
                              ellipse(33, 27, 14, 14);
                              ellipse(54, 21, 11, 11);

                              //nose
                              ellipse(92, 14, 14, 14);

                              //tounge
                              beginShape();
                                  vertex(32, 48);
                                  bezierVertex(36, 52, 41, 53, 48, 55);
                                  bezierVertex(46, 64, 44, 69, 36, 70);
                                  bezierVertex(28, 68, 26, 60, 30, 48);
                              endShape(CLOSE);

                              //mouth
                              noFill();
                              strokeWeight(2);
                              stroke(173, 73, 254, 250);
                              bezier(28, 46, 32, 49, 49, 57, 54, 54);
                          popStyle();
                      popMatrix();
                      break;
              }
          };
      };
      var Spirit = function(config) {
          this.headColor = config.headColor;
          this.bodyColor = config.bodyColor;
          this.bodyStroke = config.bodyStroke;

          this.draw = function() {
              pushStyle();
                  noStroke();
                  fill(173, 73, 255, 150);
                  fill(this.headColor);
                  ellipse(40, 79, 70, 55);

                  fill(220, 123, 254, 150);
                  fill(this.bodyColor);
                  stroke(219, 81, 251, 70);
                  stroke(this.bodyStroke);
                  strokeWeight(8);
                  beginShape();
                      vertex(42, 35);
                      bezierVertex(56, 48, 61, 48, 75, 65);
                      bezierVertex(78, 74, 78, 88, 71, 97);
                      bezierVertex(68, 103, 56, 104, 52, 107);
                      bezierVertex(34, 107, 16, 105, 12, 100);
                      bezierVertex(3, 89, 1, 76, 12, 58);
                      bezierVertex(17, 51, 36, 41, 42, 35);
                  endShape(CLOSE);

                  noStroke();
                  fill(40, 100);
                  ellipse(28, 71, 10, 10);
                  ellipse(50, 71, 10, 10);
                  strokeWeight(1);
              popStyle();
          };
      };
      var Web = function(config) {
          this.x = config.x || 0;
          this.y = config.y || 0;
          this.scale = config.scale || {
              x: 1,
              y: 1
          };
          this.color = color(184, 182, 184);
          this.draw = function() {
              noFill();
              strokeWeight(1);
              stroke(this.color);

              pushMatrix();
                  translate(this.x, this.y);
                  scale(this.scale.x, this.scale.y);

                  beginShape();
                      vertex(320, 80);
                      bezierVertex(280, 53, 270, 53, 220, 0);
                  endShape();
                  beginShape();
                      vertex(320, 80);
                      bezierVertex(320, 63, 300, 53, 290, 0);
                  endShape();
                  beginShape();
                      vertex(320, 80);
                      bezierVertex(330, 63, 320, 55, 350, 0);
                  endShape();
                  beginShape();
                      vertex(320, 80);
                      bezierVertex(340, 78, 345, 72, 400, 42);
                  endShape();
                  beginShape();
                      vertex(320, 80);
                      bezierVertex(345, 98, 355, 98, 400, 110);
                  endShape();
                  beginShape();
                      vertex(320, 80);
                      bezierVertex(335, 118, 345, 128, 400, 190);
                  endShape();

                  //first row
                  beginShape();
                      vertex(287, 58);
                      bezierVertex(298, 56, 300, 56, 305, 46);
                  endShape();
                  beginShape();
                      vertex(305, 46);
                      bezierVertex(312, 56, 320, 56, 329, 50);
                  endShape();
                  beginShape();
                      vertex(329, 50);
                      bezierVertex(335, 66, 335, 66, 344, 73);
                  endShape();
                  beginShape();
                      vertex(344, 73);
                      bezierVertex(340, 76, 340, 80, 346, 95);
                  endShape();
                  beginShape();
                      vertex(346, 95);
                      bezierVertex(338, 104, 338, 97, 339, 116);
                  endShape();

                  //second row
                  beginShape();
                      vertex(260, 38);
                      bezierVertex(280, 37, 285, 35, 296, 23);
                  endShape();
                  beginShape();
                      vertex(296, 23);
                      bezierVertex(310, 35, 320, 33, 338, 26);
                  endShape();
                  beginShape();
                      vertex(338, 26);
                      bezierVertex(340, 45, 350, 52, 368, 61);
                  endShape();
                  beginShape();
                      vertex(368, 61);
                      bezierVertex(355, 80, 360, 82, 371, 102);
                  endShape();
                  beginShape();
                      vertex(371, 102);
                      bezierVertex(355, 120, 360, 122, 357, 139);
                  endShape();

                  //third row
                  beginShape();
                      vertex(235, 16);
                      bezierVertex(270, 17, 280, 15, 290, 0);
                  endShape();
                  beginShape();
                      vertex(290, 0);
                      bezierVertex(315, 17, 330, 15, 347, 5);
                  endShape();
                  beginShape();
                      vertex(347, 5);
                      bezierVertex(360, 37, 350, 35, 392, 47);
                  endShape();
                  beginShape();
                      vertex(392, 47);
                      bezierVertex(380, 67, 370, 90, 395, 108);
                  endShape();
                  beginShape();
                      vertex(395, 108);
                      bezierVertex(380, 117, 370, 140, 378, 165);
                  endShape();

                  //forth row
                  beginShape();
                      vertex(372, 0);
                      bezierVertex(380, 27, 385, 25, 400, 26);
                  endShape();
                  beginShape();
                      vertex(400, 137);
                      bezierVertex(384, 163, 392, 175, 393, 182);
                  endShape();
              popMatrix();
          };
      };
      var Spider = function(config) {
          pushMatrix();
              translate(config.x, config.y);

              noStroke();
              fill(20, config.opacity || 255);

              //body
              ellipse(350, 220, 20, 25);
              //head
              ellipse(350, 237, 10, 10);

              //stripe
              noFill();
              stroke(config.color, 100);
              strokeWeight(3);
              ellipse(350, 216, 3, 8);
              ellipse(350, 223, 2, 2);

              noFill();
              stroke(20, config.opacity || 255);
              strokeWeight(2);

              //eyes
              line(348, 240, 348, 242);
              line(352, 240, 352, 242);

              strokeWeight(1);

              //back legs
              beginShape();
                  vertex(340, 220);
                  bezierVertex(325, 210, 326, 206, 326, 199);
              endShape();
              beginShape();
                  vertex(360, 220);
                  bezierVertex(375, 210, 374, 206, 374, 199);
              endShape();

              beginShape();
                  vertex(341, 212);
                  bezierVertex(327, 202, 334, 196, 333, 190);
              endShape();
              beginShape();
                  vertex(359, 212);
                  bezierVertex(373, 202, 366, 196, 367, 190);
              endShape();

              //front legs
              beginShape();
                  vertex(340, 223);
                  bezierVertex(336, 225, 336, 228, 328, 230);
              endShape();
              beginShape();
                  vertex(328, 230);
                  bezierVertex(332, 250, 332, 248, 334, 250);
              endShape();

              beginShape();
                  vertex(360, 223);
                  bezierVertex(364, 225, 364, 228, 372, 230);
              endShape();
              beginShape();
                  vertex(372, 230);
                  bezierVertex(368, 250, 368, 248, 366, 250);
              endShape();

              beginShape();
                  vertex(342, 227);
                  bezierVertex(340, 229, 340, 232, 334, 234);
              endShape();
              beginShape();
                  vertex(334, 234);
                  bezierVertex(338, 254, 343, 252, 342, 255);
              endShape();

              beginShape();
                  vertex(358, 227);
                  bezierVertex(360, 229, 360, 232, 366, 234);
              endShape();
              beginShape();
                  vertex(366, 234);
                  bezierVertex(362, 254, 357, 252, 358, 255);
              endShape();
          popMatrix();
      };

      var AI = function(config) {
          this.x = config.x || 300;
          this.y = config.y || 300;
          this.vx = 0;
          this.vy = 0;
          this.px = this.x;
          this.py = this.y;
          this.w = config.w || 40;
          this.h = config.h || 40;
          this.angle = config.angle || 0;
          this.segments = [];
          this.SPEED_MIN = config.SPEED_MIN || 4;
          this.SPEED_MAX = config.SPEED_MAX || 6;
          this.speed = this.SPEED_MIN;
          this.dir = 0;
          this.faceDir = 1;
          this.color = config.color || game.COLORS.purple;
          this.REACH_MIN = config.REACH_MIN || this.w * 0.5;
          this.REACH_MAX = config.REACH_MAX || this.w * 2;
          this.reach = this.REACH_MIN;
          this.GEM_TIMER = config.GEM_TIMER || 300;
          this.gemTimer = config.gemTimer || 0;
          this.SPEED_TIMER = config.SPEED_TIMER || 300;
          this.speedTimer = config.speedTimer || 0;
          this.points = 0;
          this.team = config.team || 0; // 0 = GREEN, 1 = Purple
          this.index = config.index || 0; //0-3 = index of the ghost
          this.target = {
              x: 0,
              y: 0
          };
          this.hasTargetGem = false;
          this.counter = 1;
          this.img = config.img || undefined;
          this.spiritImg = config.spiritImg || undefined;
          this.init();
      };
      AI.new = function(config) {
          var obj = Object.create(AI.prototype);
          AI.apply(obj, arguments);
          return obj;
      };
      AI.prototype.init = function() {
          this.segments.length = 0;
      };
      AI.prototype.update = function() {
          this.hasTargetGem = false;

          this.target.x = ~~random(game.world.w);
          this.target.y = ~~random(game.world.h);

          this.angle = atan2(this.target.y - this.y, this.target.x - this.x);

          this.vx = this.speed * cos(this.angle);
          this.vy = this.speed * sin(this.angle);

          if(this.gemTimer > 0) {
              this.gemTimer = constrain(this.gemTimer - 1, 0, this.GEM_TIMER);
              if(this.gemTimer === 0) {
                  this.reach = this.REACH_MIN;
              }
          }
          if(this.speedTimer > 0) {
              this.speedTimer = constrain(this.speedTimer - 1, 0, this.SPEED_TIMER);
              if(this.speedTimer === 0) {
                  this.speed = this.SPEED_MIN;
              }
          }
      };
      AI.prototype.home = function() {
          //check to see if shoud head back to base
          var coordsArr = this.team === "GREEN" ? game.levels[game.level].coords.green : game.levels[game.level].coords.purple;

          var goingHome = false;

          for(var i = 0; i < coordsArr.length; i++) {
              var item = coordsArr[i];

              if(this.segments.length >= item.gems) {

                  if(game.collision(this, {
                      x: item.from.x * game.BLOCK_SIZE,
                      y: item.from.y * game.BLOCK_SIZE,
                      w: item.from.w * game.BLOCK_SIZE,
                      h: item.from.h * game.BLOCK_SIZE
                  })) {
                      this.target.x = item.to.x * game.BLOCK_SIZE;
                      this.target.y = item.to.y * game.BLOCK_SIZE;
                      goingHome = true;
                      break;
                  }
              }
          }

          if(goingHome) {
              this.angle = atan2(this.target.y - this.y, this.target.x - this.x);

              this.vx = (this.speed * random(0.5, 1)) * cos(this.angle);
              this.vy = (this.speed * random(0.5, 1)) * sin(this.angle);

              if(this.gemTimer > 0) {
                  this.gemTimer = constrain(this.gemTimer - 1, 0, this.GEM_TIMER);
                  if(this.gemTimer === 0) {
                      this.reach = this.REACH_MIN;
                  }
              }
              if(this.speedTimer > 0) {
                  this.speedTimer = constrain(this.speedTimer - 1, 0, this.SPEED_TIMER);
                  if(this.speedTimer === 0) {
                      this.speed = this.SPEED_MIN;
                  }
              }
          }
      };
      AI.prototype.move = function() {
          this.px = this.x;
          this.py = this.y;

          if(this.counter++ % 300 === 0) {
              this.update();
          }

          if(!this.hasTargetGem && this.counter % 10 === 0) {
              this.home();
          }

          this.x += this.vx;
          this.y += this.vy;

          this.dir = this.vx === 0 ? 0 : this.vx < 0 ? -1 : 1;

          if(this.vx < 0) {
              this.faceDir = -1;
          }
          else if(this.vx > 0){
              this.faceDir = 1;
          }
      };
      AI.prototype.draw = function() {
          noStroke();

          fill(this.color, 150);
          for(var i = 0; i < this.segments.length; i++) {
              var segment = this.segments[i];

              if(i === 0) {
                  segment.x = this.x + this.w / 2;
                  segment.y = this.y + this.h / 2;
              }
              else {
                  segment.x = lerp(segment.x, this.segments[i-1].x, 0.15);
                  segment.y = lerp(segment.y, this.segments[i-1].y, 0.15);
              }

              image(this.spiritImg, segment.x - segment.w * 0.25, segment.y - segment.h * 0.25, segment.w, segment.h);
          }

          pushMatrix();
              translate(this.x + this.w / 2, this.y + this.h / 2);
              //rotate(this.angle);
              if(this.faceDir === -1) {
                  translate(this.w * 0.25, 0);
                  scale(-1, 1);
              }
              translate(-this.x-this.w / 2, -this.y-this.h / 2);

              image(this.img, this.x, this.y, this.w, this.h);
          popMatrix();
      };
      AI.prototype.run = function() {
          this.draw();
          this.move();
      };

      var Player = function(config) {
          this.x = config.x || 300;
          this.y = config.y || 300;
          this.px = this.x;
          this.py = this.y;
          this.w = config.w || 40;
          this.h = config.h || 40;
          this.angle = config.angle || 0;
          this.segments = [];
          this.SPEED_MIN = config.SPEED_MIN || 4;
          this.SPEED_MAX = config.SPEED_MAX || 6;
          this.speed = this.SPEED_MIN;
          this.dir = 0;
          this.moved = false;
          this.faceDir = 1;
          this.color = config.color;
          this.REACH_MIN = config.REACH_MIN || this.w * 0.5;
          this.REACH_MAX = config.REACH_MAX || this.w * 2;
          this.reach = this.REACH_MIN;
          this.GEM_TIMER = config.GEM_TIMER || 300;
          this.gemTimer = config.gemTimer || 0;
          this.SPEED_TIMER = config.SPEED_TIMER || 300;
          this.speedTimer = config.speedTimer || 0;
          this.LIGHT_TIMER = config.LIGHT_TIMER || 300;
          this.lightTimer = config.lightTimer || 0;
          this.LIGHT_MIN = 15;
          this.LIGHT_MAX = 40;
          this.lightRadius = this.LIGHT_MIN;
          this.points = 0;
          this.team = config.team || "";
          this.index = config.index || 0; //0-7 = index of the ghost
          this.img = config.img || undefined;
          this.spiritImg = config.spiritImg || undefined;

          this.init = function() {
              this.segments.length = 0;
              this.reach = this.REACH_MIN;
              this.gemTimer = 0;
              this.speedTimer = 0;
              this.lightTimer = 0;
              this.reach = this.REACH_MIN;
              this.lightRadius = this.LIGHT_MIN;
          };
          this.init();
          this.update = function() {
              if(this.gemTimer > 0) {
                  this.gemTimer = constrain(this.gemTimer - 1, 0, this.GEM_TIMER);
                  if(this.gemTimer === 0) {
                      this.reach = this.REACH_MIN;
                  }
              }
              if(this.speedTimer > 0) {
                  this.speedTimer = constrain(this.speedTimer - 1, 0, this.SPEED_TIMER);
                  if(this.speedTimer === 0) {
                      this.speed = this.SPEED_MIN;
                  }
              }
              if(this.lightTimer > 0) {
                  this.lightTimer = constrain(this.lightTimer - 1, 0, this.LIGHT_TIMER);
                  if(this.lightTimer === 0) {
                      this.lightRadius = this.LIGHT_MIN;
                  }
              }
          };
          this.move = function() {
              this.px = this.x;
              this.py = this.y;
              this.dir = 0;

              // if(game.mobile && mouseIsPressed) {
            if(game.mobile) {
                  if(mouseX < game.cam.x + this.x) {
                      this.x-= this.speed;
                       this.dir = -1;
                       this.faceDir = -1;
                       this.moved = true;
                  }
                  else if(mouseX > game.cam.x + this.x) {
                      this.x+= this.speed;
                      this.dir = 1;
                      this.faceDir = 1;
                      this.moved = true;
                  }

                  if(mouseY < game.cam.y + this.y) {
                      this.y-= this.speed;
                      this.moved = true;
                  }
                  else if(mouseY > game.cam.y + this.y) {
                      this.y+= this.speed;
                      this.moved = true;
                  }
              }

              if(keys[LEFT] || keys[65]) { //Left arrow or A
                   this.x-= this.speed;
                   this.dir = -1;
                   this.faceDir = -1;
                   this.moved = true;
              }
              if(keys[RIGHT] || keys[68]) { //Right arrow or D
                   this.x+= this.speed;
                   this.dir = 1;
                   this.faceDir = 1;
                   this.moved = true;
              }
              if((keys[UP] || keys[87])) { //Up arrow or W
                   this.y-= this.speed;
                   this.moved = true;
              }
              if(keys[DOWN] || keys[83]) { //Down arrow or S
                   this.y+= this.speed;
                   this.moved = true;
              }

              this.angle = lerp(this.angle, 10 * this.dir, 0.2);
          };
          this.draw = function() {
              noStroke();
              fill(this.color, 150);
              for(var i = 0; i < this.segments.length; i++) {
                  var segment = this.segments[i];

                  if(i === 0) {
                      segment.x = this.x + this.w / 2;
                      segment.y = this.y + this.h / 2;
                  }
                  else {
                      segment.x = lerp(segment.x, this.segments[i-1].x, 0.15);
                      segment.y = lerp(segment.y, this.segments[i-1].y, 0.15);
                  }

                  image(this.spiritImg, segment.x - segment.w * 0.25, segment.y - segment.h * 0.25, segment.w, segment.h);
              }

              pushMatrix();
                  translate(this.x + this.w / 2, this.y + this.h / 2);
                  rotate(radians(this.angle));
                  if(this.faceDir === -1) {
                      translate(this.w * 0.25, 0);
                      scale(-1, 1);
                  }
                  translate(-this.x-this.w / 2, -this.y-this.h / 2);

                  image(this.img, this.x, this.y, this.w, this.h);
              popMatrix();
          };
          this.run = function() {
              this.draw();
              this.move();
              this.update();
          };
      };

      var Transition = function(config) {
          this.h = config.h || 0;
          this.vy = 15;
          this.active = config.active || false;
          this.page = config.page || "home";

          //reset the x position back to the left of the screen
          this.reset = function() {
              this.h = 0;
              this.vy = 15;
          };
          //draw the transition - if it's currently active
          this.draw = function() {
              if(this.active) {
                  pushStyle();
                      stroke(255, 50);
                      strokeWeight(2);
                      fill(43, 43, 43);

                      rect(0, 0, width, this.h);
                      rect(0, height-this.h, width, this.h);
                  popStyle();
              }
          };
          //update the transition - if it's currently active
          this.update = function() {
              if(this.active) {
                  this.h+= this.vy;

                  //if halfway across the screen then change the scene
                  if(this.h >= 300) {
                      game.page = this.page;
                      //if(game.page === "play") {
                      //    game.init();
                      //}
                      this.vy*= -1;
                  }
                  //else if it's completely off the screen reset it and set to inactive
                  else if(this.h < 0) {
                      this.reset();
                      this.active = false;
                  }
              }
          };
          this.run = function() {
              this.draw();
              this.update();
          };
      };

      var Particle = function(config) {
          this.x = config.x;
          this.y = config.y;
          this.vx = config.vx || 0;
          this.vy = config.vy || 0;
          this.w = config.w || 5;
          this.h = config.h || this.w;
          this.color = config.color;
          this.opacity = config.opacity || 150;
          this.opacitySpeed = config.opacitySpeed || 3;
      };
      Particle.new = function(confog) {
          var obj = Object.create(Particle.prototype);
          Particle.apply(obj, arguments);
          return obj;
      };
      Particle.prototype.update = function() {
          this.x+= this.vx;
          this.y+= this.vy;
          this.opacity-= this.opacitySpeed;
      };
      Particle.prototype.draw = function() {
          noStroke();
          pushMatrix();
              translate(this.x, this.y);

              fill(this.color, this.opacity);
              ellipse(0, 0, this.w, this.h);

          popMatrix();
      };
      Particle.prototype.run = function() {
          this.draw();
          this.update();
      };

      var Block = function(config) {
          this.x = config.x || 0;
          this.y = config.y || 0;
          this.w = config.w || 40;
          this.h = config.h || 40;
      };
      Block.new = function(config) {
          var obj = Object.create(Block.prototype);
          Block.apply(obj, arguments);
          return obj;
      };
      Block.prototype.draw = function() {
          if(game.level === 1) {
              image(game.images.block, this.x, this.y, this.w, this.h);
          }
          else if(game.level === 2) {
              image(game.images.block2, this.x, this.y, this.w, this.h);
          }
          else {
              image(game.images.block3, this.x, this.y, this.w, this.h);
          }
      };
      Block.prototype.run = function() {
          this.draw();  
      };

      var Base = function(config) {
          this.x = config.x || 0;
          this.y = config.y || 0;
          this.w = config.w || 40;
          this.h = config.h || 40;
          this.team = config.team || "friend";
          this.color = config.color || color(120, 214, 136);
      };
      Base.new = function(config) {
          var obj = Object.create(Base.prototype);
          Base.apply(obj, arguments);
          return obj;
      };
      Base.prototype.draw = function() {
          if(this.team === "GREEN") {
              image(game.images.friendBase, this.x, this.y, this.w, this.h);
          }
          else {
              image(game.images.foeBase, this.x, this.y, this.w, this.h);
          }
      };
      Base.prototype.run = function() {
          this.draw();  
      };

      var Gem = function(config) {
          this.x = config.x || 0;
          this.y = config.y || 0;
          this.w = config.w || 40;
          this.h = config.h || 40;
          this.used = config.used || false;
          /*
          types are:
          - 0 = normal
          - 1 = extra speed
          - 2 = wider reach
          - 3 = visibility
          */
          this.type = config.type || ~~random(4);
      };
      Gem.new = function(config) {
          var obj = Object.create(Gem.prototype);
          Gem.apply(obj, arguments);
          return obj;
      };
      Gem.prototype.draw = function() {
          if(this.used) {
              switch(this.type) {
                  case 0: //normal gem
                      image(game.images.normalSpirit, this.x, this.y, this.w, this.h);
                      break;
                  case 1: //extra speed
                      image(game.images.speedSpirit, this.x, this.y, this.w, this.h);
                      break;
                  case 2: //wider reach
                      image(game.images.reachSpirit, this.x, this.y, this.w, this.h);
                      break;
                  case 3: //wider visibility
                      image(game.images.lightSpirit, this.x, this.y, this.w, this.h);
                      break;
              }
          }
      };
      Gem.prototype.run = function() {
          this.draw();  
      };

      //Game engine
      var Game = function(config) {
          this.page = "load";
          this.level = 1;
          this.BLOCK_SIZE = 25;
          this.COLORS = {
              green: color(105, 179, 111),
              purple: color(179, 89, 172)
          };
          this.GEM_COLORS = [
              color(55, 214, 209, 150), //normal
              color(199, 195, 72, 150), //speed
              color(235, 142, 70, 150), //reach
              color(222, 93, 136, 150)  //light
          ];
          this.player = new Player({
              w: this.BLOCK_SIZE,
              h: this.BLOCK_SIZE,
              color: this.COLORS.green
          });
          this.foes = [];
          this.friends = [];
          this.foeBases = [];
          this.friendBases = [];
          this.levels = [
              {
                  grid: [
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                      "------------------------------------------------------------",
                  ]
              }, // menu
              {
                  base: {
                      green: {
                          x: 7 * this.BLOCK_SIZE,
                          y: 14 * this.BLOCK_SIZE
                      },
                      purple: {
                          x: 30 * this.BLOCK_SIZE,
                          y: 14 * this.BLOCK_SIZE
                      }
                  },
                  coords: {
                      green: [ //green
                          {
                              gems: 2,
                              from: {
                                      x: 2,
                                      y: 4,
                                      w: 3,
                                      h: 4
                                  },
                              to: {
                                      x: 6,
                                      y: 10
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 8,
                                      y: 2,
                                      w: 2,
                                      h: 3
                                  },
                              to: {
                                      x: 8,
                                      y: 10
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 11,
                                      y: 2,
                                      w: 5,
                                      h: 3
                                  },
                              to: {
                                      x: 8,
                                      y: 4
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 11,
                                      y: 9,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 8,
                                      y: 10
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 5,
                                      y: 9,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 7,
                                      y: 14
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 22,
                                      y: 3,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 14,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 30,
                                      y: 1,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 22,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 33,
                                      y: 4,
                                      w: 3,
                                      h: 4
                                  },
                              to: {
                                      x: 32,
                                      y: 9
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 28,
                                      y: 9,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 24,
                                      y: 10
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 23,
                                      y: 9,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 23,
                                      y: 14
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 12,
                                      y: 13,
                                      w: 14,
                                      h: 3
                                  },
                              to: {
                                      x: 12,
                                      y: 18
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 12,
                                      y: 17,
                                      w: 9,
                                      h: 2
                                  },
                              to: {
                                      x: 9,
                                      y: 18
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 23,
                                      y: 18,
                                      w: 12,
                                      h: 1
                                  },
                              to: {
                                      x: 12,
                                      y: 18
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 5,
                                      y: 18,
                                      w: 5,
                                      h: 1
                                  },
                              to: {
                                      x: 7,
                                      y: 14
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 2,
                                      y: 21,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 6,
                                      y: 18
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 10,
                                      y: 21,
                                      w: 3,
                                      h: 2
                                  },
                              to: {
                                      x: 5,
                                      y: 21
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 17,
                                      y: 22,
                                      w: 4,
                                      h: 5
                                  },
                              to: {
                                      x: 16,
                                      y: 18
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 32,
                                      w: 5,
                                      h: 3
                                  },
                              to: {
                                      x: 11,
                                      y: 32
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 10,
                                      y: 32,
                                      w: 3,
                                      h: 3
                                  },
                              to: {
                                      x: 11,
                                      y: 22
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 17,
                                      y: 32,
                                      w: 17,
                                      h: 3
                                  },
                              to: {
                                      x: 11,
                                      y: 32
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 25,
                                      y: 22,
                                      w: 3,
                                      h: 8
                                  },
                              to: {
                                      x: 25,
                                      y: 33
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 31,
                                      y: 21,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 31,
                                      y: 18
                                  }
                          }
                      ],
                      purple: [ //purple
                          {
                              gems: 2,
                              from: {
                                      x: 33,
                                      y: 4,
                                      w: 3,
                                      h: 4
                                  },
                              to: {
                                      x: 31,
                                      y: 10
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 28,
                                      y: 2,
                                      w: 2,
                                      h: 3
                                  },
                              to: {
                                      x: 28,
                                      y: 10
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 22,
                                      y: 2,
                                      w: 5,
                                      h: 3
                                  },
                              to: {
                                      x: 29,
                                      y: 4
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 23,
                                      y: 9,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 30,
                                      y: 10
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 28,
                                      y: 9,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 30,
                                      y: 14
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 11,
                                      y: 3,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 23,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 4,
                                      y: 1,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 15,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 4,
                                      w: 3,
                                      h: 4
                                  },
                              to: {
                                      x: 5,
                                      y: 9
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 5,
                                      y: 9,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 13,
                                      y: 10
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 11,
                                      y: 9,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 14,
                                      y: 14
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 12,
                                      y: 13,
                                      w: 14,
                                      h: 3
                                  },
                              to: {
                                      x: 25,
                                      y: 18
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 17,
                                      y: 17,
                                      w: 9,
                                      h: 2
                                  },
                              to: {
                                      x: 28,
                                      y: 18
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 3,
                                      y: 18,
                                      w: 12,
                                      h: 1
                                  },
                              to: {
                                      x: 25,
                                      y: 18
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 28,
                                      y: 18,
                                      w: 5,
                                      h: 1
                                  },
                              to: {
                                      x: 30,
                                      y: 14
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 31,
                                      y: 21,
                                      w: 5,
                                      h: 2
                                  },
                              to: {
                                      x: 31,
                                      y: 18
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 25,
                                      y: 21,
                                      w: 3,
                                      h: 2
                                  },
                              to: {
                                      x: 32,
                                      y: 21
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 17,
                                      y: 22,
                                      w: 4,
                                      h: 5
                                  },
                              to: {
                                      x: 21,
                                      y: 18
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 31,
                                      y: 32,
                                      w: 5,
                                      h: 3
                                  },
                              to: {
                                      x: 26,
                                      y: 32
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 25,
                                      y: 32,
                                      w: 3,
                                      h: 3
                                  },
                              to: {
                                      x: 26,
                                      y: 22
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 4,
                                      y: 32,
                                      w: 17,
                                      h: 3
                                  },
                              to: {
                                      x: 26,
                                      y: 32
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 10,
                                      y: 22,
                                      w: 3,
                                      h: 8
                                  },
                              to: {
                                      x: 12,
                                      y: 33
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 3,
                                      y: 21,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 6,
                                      y: 18
                                  }
                          }
                      ]
                  },
                  grid: [
                      "BBBBBBBBBBBBBBBBBB  BBBBBBBBBBBBBBBBBB",
                      "B----------------B  B----------------B",
                      "B----G-G-G-G-G---BBBB---G-G-G-G-G----B",
                      "B-G--------------------------------G-B",
                      "B-----B--G-G---G-G--G-G---G-G--B-----B",
                      "B-G---B------------------------B---G-B",
                      "B-----B----BBB---G-G----BBB----B-----B",
                      "B-G--------------------------------G-B",
                      "B----------------B--B----------------B",
                      "B-G--------------B--B--------------G-B",
                      "B----------------B--B----------------B",
                      "B----------------B--B----------------B",
                      "B---BFFFFFB----------------BEEEEEB---B",
                      "B---BFF2FFB----------------BEE6EEB---B",
                      "B---BF1F3FB--G-G-G--G-G-G--BE5E7EB---B",
                      "B---BFF4FFB----------------BEE8EEB---B",
                      "B---BFFFFFB----------------BEEEEEB---B",
                      "B------------------------------------B",
                      "B------------G-G-G--G-G-G------------B",
                      "B------------------------------------B",
                      "B-------BBBBBBB--G--G--BBBBBBB-------B",
                      "B-G-G-G-------B--------B-------G-G-G-B",
                      "B-------------B--G--G--B-------------B",
                      "B----------G--B--------B--G----------B",
                      "BBBBBBBBB-----B--G--G--B-----BBBBBBBBB",
                      "        B--G--B--------B--G--B        ",
                      "        B-----B--G--G--B-----B        ",
                      "        B--G--B--------B--G--B        ",
                      "        B-----B--G--G--B-----B        ",
                      "BBBBBBBBB--G--B--------B--G--BBBBBBBBB",
                      "B-------------BBB----BBB-------------B",
                      "B----------G--------------G----------B",
                      "B--G-G-G----------------------G-G-G--B",
                      "B------------------------------------B",
                      "B------------------------------------B",
                      "B--G-G-G-----G-G-G--G-G-G-----G-G-G--B",
                      "B------------------------------------B",
                      "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
                  ]
              }, // level 1
              {
                  base: {
                      green: {
                          x: 13 * this.BLOCK_SIZE,
                          y: 19 * this.BLOCK_SIZE
                      },
                      purple: {
                          x: 26 * this.BLOCK_SIZE,
                          y: 19 * this.BLOCK_SIZE
                      }
                  },
                  coords: {
                      green: [ //green
                          {
                              gems: 2,
                              from: {
                                      x: 18,
                                      y: 17,
                                      w: 4,
                                      h: 5
                                  },
                              to: {
                                      x: 13,
                                      y: 19
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 4,
                                      y: 2,
                                      w: 3,
                                      h: 1
                                  },
                              to: {
                                      x: 11,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 10,
                                      y: 4,
                                      w: 3,
                                      h: 5
                                  },
                              to: {
                                      x: 11,
                                      y: 12
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 6,
                                      y: 12,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 19,
                                      y: 13
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 10,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 9,
                                      y: 12
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 15,
                                      y: 4,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 11,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 4,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 28,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 27,
                                      y: 4,
                                      w: 3,
                                      h: 5
                                  },
                              to: {
                                      x: 28,
                                      y: 12
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 33,
                                      y: 2,
                                      w: 3,
                                      h: 1
                                  },
                              to: {
                                      x: 24,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 37,
                                      y: 10,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 29,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 27,
                                      y: 12,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 17,
                                      y: 12,
                                      w: 6,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 19
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 7,
                                      y: 16,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 8,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 7,
                                      y: 20,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 8,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 32,
                                      y: 16,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 31,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 32,
                                      y: 20,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 31,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 7,
                                      y: 25,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 19,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 26,
                                      y: 25,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 17,
                                      y: 25,
                                      w: 6,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 20
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 27,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 9,
                                      y: 25
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 37,
                                      y: 27,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 30,
                                      y: 25
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 2,
                                      y: 35,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 27,
                                      y: 2
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 37,
                                      y: 35,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 30,
                                      y: 27
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 5,
                                      y: 35,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 11,
                                      y: 35
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 31,
                                      y: 35,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 28,
                                      y: 35
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 10,
                                      y: 30,
                                      w: 3,
                                      h: 6
                                  },
                              to: {
                                      x: 11,
                                      y: 26
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 27,
                                      y: 30,
                                      w: 3,
                                      h: 6
                                  },
                              to: {
                                      x: 28,
                                      y: 26
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 15,
                                      y: 35,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 11,
                                      y: 35
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 21,
                                      y: 35,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 28,
                                      y: 35
                                  }
                          }
                      ],
                      purple: [ //purple
                          {
                              gems: 2,
                              from: {
                                      x: 18,
                                      y: 17,
                                      w: 4,
                                      h: 5
                                  },
                              to: {
                                  x: 26,
                                  y: 19
                              }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 4,
                                      y: 2,
                                      w: 3,
                                      h: 1
                                  },
                              to: {
                                      x: 11,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 10,
                                      y: 4,
                                      w: 3,
                                      h: 5
                                  },
                              to: {
                                      x: 11,
                                      y: 12
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 6,
                                      y: 12,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 19,
                                      y: 13
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 10,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 9,
                                      y: 12
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 15,
                                      y: 4,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 11,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 4,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 28,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 27,
                                      y: 4,
                                      w: 3,
                                      h: 5
                                  },
                              to: {
                                      x: 28,
                                      y: 12
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 33,
                                      y: 2,
                                      w: 3,
                                      h: 1
                                  },
                              to: {
                                      x: 24,
                                      y: 4
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 37,
                                      y: 10,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 29,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 27,
                                      y: 12,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 17,
                                      y: 12,
                                      w: 6,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 19
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 7,
                                      y: 16,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 8,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 7,
                                      y: 20,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 8,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 32,
                                      y: 16,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 31,
                                      y: 12
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 32,
                                      y: 20,
                                      w: 1,
                                      h: 3
                                  },
                              to: {
                                      x: 31,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 7,
                                      y: 25,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 19,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 26,
                                      y: 25,
                                      w: 7,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 25
                                  }
                          },
                          {
                              gems: 2,
                              from: {
                                      x: 17,
                                      y: 25,
                                      w: 6,
                                      h: 2
                                  },
                              to: {
                                      x: 20,
                                      y: 20
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 2,
                                      y: 27,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 9,
                                      y: 25
                                  }
                          },
                          {
                              gems: 3,
                              from: {
                                      x: 37,
                                      y: 27,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 30,
                                      y: 25
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 2,
                                      y: 35,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 27,
                                      y: 2
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 37,
                                      y: 35,
                                      w: 1,
                                      h: 2
                                  },
                              to: {
                                      x: 30,
                                      y: 27
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 5,
                                      y: 35,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 11,
                                      y: 35
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 31,
                                      y: 35,
                                      w: 4,
                                      h: 2
                                  },
                              to: {
                                      x: 28,
                                      y: 35
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 10,
                                      y: 30,
                                      w: 3,
                                      h: 6
                                  },
                              to: {
                                      x: 11,
                                      y: 26
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 27,
                                      y: 30,
                                      w: 3,
                                      h: 6
                                  },
                              to: {
                                      x: 28,
                                      y: 26
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 15,
                                      y: 35,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 11,
                                      y: 35
                                  }
                          },
                          {
                              gems: 4,
                              from: {
                                      x: 21,
                                      y: 35,
                                      w: 4,
                                      h: 1
                                  },
                              to: {
                                      x: 28,
                                      y: 35
                                  }
                          }
                      ]
                  },
                  grid: [
                      "BBBBBBBBBBBB                BBBBBBBBBBBB",
                      "B----------B                B----------B",
                      "B---G-G-G--BBBBBBBBBBBBBBBBBB--G-G-G---B",
                      "B--------------------------------------B",
                      "B-G--------G-G-G-G-G-G-G-G-G---------G-B",
                      "B----BBBB----------------------BBBB----B",
                      "B-G--B  B--G----------------G--B  B--G-B",
                      "B----B  B-----BBBBBBBBBBBB-----B  B----B",
                      "B-G--BBBB--G--B          B--G--BBBB--G-B",
                      "B-------------B          B-------------B",
                      "B-G-G-G-G-----BBBBBBBBBBBB-----G-G-G-G-B",
                      "B--------------------------------------B",
                      "B-------G--G--G-G-G--G-G-G--G--G-------B",
                      "BBBBB------------------------------BBBBB",
                      "    B------------------------------B    ",
                      "    B--G------------------------G--B    ",
                      "    B-----BBBBBB--------BBBBBB-----B    ",
                      "    B--G--BFFFFF--------EEEEEB--G--B    ",
                      "    B-----BF1F2F--------E5E6EB-----B    ",
                      "    B--G--BFFFFF--------EEEEEB--G--B    ",
                      "    B-----BF4F3F--------E7E8EB-----B    ",
                      "    B--G--BFFFFF--------EEEEEB--G--B    ",
                      "    B-----BBBBBB--------BBBBBB-----B    ",
                      "    B--G------------------------G--B    ",
                      "    B------------------------------B    ",
                      "BBBBB------G---G-G-G-G-G----G------BBBBB",
                      "B--------------------------------------B",
                      "B-G-G-G----G---G-G-G-G-G----G----G-G-G-B",
                      "B--------------------------------------B",
                      "B-G--BBBB--G--BBBBBBBBBBBB--G--BBBB--G-B",
                      "B----B  B-----B          B-----B  B----B",
                      "B-G--B  B--G--B          B--G--B  B--G-B",
                      "B----B  B-----BBBBBBBBBBBB-----B  B----B",
                      "B-G--BBBB--G----------------G--BBBB--G-B",
                      "B--------------------------------------B",
                      "B-G-----G--G--G-G-G-G-G-G---G--G-----G-B",
                      "B--------------------------------------B",
                      "B---G-G-G--BBBBBBBBBBBBBBBBBB--G-G-G---B",
                      "B----------B                B----------B",
                      "BBBBBBBBBBBB                BBBBBBBBBBBB"
                      ]
              }, // level 2
              {
                  base: {
                      green: {
                          x: 16 * this.BLOCK_SIZE,
                          y: 15 * this.BLOCK_SIZE
                      },
                      purple: {
                          x: 22 * this.BLOCK_SIZE,
                          y: 15 * this.BLOCK_SIZE
                      }
                  },
                  coords: {
                      green: [ //green
                          {
                              gems: 4,
                              from: {
                                      x: 7,
                                      y: 4,
                                      w: 3,
                                      h: 2
                                  },
                              to: {
                                      x: 12,
                                      y: 7
                                  }
                          },
                          {
                              gems: 4,
                              from: {
               .........完整代码请登录后点击上方下载按钮下载查看

网友评论0