home *** CD-ROM | disk | FTP | other *** search
- function pressed(cd)
- {
- var _loc1_ = cd;
- c = getCdir();
- if(getChanged() == false && getGameOn() == true)
- {
- if(_loc1_ == 38)
- {
- if(c != 1 && c != 3)
- {
- setCdir(3);
- setChanged(true);
- }
- }
- else if(_loc1_ == 40)
- {
- if(c != 3 && c != 1)
- {
- setCdir(1);
- setChanged(true);
- }
- }
- else if(_loc1_ == 37)
- {
- if(c != 2 && c != 4)
- {
- setCdir(4);
- setChanged(true);
- }
- }
- else if(_loc1_ == 39)
- {
- if(c != 4 && c != 2)
- {
- setCdir(2);
- setChanged(true);
- }
- }
- }
- }
- function setCdir(c)
- {
- this.cdir = c;
- }
- function getCdir()
- {
- return this.cdir;
- }
- function getChanged()
- {
- return this.changed;
- }
- function setChanged(c)
- {
- this.changed = c;
- }
- function getGameOn()
- {
- return this.gameOn;
- }
- function getPR(z)
- {
- d = 800;
- return d / (z + d);
- }
- function drawLine(x, y, z, x2, y2, z2)
- {
- var _loc1_ = y2;
- var _loc2_ = y;
- var _loc3_ = x2;
- x *= getPR(z);
- _loc2_ *= getPR(z);
- _loc3_ *= getPR(z2);
- _loc1_ *= getPR(z2);
- _loc2_ -= 500;
- _loc1_ -= 500;
- moveTo(x,_loc2_);
- lineTo(_loc3_,_loc1_);
- }
- function getPointX(p, z)
- {
- return p * getPR(z);
- }
- function getPointY(p, z)
- {
- return p * getPR(z) - 500;
- }
- function drawSquare(x, y, z, x2, y2, z2)
- {
- var _loc1_ = y2;
- var _loc2_ = x2;
- var _loc3_ = z;
- drawLine(x,y,_loc3_,_loc2_,y,_loc3_);
- drawLine(x,_loc1_,z2,_loc2_,_loc1_,z2);
- drawLine(x,y,_loc3_,x,_loc1_,z2);
- drawLine(_loc2_,y,_loc3_,_loc2_,_loc1_,z2);
- }
- function drawCube(x, y, z, s)
- {
- var _loc1_ = s;
- var _loc2_ = z;
- var _loc3_ = y;
- drawSquare(x,_loc3_,_loc2_,x + _loc1_,_loc3_ + _loc1_,_loc2_);
- drawSquare(x,_loc3_,_loc2_ + _loc1_,x + _loc1_,_loc3_ + _loc1_,_loc2_ + _loc1_);
- drawLine(x,_loc3_,_loc2_,x,_loc3_,_loc2_ + _loc1_);
- drawLine(x + _loc1_,_loc3_,_loc2_,x + _loc1_,_loc3_,_loc2_ + _loc1_);
- drawLine(x,_loc3_ + _loc1_,_loc2_,x,_loc3_ + _loc1_,_loc2_ + _loc1_);
- drawLine(x + _loc1_,_loc3_ + _loc1_,_loc2_,x + _loc1_,_loc3_ + _loc1_,_loc2_ + _loc1_);
- }
- function moveIt()
- {
- var _loc1_ = this;
- if(gameOn != false)
- {
- if(_loc1_.cdir == 3)
- {
- newchead = _loc1_.chead - 20;
- }
- if(_loc1_.cdir == 1)
- {
- newchead = _loc1_.chead + 20;
- }
- if(_loc1_.cdir == 2)
- {
- newchead = _loc1_.chead + 1;
- }
- if(_loc1_.cdir == 4)
- {
- newchead = _loc1_.chead - 1;
- }
- if(newchead < 0)
- {
- destroyIt();
- }
- else if(newchead > 399)
- {
- destroyIt();
- }
- else if(_loc1_["worm" + newchead]._currentframe == 2)
- {
- destroyIt();
- }
- else if(newchead % 20 == 0 && _loc1_.cdir == 2 && newchead != 0)
- {
- destroyIt();
- }
- else if((newchead + 1) % 20 == 0 && _loc1_.cdir == 4)
- {
- destroyIt();
- }
- else
- {
- _loc1_["worm" + _loc1_.chead].gotoAndStop(1);
- next = _loc1_.chead;
- _loc1_.chead = newchead;
- _loc1_["worm" + _loc1_.chead].gotoAndStop(3);
- _loc1_["worm" + _loc1_.chead].wormhead.gotoAndStop(_loc1_.cdir);
- _loc1_["worm" + _loc1_.chead].wormhead2.gotoAndStop(_loc1_.cdir);
- _loc1_["worm" + _loc1_.chead].tail = next;
- if(_loc1_.chead == appleAt)
- {
- placeApple();
- toadd += 3;
- _loc1_.apples = int(_loc1_.apples) + 1;
- lvl = Math.floor(_loc1_.apples / 10) + 1;
- if(lvl >= 5)
- {
- lvl = 4;
- }
- if(int(lvl) != int(_loc1_.level))
- {
- _parent.levelAlert.levelText.level = "Level: " + lvl;
- _parent.levelAlert.play();
- }
- _loc1_.level = lvl;
- }
- if(_loc1_.chead == _loc1_.apple2At)
- {
- _loc1_.toadd = 0;
- _loc1_.apple2At = -1;
- gnext = _loc1_["worm" + _loc1_.chead].tail;
- arr = new Array();
- while(gnext != null)
- {
- arr[arr.length] = gnext;
- gnext = _loc1_["worm" + gnext].tail;
- }
- if(arr.length >= 5)
- {
- arr.reverse();
- _loc1_["worm" + arr[0]].gotoAndStop(1);
- _loc1_["worm" + arr[0]].tail = null;
- _loc1_["worm" + arr[1]].gotoAndStop(1);
- _loc1_["worm" + arr[1]].tail = null;
- _loc1_["worm" + arr[2]].gotoAndStop(1);
- _loc1_["worm" + arr[2]].tail = null;
- _loc1_["worm" + arr[3]].tail = null;
- }
- }
- while(next != null)
- {
- obj = _loc1_["worm" + next];
- next = obj.tail;
- next2 = _loc1_["worm" + next].tail;
- if(next2 == null)
- {
- if(_loc1_.toadd == 0)
- {
- _loc1_["worm" + obj.tail].gotoAndStop(1);
- obj.tail = null;
- }
- else
- {
- _loc1_.toadd = _loc1_.toadd - 1;
- }
- }
- if(next != null)
- {
- obj.gotoAndStop(2);
- }
- }
- _loc1_.changed = false;
- }
- }
- }
- function destroyIt()
- {
- var _loc1_ = this;
- if(_loc1_.chance == false)
- {
- _loc1_.chance = true;
- }
- else
- {
- _loc1_.chance = false;
- _loc1_.gameOn = false;
- nxt = _loc1_["worm" + _loc1_.chead].tail;
- while(nxt != null)
- {
- r = int(Math.random() * 40) + 2;
- _loc1_["worm" + nxt].b1.gotoAndPlay(r);
- _loc1_["worm" + nxt].b2.gotoAndPlay(r);
- nxt = _loc1_["worm" + nxt].tail;
- }
- _loc1_["worm" + _loc1_.chead].wormhead.play();
- _loc1_["worm" + _loc1_.chead].wormhead2.play();
- _parent.btnRestart._visible = true;
- }
- }
- function placeApple()
- {
- var _loc1_ = this;
- do
- {
- pos = int(Math.random() * 400);
- if(_loc1_["worm" + pos]._currentframe > 1)
- {
- nopos = true;
- }
- else
- {
- nopos = false;
- }
- }
- while(nopos == true);
-
- _loc1_["worm" + pos].gotoAndStop(4);
- _loc1_.appleAt = pos;
- newp = int(Math.random() * 10) + 1;
- if(newp == 5)
- {
- placeApple2();
- }
- }
- function placeApple2()
- {
- var _loc1_ = this;
- if(_loc1_.apple2At == -1)
- {
- do
- {
- pos = int(Math.random() * 400);
- if(_loc1_["worm" + pos]._currentframe > 1)
- {
- nopos = true;
- }
- else
- {
- nopos = false;
- }
- }
- while(nopos == true);
-
- _loc1_["worm" + pos].gotoAndStop(5);
- _loc1_.apple2At = pos;
- }
- }
- _parent.btnRestart._visible = false;
- this.gameOn = false;
- lineStyle(1,13421772,50);
- drawSquare(-400,1000,100,400,1000,900);
- var u = 0;
- var v = 0;
- var n = 0;
- u = -400;
- while(u < 400)
- {
- v = 100;
- while(v < 900)
- {
- drawSquare(u,1000,v,u + 40,1000,v + 40);
- v += 40;
- }
- u += 40;
- }
- lineStyle(1,16764108,100);
- v = 100;
- while(v < 900)
- {
- drawCube(-440,960,v,40);
- drawCube(400,960,v,40);
- v += 40;
- }
- u = -440;
- while(u < 440)
- {
- drawCube(u,960,900,40);
- u += 40;
- }
- n = 0;
- zpoint = 920;
- v = 0;
- while(v < 20)
- {
- zpoint -= 40;
- u = 0;
- while(u < 20)
- {
- w = this.attachMovie("theworm","worm" + n,n);
- w._x = getPointX(-380 + u * 40,zpoint + 15);
- w._y = getPointY(1000,zpoint + 15);
- w._visible = true;
- w._width *= getPR(zpoint);
- w._height *= getPR(zpoint);
- w.gotoAndStop(1);
- n++;
- u++;
- }
- v++;
- }
- this.chead = 270;
- this.cdir = 3;
- this["worm" + this.chead]._visible = true;
- this["worm" + this.chead].gotoAndStop(3);
- this["worm" + this.chead].wormhead.gotoAndStop(this.cdir);
- this["worm" + this.chead].wormhead2.gotoAndStop(this.cdir);
- this["worm" + this.chead].tail = this.chead + 20;
- this["worm" + (this.chead + 20)].gotoAndStop(2);
- this["worm" + (this.chead + 20)].tail = this.chead + 40;
- this["worm" + (this.chead + 40)].gotoAndStop(2);
- this["worm" + (this.chead + 40)].tail = null;
- placeApple();
- this.apple2At = -1;
- this.changed = false;
- this.toadd = 0;
- this.apples = 0;
- this.level = 1;
- this.chance = false;
-