home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2005 July / Game.EXE_07_2005_DVD.iso / Flash / Tilt Maze / tilt.swf / scripts / frame_2 / DoAction.as
Encoding:
Text File  |  2005-05-13  |  12.2 KB  |  327 lines

  1. function buildMap(map, exit)
  2. {
  3.    var _loc3_ = map;
  4.    getwh(level);
  5.    mapWidth = _loc3_[0].length;
  6.    mapHeight = _loc3_.length;
  7.    var _loc2_ = 0;
  8.    while(_loc2_ < mapHeight)
  9.    {
  10.       var _loc1_ = 0;
  11.       while(_loc1_ < mapWidth)
  12.       {
  13.          this.attachMovie("tile","t_" + _loc2_ + "_" + _loc1_,++d);
  14.          t = this["t_" + _loc2_ + "_" + _loc1_];
  15.          t._height = tileH;
  16.          t._width = tileW;
  17.          t._x = _loc1_ * tileW;
  18.          t._y = _loc2_ * tileH;
  19.          t.w_0._visible = Number(_loc3_[_loc2_][_loc1_].substr(0,1));
  20.          t.w_1._visible = Number(_loc3_[_loc2_][_loc1_].substr(1,1));
  21.          t.w_2._visible = Number(_loc3_[_loc2_][_loc1_].substr(2,1));
  22.          t.w_3._visible = Number(_loc3_[_loc2_][_loc1_].substr(3,1));
  23.          t.exit._visible = false;
  24.          _loc1_ = _loc1_ + 1;
  25.       }
  26.       _loc2_ = _loc2_ + 1;
  27.    }
  28.    var c = 0;
  29.    while(c < exit.length)
  30.    {
  31.       var x = exit[c][0];
  32.       var y = exit[c][1];
  33.       this["t_" + y + "_" + x].exit._visible = true;
  34.       c++;
  35.    }
  36. }
  37. function createBall(x, y)
  38. {
  39.    var _loc1_ = this;
  40.    _loc1_.attachMovie("ball","ball" + w,++w);
  41.    var bounds = _loc1_["b" + w].getBounds(_loc1_);
  42.    var tilex = tileW * x + bounds.xMax;
  43.    var tiley = tileH * y + bounds.yMax;
  44.    b = _loc1_["ball" + w];
  45.    b._height = tileH;
  46.    b._width = tileW;
  47.    b._x = tilex;
  48.    b._y = tiley;
  49.    b.onEnterFrame = function()
  50.    {
  51.       var _loc1_ = this;
  52.       if(moveRight)
  53.       {
  54.          _loc1_._x += step;
  55.          counter++;
  56.          if(counter == 4)
  57.          {
  58.             moveRight = false;
  59.             playGame = true;
  60.          }
  61.       }
  62.       if(moveLeft)
  63.       {
  64.          _loc1_._x -= step;
  65.          counter++;
  66.          if(counter == 4)
  67.          {
  68.             moveLeft = false;
  69.             playGame = true;
  70.          }
  71.       }
  72.       if(moveDown)
  73.       {
  74.          _loc1_._y += step;
  75.          counter++;
  76.          if(counter == 4)
  77.          {
  78.             moveDown = false;
  79.             playGame = true;
  80.          }
  81.       }
  82.       if(moveUp)
  83.       {
  84.          _loc1_._y -= step;
  85.          counter++;
  86.          if(counter == 4)
  87.          {
  88.             moveUp = false;
  89.             playGame = true;
  90.          }
  91.       }
  92.       if(playGame)
  93.       {
  94.          var dy = Math.floor((_loc1_._y + tileH) / tileH);
  95.          var uy = Math.floor((_loc1_._y - tileH) / tileH);
  96.          var lx = Math.floor((_loc1_._x - tileW) / tileW);
  97.          var rx = Math.floor((_loc1_._x + tileW) / tileW);
  98.          var _loc3_ = Math.floor(_loc1_._x / tileW);
  99.          var _loc2_ = Math.floor(_loc1_._y / tileH);
  100.          if(_loc1_.direction == "right")
  101.          {
  102.             if(_root["t_" + _loc2_ + "_" + _loc3_].w_1._visible == false)
  103.             {
  104.                if(_root["t_" + _loc2_ + "_" + rx].w_3._visible == false)
  105.                {
  106.                   playGame = false;
  107.                   moveRight = true;
  108.                   counter = 0;
  109.                }
  110.             }
  111.          }
  112.          if(_loc1_.direction == "left")
  113.          {
  114.             if(_root["t_" + _loc2_ + "_" + _loc3_].w_3._visible == false)
  115.             {
  116.                if(_root["t_" + _loc2_ + "_" + lx].w_1._visible == false)
  117.                {
  118.                   playGame = false;
  119.                   moveLeft = true;
  120.                   counter = 0;
  121.                }
  122.             }
  123.          }
  124.          if(_loc1_.direction == "down")
  125.          {
  126.             if(_root["t_" + _loc2_ + "_" + _loc3_].w_2._visible == false)
  127.             {
  128.                if(_root["t_" + dy + "_" + _loc3_].w_0._visible == false)
  129.                {
  130.                   playGame = false;
  131.                   moveDown = true;
  132.                   counter = 0;
  133.                }
  134.             }
  135.          }
  136.          if(_loc1_.direction == "up")
  137.          {
  138.             if(_root["t_" + _loc2_ + "_" + _loc3_].w_0._visible == false)
  139.             {
  140.                if(_root["t_" + uy + "_" + _loc3_].w_2._visible == false)
  141.                {
  142.                   playGame = false;
  143.                   moveUp = true;
  144.                   counter = 0;
  145.                }
  146.             }
  147.          }
  148.          if(_root["t_" + _loc2_ + "_" + _loc3_].exit._visible == true)
  149.          {
  150.             _root["t_" + _loc2_ + "_" + _loc3_].exit._visible = false;
  151.             _root["t_" + _loc2_ + "_" + _loc3_].exit.gotoAndStop(2);
  152.             wipe.start(0,1);
  153.             ex++;
  154.             if(ex == exitCounter)
  155.             {
  156.                nextFrame();
  157.             }
  158.          }
  159.          if(moveRight == false and moveUp == false and moveDown == false and moveLeft == false)
  160.          {
  161.             if(Key.isDown(39))
  162.             {
  163.                _loc1_.direction = "right";
  164.             }
  165.             if(Key.isDown(37))
  166.             {
  167.                _loc1_.direction = "left";
  168.             }
  169.             if(Key.isDown(40))
  170.             {
  171.                _loc1_.direction = "down";
  172.             }
  173.             if(Key.isDown(38))
  174.             {
  175.                _loc1_.direction = "up";
  176.             }
  177.             if(Key.isDown(17))
  178.             {
  179.                level--;
  180.                nextFrame();
  181.             }
  182.          }
  183.       }
  184.    };
  185. }
  186. function doLevel(lv)
  187. {
  188.    switch(lv)
  189.    {
  190.       case 1:
  191.          createBall(1,1);
  192.          step = 10;
  193.          exitCounter = 1;
  194.          break;
  195.       case 2:
  196.          createBall(3,3);
  197.          step = 9;
  198.          exitCounter = 1;
  199.          break;
  200.       case 3:
  201.          createBall(1,4);
  202.          step = 9;
  203.          exitCounter = 1;
  204.          break;
  205.       case 4:
  206.          createBall(1,3);
  207.          step = 8;
  208.          exitCounter = 1;
  209.          break;
  210.       case 5:
  211.          createBall(5,2);
  212.          step = 8;
  213.          exitCounter = 1;
  214.          break;
  215.       case 6:
  216.          createBall(6,4);
  217.          step = 7;
  218.          exitCounter = 1;
  219.          break;
  220.       case 7:
  221.          createBall(3,4);
  222.          step = 10;
  223.          exitCounter = 5;
  224.          break;
  225.       case 8:
  226.          createBall(3,3);
  227.          step = 10;
  228.          exitCounter = 8;
  229.          break;
  230.       case 9:
  231.          createBall(3,3);
  232.          step = 10;
  233.          exitCounter = 8;
  234.          break;
  235.       case 10:
  236.          createBall(1,3);
  237.          step = 9;
  238.          exitCounter = 6;
  239.          break;
  240.       case 11:
  241.          createBall(5,5);
  242.          step = 7;
  243.          exitCounter = 15;
  244.    }
  245. }
  246. function getwh(lv)
  247. {
  248.    switch(lv)
  249.    {
  250.       case 1:
  251.          tileW = 40;
  252.          tileH = 40;
  253.          break;
  254.       case 2:
  255.          tileW = 36;
  256.          tileH = 36;
  257.          break;
  258.       case 3:
  259.          tileW = 36;
  260.          tileH = 36;
  261.          break;
  262.       case 4:
  263.          tileW = 32;
  264.          tileH = 32;
  265.          break;
  266.       case 5:
  267.          tileW = 32;
  268.          tileH = 32;
  269.          break;
  270.       case 6:
  271.          tileW = 28;
  272.          tileH = 28;
  273.          break;
  274.       case 7:
  275.          tileW = 40;
  276.          tileH = 40;
  277.          break;
  278.       case 8:
  279.          tileW = 40;
  280.          tileH = 40;
  281.          break;
  282.       case 9:
  283.          tileW = 40;
  284.          tileH = 40;
  285.          break;
  286.       case 10:
  287.          tileW = 36;
  288.          tileH = 36;
  289.          break;
  290.       case 11:
  291.          tileW = 28;
  292.          tileH = 28;
  293.    }
  294. }
  295. myMap1 = [["0000","0000","0000","0000","0000","0000"],["0000","1001","1010","1000","1001","1100"],["0000","0001","0000","0000","0000","0110"],["0000","0101","0000","0010","0000","0100"],["0000","0001","0010","0000","0000","0110"],["0000","0011","0010","0010","0011","0110"]];
  296. myMap2 = [["0000","0000","0000","0000","0000","0000","0000"],["0000","1101","1000","1010","1000","1100","1100"],["0000","0001","0000","0000","0000","0010","0100"],["0000","0101","0000","0111","0000","0000","0110"],["0000","0011","0000","0000","1101","0000","0100"],["0000","0001","0000","0000","0000","0000","0110"],["0000","0011","0010","0111","0010","0010","0110"]];
  297. myMap3 = [["0000","0000","0000","0000","0000","0000","0000"],["0000","1001","1000","1110","1000","1000","1110"],["0000","0011","0000","0010","0000","0000","0100"],["0000","0001","0000","0000","0000","0000","0111"],["0000","0001","0000","0000","0011","0000","0100"],["0000","0111","0000","0000","0000","0000","0100"],["0000","0011","0110","0010","0010","0111","0110"]];
  298. myMap4 = [["0000","0000","0000","0000","0000","0000","0000","0000"],["0000","1001","1000","1000","1010","1100","1000","1100"],["0000","0011","0100","0000","0000","0010","0000","0110"],["0000","0011","0000","0100","0000","0000","0000","0100"],["0000","0001","0000","0000","0000","0110","0000","0110"],["0000","0001","0000","0100","0000","0000","0000","0110"],["0000","0011","1100","0000","0000","0000","0010","0100"],["0000","0011","0010","0110","0010","0010","0011","0110"]];
  299. myMap5 = [["0000","0000","0000","0000","0000","0000","0000","0000","0000"],["0000","1101","1000","1010","1100","1000","1000","1110"],["0000","0001","0000","0000","0000","0000","0000","0100"],["0000","0001","0010","0100","0000","0000","0100","0100"],["0000","0001","0000","0000","0110","0100","0000","0110"],["0000","0011","0000","0000","0000","0010","0000","0100"],["0000","0001","0000","0111","0000","0000","0000","0100"],["0000","0011","0010","0010","0110","0010","0010","0111"]];
  300. myMap6 = [["0000","0000","0000","0000","0000","0000","0000","0000","0000","0000"],["0000","1011","1000","1100","1000","1000","1010","1100","1000","1110"],["0000","0001","0110","0000","0000","0010","0000","0000","0000","0101"],["0000","0001","0000","0000","0000","0000","0100","0100","0000","0100"],["0000","0011","0100","0000","0010","0000","0011","0000","0000","0110"],["0000","0001","0000","0000","0010","0000","0010","0100","0000","0100"],["0000","0001","0000","0000","0100","0100","0000","0010","0000","0110"],["0000","0001","1001","0010","0000","0010","0000","0000","0000","0100"],["0000","0011","0000","0000","0010","0100","0000","0000","0010","0100"],["0000","0011","0010","0010","0110","0010","0010","0010","0110","0110"]];
  301. myMap7 = [["0000","0000","0000","0000","0000","0000"],["0000","1011","1100","1000","1010","1100"],["0000","0001","0000","0000","0100","0100"],["0000","0101","0100","0010","0000","0100"],["0000","0001","0000","0000","0000","0110"],["0000","0111","0010","0110","0010","0110"]];
  302. myMap8 = [["0000","0000","0000","0000","0000","0000"],["0000","1011","1000","1010","1100","1100"],["0000","0001","0000","0100","0000","0100"],["0000","0101","0000","0010","0000","0110"],["0000","0011","0000","0001","0010","0110"],["0000","0011","0010","0010","0010","0110"]];
  303. myMap9 = [["0000","0000","0000","0000","0000","0000","0000"],["0000","1011","1100","1000","1010","1110"],["0000","0101","0000","0000","0010","0100"],["0000","0001","0010","0000","0000","0110"],["0000","0001","0100","0100","0010","0100"],["0000","0111","0010","0010","0010","0110"]];
  304. myMap10 = [["0000","0000","0000","0000","0000","0000","0000","0000"],["0000","1101","1000","1100","1000","1000","1100"],["0000","0011","0000","0010","0100","0000","0110"],["0000","0101","0000","0000","0000","0000","0100"],["0000","0011","0000","0000","0011","0000","0111"],["0000","0001","0000","0010","0000","0000","0100"],["0000","0111","0010","0010","0110","0010","0110"]];
  305. myMap11 = [["0000","0000","0000","0000","0000","0000","0000","0000","0000"],["0000","1001","1010","1100","1000","1000","1000","1110","1100"],["0000","0001","0000","0000","0000","0100","0000","0000","0100"],["0000","0001","0000","0000","0000","0000","0000","0110","0100"],["0000","0111","0100","1000","0000","0000","0000","0000","0110"],["0000","0001","0000","0000","0110","0000","0100","0000","0100"],["0000","0001","0000","0000","0000","0010","0000","0000","0110"],["0000","0001","0000","0010","0000","0010","0000","0000","0100"],["0000","0111","0010","0010","0010","0010","0110","0010","0110"]];
  306. myExit1 = [[5,5]];
  307. myExit2 = [[4,4]];
  308. myExit3 = [[6,3]];
  309. myExit4 = [[7,5]];
  310. myExit5 = [[3,6]];
  311. myExit6 = [[4,6]];
  312. myExit7 = [[1,1],[5,5],[5,1],[1,5],[3,3]];
  313. myExit8 = [[1,2],[1,4],[2,5],[2,1],[4,1],[4,5],[5,2],[5,4]];
  314. myExit9 = [[1,1],[5,1],[5,5],[1,5],[2,2],[4,2],[2,4],[4,4]];
  315. myExit10 = [[1,2],[4,1],[1,5],[4,6],[6,5],[6,4]];
  316. myExit11 = [[2,1],[6,1],[8,1],[4,2],[7,3],[1,4],[3,4],[5,4],[7,5],[2,6],[4,6],[5,7],[1,8],[3,8],[7,8]];
  317. moveRight = moveLeft = moveDown = moveUp = false;
  318. playGame = true;
  319. w = 0;
  320. ex = 0;
  321. myMap = _root["myMap" + level];
  322. myExit = _root["myExit" + level];
  323. myText = "Level: " + level;
  324. buildMap(myMap,myExit);
  325. doLevel(level);
  326. stop();
  327.