home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / snake_3d.swf / scripts / DefineSprite_113 / frame_1 / DoAction.as
Encoding:
Text File  |  2007-04-02  |  8.5 KB  |  369 lines

  1. function pressed(cd)
  2. {
  3.    var _loc1_ = cd;
  4.    c = getCdir();
  5.    if(getChanged() == false && getGameOn() == true)
  6.    {
  7.       if(_loc1_ == 38)
  8.       {
  9.          if(c != 1 && c != 3)
  10.          {
  11.             setCdir(3);
  12.             setChanged(true);
  13.          }
  14.       }
  15.       else if(_loc1_ == 40)
  16.       {
  17.          if(c != 3 && c != 1)
  18.          {
  19.             setCdir(1);
  20.             setChanged(true);
  21.          }
  22.       }
  23.       else if(_loc1_ == 37)
  24.       {
  25.          if(c != 2 && c != 4)
  26.          {
  27.             setCdir(4);
  28.             setChanged(true);
  29.          }
  30.       }
  31.       else if(_loc1_ == 39)
  32.       {
  33.          if(c != 4 && c != 2)
  34.          {
  35.             setCdir(2);
  36.             setChanged(true);
  37.          }
  38.       }
  39.    }
  40. }
  41. function setCdir(c)
  42. {
  43.    this.cdir = c;
  44. }
  45. function getCdir()
  46. {
  47.    return this.cdir;
  48. }
  49. function getChanged()
  50. {
  51.    return this.changed;
  52. }
  53. function setChanged(c)
  54. {
  55.    this.changed = c;
  56. }
  57. function getGameOn()
  58. {
  59.    return this.gameOn;
  60. }
  61. function getPR(z)
  62. {
  63.    d = 800;
  64.    return d / (z + d);
  65. }
  66. function drawLine(x, y, z, x2, y2, z2)
  67. {
  68.    var _loc1_ = y2;
  69.    var _loc2_ = y;
  70.    var _loc3_ = x2;
  71.    x *= getPR(z);
  72.    _loc2_ *= getPR(z);
  73.    _loc3_ *= getPR(z2);
  74.    _loc1_ *= getPR(z2);
  75.    _loc2_ -= 500;
  76.    _loc1_ -= 500;
  77.    moveTo(x,_loc2_);
  78.    lineTo(_loc3_,_loc1_);
  79. }
  80. function getPointX(p, z)
  81. {
  82.    return p * getPR(z);
  83. }
  84. function getPointY(p, z)
  85. {
  86.    return p * getPR(z) - 500;
  87. }
  88. function drawSquare(x, y, z, x2, y2, z2)
  89. {
  90.    var _loc1_ = y2;
  91.    var _loc2_ = x2;
  92.    var _loc3_ = z;
  93.    drawLine(x,y,_loc3_,_loc2_,y,_loc3_);
  94.    drawLine(x,_loc1_,z2,_loc2_,_loc1_,z2);
  95.    drawLine(x,y,_loc3_,x,_loc1_,z2);
  96.    drawLine(_loc2_,y,_loc3_,_loc2_,_loc1_,z2);
  97. }
  98. function drawCube(x, y, z, s)
  99. {
  100.    var _loc1_ = s;
  101.    var _loc2_ = z;
  102.    var _loc3_ = y;
  103.    drawSquare(x,_loc3_,_loc2_,x + _loc1_,_loc3_ + _loc1_,_loc2_);
  104.    drawSquare(x,_loc3_,_loc2_ + _loc1_,x + _loc1_,_loc3_ + _loc1_,_loc2_ + _loc1_);
  105.    drawLine(x,_loc3_,_loc2_,x,_loc3_,_loc2_ + _loc1_);
  106.    drawLine(x + _loc1_,_loc3_,_loc2_,x + _loc1_,_loc3_,_loc2_ + _loc1_);
  107.    drawLine(x,_loc3_ + _loc1_,_loc2_,x,_loc3_ + _loc1_,_loc2_ + _loc1_);
  108.    drawLine(x + _loc1_,_loc3_ + _loc1_,_loc2_,x + _loc1_,_loc3_ + _loc1_,_loc2_ + _loc1_);
  109. }
  110. function moveIt()
  111. {
  112.    var _loc1_ = this;
  113.    if(gameOn != false)
  114.    {
  115.       if(_loc1_.cdir == 3)
  116.       {
  117.          newchead = _loc1_.chead - 20;
  118.       }
  119.       if(_loc1_.cdir == 1)
  120.       {
  121.          newchead = _loc1_.chead + 20;
  122.       }
  123.       if(_loc1_.cdir == 2)
  124.       {
  125.          newchead = _loc1_.chead + 1;
  126.       }
  127.       if(_loc1_.cdir == 4)
  128.       {
  129.          newchead = _loc1_.chead - 1;
  130.       }
  131.       if(newchead < 0)
  132.       {
  133.          destroyIt();
  134.       }
  135.       else if(newchead > 399)
  136.       {
  137.          destroyIt();
  138.       }
  139.       else if(_loc1_["worm" + newchead]._currentframe == 2)
  140.       {
  141.          destroyIt();
  142.       }
  143.       else if(newchead % 20 == 0 && _loc1_.cdir == 2 && newchead != 0)
  144.       {
  145.          destroyIt();
  146.       }
  147.       else if((newchead + 1) % 20 == 0 && _loc1_.cdir == 4)
  148.       {
  149.          destroyIt();
  150.       }
  151.       else
  152.       {
  153.          _loc1_["worm" + _loc1_.chead].gotoAndStop(1);
  154.          next = _loc1_.chead;
  155.          _loc1_.chead = newchead;
  156.          _loc1_["worm" + _loc1_.chead].gotoAndStop(3);
  157.          _loc1_["worm" + _loc1_.chead].wormhead.gotoAndStop(_loc1_.cdir);
  158.          _loc1_["worm" + _loc1_.chead].wormhead2.gotoAndStop(_loc1_.cdir);
  159.          _loc1_["worm" + _loc1_.chead].tail = next;
  160.          if(_loc1_.chead == appleAt)
  161.          {
  162.             placeApple();
  163.             toadd += 3;
  164.             _loc1_.apples = int(_loc1_.apples) + 1;
  165.             lvl = Math.floor(_loc1_.apples / 10) + 1;
  166.             if(lvl >= 5)
  167.             {
  168.                lvl = 4;
  169.             }
  170.             if(int(lvl) != int(_loc1_.level))
  171.             {
  172.                _parent.levelAlert.levelText.level = "Level: " + lvl;
  173.                _parent.levelAlert.play();
  174.             }
  175.             _loc1_.level = lvl;
  176.          }
  177.          if(_loc1_.chead == _loc1_.apple2At)
  178.          {
  179.             _loc1_.toadd = 0;
  180.             _loc1_.apple2At = -1;
  181.             gnext = _loc1_["worm" + _loc1_.chead].tail;
  182.             arr = new Array();
  183.             while(gnext != null)
  184.             {
  185.                arr[arr.length] = gnext;
  186.                gnext = _loc1_["worm" + gnext].tail;
  187.             }
  188.             if(arr.length >= 5)
  189.             {
  190.                arr.reverse();
  191.                _loc1_["worm" + arr[0]].gotoAndStop(1);
  192.                _loc1_["worm" + arr[0]].tail = null;
  193.                _loc1_["worm" + arr[1]].gotoAndStop(1);
  194.                _loc1_["worm" + arr[1]].tail = null;
  195.                _loc1_["worm" + arr[2]].gotoAndStop(1);
  196.                _loc1_["worm" + arr[2]].tail = null;
  197.                _loc1_["worm" + arr[3]].tail = null;
  198.             }
  199.          }
  200.          while(next != null)
  201.          {
  202.             obj = _loc1_["worm" + next];
  203.             next = obj.tail;
  204.             next2 = _loc1_["worm" + next].tail;
  205.             if(next2 == null)
  206.             {
  207.                if(_loc1_.toadd == 0)
  208.                {
  209.                   _loc1_["worm" + obj.tail].gotoAndStop(1);
  210.                   obj.tail = null;
  211.                }
  212.                else
  213.                {
  214.                   _loc1_.toadd = _loc1_.toadd - 1;
  215.                }
  216.             }
  217.             if(next != null)
  218.             {
  219.                obj.gotoAndStop(2);
  220.             }
  221.          }
  222.          _loc1_.changed = false;
  223.       }
  224.    }
  225. }
  226. function destroyIt()
  227. {
  228.    var _loc1_ = this;
  229.    if(_loc1_.chance == false)
  230.    {
  231.       _loc1_.chance = true;
  232.    }
  233.    else
  234.    {
  235.       _loc1_.chance = false;
  236.       _loc1_.gameOn = false;
  237.       nxt = _loc1_["worm" + _loc1_.chead].tail;
  238.       while(nxt != null)
  239.       {
  240.          r = int(Math.random() * 40) + 2;
  241.          _loc1_["worm" + nxt].b1.gotoAndPlay(r);
  242.          _loc1_["worm" + nxt].b2.gotoAndPlay(r);
  243.          nxt = _loc1_["worm" + nxt].tail;
  244.       }
  245.       _loc1_["worm" + _loc1_.chead].wormhead.play();
  246.       _loc1_["worm" + _loc1_.chead].wormhead2.play();
  247.       _parent.btnRestart._visible = true;
  248.    }
  249. }
  250. function placeApple()
  251. {
  252.    var _loc1_ = this;
  253.    do
  254.    {
  255.       pos = int(Math.random() * 400);
  256.       if(_loc1_["worm" + pos]._currentframe > 1)
  257.       {
  258.          nopos = true;
  259.       }
  260.       else
  261.       {
  262.          nopos = false;
  263.       }
  264.    }
  265.    while(nopos == true);
  266.    
  267.    _loc1_["worm" + pos].gotoAndStop(4);
  268.    _loc1_.appleAt = pos;
  269.    newp = int(Math.random() * 10) + 1;
  270.    if(newp == 5)
  271.    {
  272.       placeApple2();
  273.    }
  274. }
  275. function placeApple2()
  276. {
  277.    var _loc1_ = this;
  278.    if(_loc1_.apple2At == -1)
  279.    {
  280.       do
  281.       {
  282.          pos = int(Math.random() * 400);
  283.          if(_loc1_["worm" + pos]._currentframe > 1)
  284.          {
  285.             nopos = true;
  286.          }
  287.          else
  288.          {
  289.             nopos = false;
  290.          }
  291.       }
  292.       while(nopos == true);
  293.       
  294.       _loc1_["worm" + pos].gotoAndStop(5);
  295.       _loc1_.apple2At = pos;
  296.    }
  297. }
  298. _parent.btnRestart._visible = false;
  299. this.gameOn = false;
  300. lineStyle(1,13421772,50);
  301. drawSquare(-400,1000,100,400,1000,900);
  302. var u = 0;
  303. var v = 0;
  304. var n = 0;
  305. u = -400;
  306. while(u < 400)
  307. {
  308.    v = 100;
  309.    while(v < 900)
  310.    {
  311.       drawSquare(u,1000,v,u + 40,1000,v + 40);
  312.       v += 40;
  313.    }
  314.    u += 40;
  315. }
  316. lineStyle(1,16764108,100);
  317. v = 100;
  318. while(v < 900)
  319. {
  320.    drawCube(-440,960,v,40);
  321.    drawCube(400,960,v,40);
  322.    v += 40;
  323. }
  324. u = -440;
  325. while(u < 440)
  326. {
  327.    drawCube(u,960,900,40);
  328.    u += 40;
  329. }
  330. n = 0;
  331. zpoint = 920;
  332. v = 0;
  333. while(v < 20)
  334. {
  335.    zpoint -= 40;
  336.    u = 0;
  337.    while(u < 20)
  338.    {
  339.       w = this.attachMovie("theworm","worm" + n,n);
  340.       w._x = getPointX(-380 + u * 40,zpoint + 15);
  341.       w._y = getPointY(1000,zpoint + 15);
  342.       w._visible = true;
  343.       w._width *= getPR(zpoint);
  344.       w._height *= getPR(zpoint);
  345.       w.gotoAndStop(1);
  346.       n++;
  347.       u++;
  348.    }
  349.    v++;
  350. }
  351. this.chead = 270;
  352. this.cdir = 3;
  353. this["worm" + this.chead]._visible = true;
  354. this["worm" + this.chead].gotoAndStop(3);
  355. this["worm" + this.chead].wormhead.gotoAndStop(this.cdir);
  356. this["worm" + this.chead].wormhead2.gotoAndStop(this.cdir);
  357. this["worm" + this.chead].tail = this.chead + 20;
  358. this["worm" + (this.chead + 20)].gotoAndStop(2);
  359. this["worm" + (this.chead + 20)].tail = this.chead + 40;
  360. this["worm" + (this.chead + 40)].gotoAndStop(2);
  361. this["worm" + (this.chead + 40)].tail = null;
  362. placeApple();
  363. this.apple2At = -1;
  364. this.changed = false;
  365. this.toadd = 0;
  366. this.apples = 0;
  367. this.level = 1;
  368. this.chance = false;
  369.