home *** CD-ROM | disk | FTP | other *** search
- function setTerrainOn(pos)
- {
- var floor = floors[pos];
- var ceiling = ceilings[pos];
- floor.clear();
- ceiling.clear();
- floor.beginGradientFill("linear",[16777215,12303291],[100,100],[0,255],{matrixType:"box",x:0,y:hh / 2,w:ww,h:hh / 2,r:1.5707963});
- ceiling.beginFill(15658751);
- var iStart = -1;
- var iEnd = 21;
- floor.moveTo((iStart - 1) * ww / 20,hh);
- ceiling.moveTo((iStart - 1) * ww / 20,0);
- fp = recentFp[0];
- cp = recentCp[0];
- var i = iStart;
- while(i <= iEnd)
- {
- lfp = fp;
- lcp = cp;
- if(i <= 1)
- {
- fp = recentFp[i + 1];
- cp = recentCp[i + 1];
- }
- else
- {
- cp += rand(rt) * 20 - 10;
- fp += rand(rt) * 20 - 10;
- if(rand(rt) < 0.15)
- {
- if(rand(rt) < 0.5)
- {
- cp += rand(rt) * gap / 4;
- }
- else
- {
- fp -= rand(rt) * gap / 4;
- }
- }
- cp += (hh / 2 - gap / 2 - cp) / 12;
- fp += (hh / 2 + gap / 2 - fp) / 12;
- }
- if(i >= 19)
- {
- recentFp[i - 19] = fp;
- recentCp[i - 19] = cp;
- }
- floor.curveTo((i - 1) * ww / 20,lfp,ww / 20 * (i - 0.5),(fp + lfp) / 2);
- ceiling.curveTo((i - 1) * ww / 20,lcp,ww / 20 * (i - 0.5),(cp + lcp) / 2);
- i++;
- }
- floor.lineTo(ww + 20,hh);
- floor.lineTo(0,hh);
- ceiling.lineTo(ww + 20,0);
- ceiling.lineTo(0,0);
- floor.endFill();
- ceiling.endFill();
- }
- function rotateRadians(x, y, radians)
- {
- var pts = new Array();
- var cosrad = Math.cos(radians);
- var sinrad = Math.sin(radians);
- pts[1] = cosrad * x - sinrad * y;
- pts[2] = cosrad * y + sinrad * x;
- return pts;
- }
- function rand(o)
- {
- o.rfr = (o.rfr + 0.1) % 6.283185307179586;
- o.rfvr += Math.cos(o.rfr) * 0.33924 + 2;
- o.rfvr %= 2.718281828459045;
- return o.rfvr * 1.4142135623730951 % 1;
- }
- function startMain()
- {
- _quality = "HIGH";
- high.removeMovieClip();
- main.removeMovieClip();
- this.attachMovie("main","main",++dep);
- main._x = ww / 2;
- main._y = hh / 2;
- main._alpha = 0;
- }
- function startHigh()
- {
- _quality = "HIGH";
- this.attachMovie("high","high",++dep);
- high._x = ww / 2;
- high._y = hh / 2;
- high.ccr = ccr;
- high.gd = gd;
- high._alpha = 0;
- }
- function startGame()
- {
- _quality = "LOW";
- score.text = "";
- recentFp = new Array();
- recentCp = new Array();
- dead = false;
- brnda = 210;
- nbfr = 0;
- furg = 1;
- if(ghosting)
- {
- ghost.removeMovieClip();
- ghost = this.attachMovie("ghost","ghost",++dep);
- gblades = ghost.propellor.blades;
- deadghost = false;
- ghost._x = ghost.x = 100;
- ghost._y = ghost.y = 100;
- ghost._alpha = 25;
- ghost._rotation = ghost.rotation = 25;
- ghost._xscale = ghost._yscale = 25;
- ghost.vy = 0;
- gcr = 0;
- gts = "";
- gdchp = 0;
- }
- gd = "";
- gft = false;
- ccr = 0;
- lcrp = 0;
- bg._x = bg.ox = bg.x = 0;
- copter.vy = 0;
- copter.rx = 0;
- copter._x = copter.x = copter.ox = 100;
- copter._y = copter.y = copter.oy = 100;
- copter._rotation = copter.rotation = 25;
- var i = 0;
- while(i < bd.length)
- {
- bd[i].b.removeMovieClip();
- i++;
- }
- rt = new Object();
- rb = new Object();
- bd = new Array();
- recentCp = [hh / 2 - gap / 2,hh / 2 - gap / 2,hh / 2 - gap / 2];
- recentFp = [hh / 2 + gap / 2,hh / 2 + gap / 2,hh / 2 + gap / 2];
- setTerrainOn(1);
- floorPos = 2;
- floors[1]._x = ceilings[1]._x = 0;
- floors[2]._x = ceilings[2]._x = ww;
- terrain._x = terrain.x = 0;
- setTerrainOn(2);
- }
- function checkTerrain()
- {
- if(terrain.x < - ww)
- {
- terrain.x += ww;
- terrain._x = terrain.x;
- floors[floorPos]._x = ceilings[floorPos]._x = 0;
- floorPos = 1 + floorPos % 2;
- floors[floorPos]._x = ceilings[floorPos]._x = ww;
- var i = 0;
- while(i < bd.length)
- {
- bd[i].x -= ww;
- bd[i].b._x -= ww;
- i++;
- }
- setTerrainOn(floorPos);
- }
- }
- ww = 750;
- hh = 300;
- dm = "flash-gear.com";
- var dmp = _root._url.split("/");
- var di = 0;
- while(di < dmp.length)
- {
- if(dmp[di].indexOf(dm) >= 0)
- {
- dm = dmp[di];
- break;
- }
- di++;
- }
- terrainHolder = this.createEmptyMovieClip("terrainHolder",++dep);
- bg = terrainHolder.createEmptyMovieClip("bg",++terrainHolder.dep);
- terrain = terrainHolder.createEmptyMovieClip("terrain",++terrainHolder.dep);
- bdB = terrain.createEmptyMovieClip("bdB",++terrain.dep);
- terrainF = terrain.createEmptyMovieClip("terrainF",++terrain.dep);
- this.attachMovie("textbox","score",++dep);
- score._x = 5;
- score._y = hh - score._height - 5;
- score.box.selectable = false;
- floors = new Array();
- ceilings = new Array();
- floorsB = new Array();
- ceilingsB = new Array();
- i = 1;
- while(i <= 2)
- {
- f = floors[i] = terrainF.createEmptyMovieClip("floor" + i,++terrainF.dep);
- c = ceilings[i] = terrainF.createEmptyMovieClip("ceiling" + i,++terrainF.dep);
- fm = f.createEmptyMovieClip("floormask",++f.dep);
- fm.beginFill(0);
- fm.lineTo(ww + 1,0);
- fm.lineTo(ww + 1,hh);
- fm.lineTo(0,hh);
- fm.lineTo(0,0);
- fm.endFill();
- f.setMask(fm);
- cm = c.createEmptyMovieClip("ceilingmask",++c.dep);
- cm.beginFill(0);
- cm.lineTo(ww + 1,0);
- cm.lineTo(ww + 1,hh);
- cm.lineTo(0,hh);
- cm.lineTo(0,0);
- cm.endFill();
- c.setMask(cm);
- i++;
- }
- gap = hh - 32;
- copter = this.attachMovie("copter","copter",++dep);
- blades = copter.propellor.blades;
- copter._xscale = copter._yscale = 25;
- i = 0;
- while(i <= hb)
- {
- hpts[i] = rotateRadians(hx[i],hy[i],copter.rotation * 3.1415926 / 180);
- i++;
- }
- hx = [36,-145,-100,-80,-60,-40,-28,30,-70];
- hy = [4,-6.5,-6.8,-6.8,-6.8,-6.8,-33,-34,-34];
- hpts = new Array();
- hb = hx.length - 1;
- i = 0;
- while(i <= hb)
- {
- hx[i] = hx[i] * copter._xscale / 100;
- hy[i] = hy[i] * copter._yscale / 100;
- i++;
- }
- this.onMouseDown = function()
- {
- this.mouseIsDown = true;
- };
- this.onMouseUp = function()
- {
- this.mouseIsDown = false;
- };
- pg.y = pg._y;
- startGame();
- dead = true;
- startMain();
- this.onEnterFrame = function()
- {
- if(main._alpha < 100)
- {
- main._alpha += lcr / 2;
- if(main._alpha > 100)
- {
- main._alpha = 100;
- }
- }
- if(high._alpha < 100)
- {
- high._alpha += lcr / 2;
- if(high._alpha > 100)
- {
- high._alpha = 100;
- }
- }
- t = getTimer();
- if(!gft)
- {
- gft = true;
- lcrt = t;
- }
- else
- {
- lcrp += (t - lcrt) * 0.12;
- lcrt = t;
- lcr = 0;
- if(++furg == 2)
- {
- lcr = Math.min(40,Math.floor(lcrp));
- furg = 0;
- if(!dead)
- {
- ccr += lcr;
- score.text = "Flight length: " + Math.ceil(ccr / 120) + " seconds";
- }
- }
- if(!dead)
- {
- while(ccr > nbfr)
- {
- if(brnda > 80)
- {
- brnda--;
- }
- var tcr = ccr - nbfr;
- nbfr += Math.ceil(rand(rb) * brnda) + brnda;
- var o = new Object();
- o.b = bdB.attachMovie("penguin","bd" + ++bdc,++bdB.dep);
- o.b._height = 30 + rand(rb) * 10;
- o.b._xscale = o.b._yscale;
- o.vx = 1 + Math.min(3,ccr * 0.0005) - o.b._height / 40;
- o.b._x = o.x = ww * 2 + 64 - terrain.x;
- o.b._y = o.y = hh / 2 + (rand(rb) * gap - gap / 2) / 2;
- o.b._rotation = - (40 - o.b._yscale);
- bd[bd.length] = o;
- }
- }
- if(lcr > 0)
- {
- lcrp -= lcr;
- if(!dead)
- {
- if(mouseIsDown)
- {
- var dch = String.fromCharCode(2);
- }
- else
- {
- var dch = String.fromCharCode(1);
- }
- var dlcr = lcr;
- while(dlcr > 0)
- {
- var dmv = Math.min(dlcr,120);
- gd += dch + String.fromCharCode(dmv);
- dlcr -= dmv;
- }
- if(mouseIsDown and copter.vy > -0.75)
- {
- copter.vy -= 0.015 * lcr;
- if(copter.vy < -0.75)
- {
- copter.vy = -0.75;
- }
- }
- else if(!mouseIsDown and copter.vy < 0.6)
- {
- copter.vy += 0.01 * lcr;
- if(copter.vy > 0.6)
- {
- copter.vy = 0.6;
- }
- }
- copter.oy = copter.y;
- copter.y += copter.vy * lcr;
- copter._y = copter.y;
- if(ghosting and !deadghost)
- {
- gblades._rotation += -41;
- while(true)
- {
- if(gts != "")
- {
- gmd = gts.charCodeAt(0) == 2;
- gcl = gts.charCodeAt(1);
- gts = "";
- }
- else
- {
- if(gdchp >= gdbp.length)
- {
- deadghost = true;
- break;
- }
- gmd = gdbp.charCodeAt(gdchp) == 2;
- gcl = gdbp.charCodeAt(gdchp + 1);
- gdchp += 2;
- }
- m = Math.min(gcl,ccr - gcr);
- if(gmd and ghost.vy > -0.75)
- {
- ghost.vy -= 0.015 * m;
- if(ghost.vy < -0.75)
- {
- ghost.vy = -0.75;
- }
- }
- else if(!gmd and ghost.vy < 0.6)
- {
- ghost.vy += 0.01 * m;
- if(ghost.vy > 0.6)
- {
- ghost.vy = 0.6;
- }
- }
- ghost.y += ghost.vy * m;
- l = 1;
- while(l <= m)
- {
- ghost.rotation += ((!gmd ? 20 : 0) - ghost.rotation) * 0.08;
- l++;
- }
- gcr += m;
- if(gcr == ccr)
- {
- if(gcl > ccr - (gcr - m))
- {
- gts = String.fromCharCode(!gmd ? 1 : 2) + String.fromCharCode(gcl - (ccr - (gcr - m)));
- }
- break;
- }
- }
- ghost._y = ghost.y;
- ghost._rotation = ghost.rotation;
- }
- else if(deadghost)
- {
- ghost.x -= copter.vx;
- ghost._x = ghost.x;
- }
- l = 1;
- while(l <= lcr)
- {
- copter.rotation += ((!mouseIsDown ? 20 : 0) - copter.rotation) * 0.08;
- l++;
- }
- i = 0;
- while(i <= hb)
- {
- hpts[i] = rotateRadians(hx[i],hy[i],copter.rotation * 3.1415926 / 180);
- i++;
- }
- copter._rotation = copter.rotation;
- blades._rotation += -41;
- copter.lrx = copter.rx;
- copter.rx = ccr + 0.00025 * Math.pow(ccr,2);
- copter.vx = copter.rx - copter.lrx;
- bg.ox = bg.x;
- bg.x -= copter.vx;
- bg._x = bg.x;
- terrain.x -= copter.vx;
- terrain._x = terrain.x;
- checkTerrain();
- }
- else
- {
- copter.vx *= Math.pow(0.99,lcr);
- copter.vy *= Math.pow(0.88,lcr);
- copter.x -= copter.vx;
- copter._x = copter.x;
- terrain.x -= copter.vx;
- terrain._x = terrain.x;
- bg.x -= copter.vx;
- bg._x = bg.x;
- i = 0;
- while(i < bd.length)
- {
- if(bd[i].falling)
- {
- bd[i].vy += lcr / 30;
- bd[i].b._y += bd[i].vy;
- }
- i++;
- }
- checkTerrain();
- }
- i = bd.length - 1;
- while(i >= 0)
- {
- var o = bd[i];
- o.x += o.vx * lcr;
- o.b._x = o.x;
- if(o.x < 0)
- {
- o.b.removeMovieClip();
- bd.splice(i,1);
- }
- i--;
- }
- }
- if(furg == 1)
- {
- if(!dead)
- {
- var d = Math.sqrt(Math.pow(copter.y - copter.oy,2) + Math.pow(bg.x - bg.ox,2));
- var tpt = new Array();
- j = 0;
- while(j <= d)
- {
- if(j > d)
- {
- j = d;
- }
- var v = j / d;
- var xv = copter.x - (bg.ox - bg.x) * (1 - v);
- var yv = copter.oy + (copter.y - copter.oy) * v;
- i = 0;
- while(i <= hb)
- {
- var pts = hpts[i];
- if(terrainHolder.hitTest(xv + pts[1],yv + pts[2],true) or yv + pts[2] < 0 or yv + pts[2] > hh)
- {
- i = 0;
- while(i < bd.length)
- {
- if(bd[i].b.hitTest(xv + pts[1],yv + pts[2],true))
- {
- bd[i].falling = true;
- bd[i].vx *= 1.5;
- }
- i++;
- }
- dead = true;
- score.text = "Flight length: " + Math.floor(1000 * ccr / 120) / 1000 + " seconds";
- if(ghosting)
- {
- ghost.removeMovieClip();
- }
- vv = new LoadVars();
- vv.c = "c";
- ccr -= lcr;
- vv.l = ccr;
- pv = new LoadVars();
- pv.onLoad = function()
- {
- if(this.ih == "1")
- {
- startHigh();
- }
- else
- {
- startMain();
- }
- };
- vv.sendAndLoad("http://" + _root.dm + "/copter/copter.php",pv);
- j = d;
- break;
- }
- i++;
- }
- j += 10;
- }
- }
- }
- }
- };
-