home *** CD-ROM | disk | FTP | other *** search
- function checkState()
- {
- sound.setPan(Math.round((player._x - 250) * 0.4) / 4);
- if(State == "falling")
- {
- if(ground.hitTest(player._x,player.getBounds(_root).yMax + 2,true))
- {
- fixPosition();
- State = "standing";
- player._y += 1;
- djump = "fresh";
- yforce = 0;
- }
- else if(ground.hitTest(player.getBounds(_root).xMin - 1,player._y,true) && Left && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
- {
- State = "hanging";
- djump = "used";
- }
- else if(ground.hitTest(player.getBounds(_root).xMax + 1,player._y,true) && Right && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
- {
- State = "hanging";
- djump = "used";
- }
- else
- {
- fall();
- applySpeed();
- fallHit();
- }
- }
- else if(State == "hanging")
- {
- fixPosition();
- getKeys();
- if(ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true) && !Right && !Up)
- {
- State = "falling";
- player._x--;
- yforce = 0;
- }
- else if(ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true) && !Left && !Up)
- {
- State = "falling";
- player._x = player._x + 1;
- yforce = 0;
- }
- else if(ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true) && (!Right && Up))
- {
- fixPosition();
- State = "jumping";
- yforce = -10;
- xforce = -5;
- }
- else if(ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true) && (!Left && Up))
- {
- State = "jumping";
- yforce = -10;
- xforce = 5;
- }
- else if(!Left && !Right && !Up)
- {
- State = "falling";
- trace("NOT USED");
- }
- else
- {
- hangHit();
- checkSide();
- }
- }
- else if(State == "jumping")
- {
- if(yforce >= 0)
- {
- State = "falling";
- }
- else if(ground.hitTest(player.getBounds(_root).xMin - 1,player._y,true) && Left && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
- {
- State = "hanging";
- }
- else if(ground.hitTest(player.getBounds(_root).xMax + 1,player._y,true) && Right && !ground.hitTest(player._x,player.getBounds(_root).yMax + 3,true) && player._y > 0)
- {
- State = "hanging";
- }
- else
- {
- jump();
- applySpeed();
- jumpHit();
- }
- }
- else if(State == "standing")
- {
- fixPosition();
- if(!ground.hitTest(player._x,player.getBounds(_root).yMax + 1,true))
- {
- State = "falling";
- }
- else if(Up)
- {
- State = "jumping";
- player._y -= 1;
- yforce = -10;
- }
- else
- {
- stand();
- applySpeed();
- standHit();
- }
- }
- }
- function fall()
- {
- yforce++;
- run(0.5);
- if(yforce <= 5 && Up && djump == "fresh")
- {
- yforce = -7;
- djump = "used";
- }
- }
- function hang()
- {
- }
- function jump()
- {
- yforce++;
- run(0.5);
- }
- function stand()
- {
- run(1);
- }
- function applySpeed()
- {
- player._x += xforce;
- player._y += yforce;
- }
- function fallHit()
- {
- while(ground.hitTest(player.getBounds(_root).xMin,player._y,true) && !ground.hitTest(player.getBounds(_root).xMax,player._y,true) && !ground.hitTest(player._x,player.getBounds(_root).yMax,true))
- {
- player._x += 1;
- }
- while(ground.hitTest(player.getBounds(_root).xMax,player._y,true) && !ground.hitTest(player.getBounds(_root).xMin,player._y,true) && !ground.hitTest(player._x,player.getBounds(_root).yMax,true))
- {
- player._x -= 1;
- }
- while(ground.hitTest(player._x,player.getBounds(_root).yMin,true) && !ground.hitTest(player._x,player.getBounds(_root).yMax,true))
- {
- player._y += 0.1;
- }
- while(ground.hitTest(player._x,player.getBounds(_root).yMax,true))
- {
- fixPosition();
- player._y -= 0.1;
- }
- }
- function hangHit()
- {
- while(!ground.hitTest(player.getBounds(_root).xMin - 1,player._y,true) && ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true))
- {
- player._x -= 0.001;
- }
- if(hangside == "right" && !ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true))
- {
- State = "falling";
- player._x += 2;
- }
- else if(hangside == "left" && !ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true))
- {
- State = "falling";
- player._x -= 2;
- }
- }
- function jumpHit()
- {
- while(ground.hitTest(player.getBounds(_root).xMin + 1,player._y,true) && !ground.hitTest(player.getBounds(_root).xMax - 1,player._y,true))
- {
- xforce = 0;
- applySpeed();
- player._x += 1;
- }
- while(ground.hitTest(player.getBounds(_root).xMax - 1,player._y,true) && !ground.hitTest(player.getBounds(_root).xMin + 1,player._y,true))
- {
- xforce = 0;
- applySpeed();
- player._x -= 1;
- }
- while(ground.hitTest(player._x,player.getBounds(_root).yMin - 1,true))
- {
- player._y += 0.1;
- yforce = 0;
- player._y += yforce;
- }
- while(ground.hitTest(player._x,player.getBounds(_root).yMax,true))
- {
- player._y -= 0.1;
- yforce = 0;
- applySpeed();
- }
- }
- function standHit()
- {
- while(ground.hitTest(player.getBounds(_root).xMin,player._y,true) && !ground.hitTest(player.getBounds(_root).xMax,player._y,true))
- {
- player._x += 0.1;
- xforce = Math.abs(xforce);
- applySpeed();
- }
- while(ground.hitTest(player.getBounds(_root).xMax,player._y,true) && !ground.hitTest(player.getBounds(_root).xMin,player._y,true))
- {
- player._x -= 0.01;
- xforce = - Math.abs(xforce);
- applySpeed();
- }
- while(ground.hitTest(player._x,player.getBounds(_root).yMax,true))
- {
- player._y -= 0.001;
- }
- }
- function getKeys()
- {
- Up = Key.isDown(38);
- Down = Key.isDown(40);
- Left = Key.isDown(37);
- Right = Key.isDown(39);
- }
- function run(amt)
- {
- if((Right || Left) && Math.abs(xforce) < maxspeed)
- {
- xforce -= amt * Left;
- xforce += amt * Right;
- }
- else
- {
- xforce *= 0.995;
- xforce *= 0.6 * friction;
- }
- }
- function seed(caller)
- {
- if(!ground.hitTest(caller._x,caller.getBounds(_root).xMax))
- {
- caller._xscale = caller._yscale += 3;
- }
- }
- function checkSide()
- {
- if(ground.hitTest(player.getBounds(_root).xMax + 4,player._y,true))
- {
- hangside = "right";
- }
- else if(ground.hitTest(player.getBounds(_root).xMin - 4,player._y,true))
- {
- hangside = "left";
- }
- }
- function animState()
- {
- if(State == "falling")
- {
- player.gotoAndStop(3);
- if(!ground.hitTest(player._x,player.getBounds(_root).yMax + 5,true))
- {
- if(Math.abs(yforce) > 5)
- {
- player._xscale = 80 - yforce;
- }
- else
- {
- player._xscale = 100 - yforce;
- }
- if(Math.abs(yforce) < 10)
- {
- player._rotation = (- xforce) * 5;
- }
- }
- player.gotoAndStop(1);
- }
- else if(State == "standing")
- {
- fixPosition();
- player.gotoAndStop(2);
- if(xforce > 0)
- {
- player.stand.eyes._xscale = 100;
- }
- else if(xforce <= 0)
- {
- player.stand.eyes._xscale = -100;
- }
- }
- else if(State == "jumping")
- {
- player.gotoAndStop(3);
- if(!ground.hitTest(player._x,player.getBounds(_root).yMax + 5,true))
- {
- if(Math.abs(yforce) > 5)
- {
- player._xscale = 80 + yforce;
- }
- else
- {
- player._xscale = 100 - yforce;
- }
- if(Math.abs(yforce) < 10)
- {
- player._rotation = xforce * 5;
- }
- }
- }
- else if(State == "hanging")
- {
- fixPosition();
- checkSide();
- if(hangside == "left")
- {
- player.gotoAndStop(4);
- }
- else if(hangside == "right")
- {
- player.gotoAndStop(5);
- }
- }
- }
- function fixPosition()
- {
- player._rotation = 0;
- player._xscale = 100;
- }
- function playerReset()
- {
- if(player._y > 300)
- {
- player._y = initialY;
- player._x = initialX;
- yforce = 0;
- xforce = 0;
- }
- }
- function playerMenu()
- {
- if(player._x > 500)
- {
- playerscore = 0;
- nextFrame();
- }
- }
- function jumpPad(caller, amount, forced)
- {
- if(caller.hitTest(player._x,player.getBounds(_root).yMax + 2,true) || forced == true)
- {
- State = "jumping";
- yforce = - amount;
- applySpeed();
- caller.play();
- }
- }
- function watchState()
- {
- if(watchStatee.length == 3)
- {
- watchStatee.pop(0);
- }
- watchStatee.unshift(State);
- if(watchStatee[0] == "standing" && watchStatee[1] == "falling" && watchStatee[2] == "standing")
- {
- sfError++;
- }
- if(watchStatee[0] == "standing" && watchStatee[1] == "falling" && watchStatee[2] == "standing" && sfError >= 3)
- {
- State = "falling";
- player._y -= 5;
- sfError = 0;
- }
- }
- function fan(caller)
- {
- if(caller.hitTest(player))
- {
- xforce -= 3;
- yforce *= 0.3;
- applySpeed();
- }
- }
- function swapFrames(up, down, left, right)
- {
- if(!up && !down && left && right)
- {
- if(player._x > 500)
- {
- nextFrame();
- }
- else if(player._x < 0)
- {
- prevFrame();
- }
- }
- else if(!up && down && left && !right)
- {
- if(player._x < 0)
- {
- prevFrame();
- }
- if(player._y > 300)
- {
- nextFrame();
- }
- }
- else if(up && !down && !left && right)
- {
- if(player._x > 500)
- {
- nextFrame();
- }
- if(player._y < 0)
- {
- prevFrame();
- }
- }
- else if(up && !down && left && !right)
- {
- if(player._x < 0)
- {
- prevFrame();
- }
- if(player._y < 0)
- {
- nextFrame();
- }
- }
- else if(!up && down && !left && right)
- {
- if(player._x > 500)
- {
- nextFrame();
- }
- if(player._y > 300)
- {
- prevFrame();
- }
- }
- }
- function fixLevel(vert, hori)
- {
- if(hori)
- {
- initialY = player._y;
- if(player._x > 490)
- {
- initialX = 0;
- player._x = 0;
- }
- else if(player._x < 10)
- {
- initialX = 498;
- player._x = 498;
- }
- else
- {
- initialX = player._x;
- initialY = 298;
- player._y = 298;
- }
- }
- else if(vert)
- {
- if(player._x < 5)
- {
- initialX = 498;
- player._x = 498;
- initialY = player._y;
- }
- else if(player._x > 495)
- {
- initialX = 2;
- player._x = 2;
- initialY = player._y;
- }
- else
- {
- initialX = player._x;
- if(player._y > 290)
- {
- initialY = 0;
- player._y = 0;
- }
- else
- {
- initialY = 298;
- player._y = 298;
- }
- }
- }
- }
- function fixLevelFirst()
- {
- initialY = player._y;
- if(player._x > 250)
- {
- initialX = player._x + 2;
- }
- else
- {
- initialX = player._x - 2;
- }
- if(player._x < 15)
- {
- player._x = 500;
- }
- }
- function time()
- {
- playerscore += 28.57142857142857;
- timer = Math.round(playerscore / 10).toString();
- if(timer.length == 2)
- {
- timer = "time = 0." + timer.charAt(0);
- }
- else if(timer.length == 3)
- {
- timer = "time = " + timer.charAt(0) + "." + timer.charAt(1) + timer.charAt(2);
- }
- else if(timer.length == 4)
- {
- timer = "time = " + timer.charAt(0) + timer.charAt(1) + "." + timer.charAt(2) + timer.charAt(3);
- }
- else if(timer.length == 5)
- {
- timer = "time = " + timer.charAt(0) + timer.charAt(1) + timer.charAt(2) + "." + timer.charAt(3);
- }
- }
- function ballPhysics(caller)
- {
- if(Math.abs(caller.byforce) < 2 && ground.hitTest(caller._x,caller._y + 13,true))
- {
- caller.byforce = 0;
- }
- ballReset(caller);
- caller.bdist = Math.sqrt(Math.pow(player._x - caller._x,2) + Math.pow(player._y - caller._y,2));
- ballHit(caller);
- caller._y += caller.byforce;
- caller._x += caller.bxforce;
- caller.bxforce *= 0.9;
- caller._rotation += 7.5398223686155035 * caller.bxforce;
- while(ground.hitTest(caller._x - 12.5,caller._y,true))
- {
- caller._x = caller._x + 1;
- caller.bxforce = 0;
- }
- while(ground.hitTest(caller._x + 12.5,caller._y,true))
- {
- caller._x = caller._x - 1;
- caller.bxforce = 0;
- if(caller._y <= player._y)
- {
- caller.byforce = -5;
- }
- }
- if(ground.hitTest(caller._x + 13,caller._y,true) || ground.hitTest(caller._x - 13,caller._y,true))
- {
- caller.bdist = Math.sqrt(Math.pow(player._x - caller._x,2) + Math.pow(player._y - caller._y,2));
- if(caller.bdist < 17.5)
- {
- if(caller._y <= player._y)
- {
- caller._y = caller._y - 1;
- caller.byforce = -5;
- }
- }
- }
- if(ground.hitTest(caller._x + 12.6,caller._y,true))
- {
- caller._x -= 0.02;
- }
- else if(ground.hitTest(caller._x - 12.6,caller._y,true))
- {
- caller._x += 0.02;
- }
- if(ground.hitTest(caller._x,caller._y + 12.5,true))
- {
- while(ground.hitTest(caller._x,caller._y + 12,true))
- {
- caller._y = caller._y - 1;
- }
- caller.byforce = (- caller.byforce) / 2;
- if(Math.abs(caller.byforce) < 2)
- {
- if(!ground.hitTest(caller._x + 15,caller._y,true) && !ground.hitTest(caller._x - 15,caller._y,true))
- {
- caller.byforce = 0;
- }
- }
- }
- else
- {
- caller.byforce = caller.byforce + 1;
- }
- }
- function ballHit(caller)
- {
- if(caller.bdist < 17.5)
- {
- if(player._x < caller._x)
- {
- caller.bxforce += 2;
- }
- else
- {
- caller.bxforce -= 2;
- }
- if(caller._y > player._y)
- {
- yforce -= 3;
- }
- }
- if(caller.bdist < 17.5)
- {
- caller.bdist = Math.sqrt(Math.pow(player._x - caller._x,2) + Math.pow(player._y - caller._y,2));
- if(player._x < caller._x)
- {
- caller._x += 0.05;
- }
- else
- {
- caller._x -= 0.05;
- }
- }
- }
- function ballReset(caller)
- {
- if(caller._y + 10 > 300)
- {
- caller._x = caller.initialX;
- caller._y = caller.initialY;
- caller.bxforce = 0;
- caller.byforce = 0;
- caller._rotation = Math.round(Math.random() * 360);
- }
- }
- function fixBall(bx, by, caller)
- {
- caller._x = bx;
- caller._y = by;
- caller.initialX = caller._x;
- caller.initialY = caller._y;
- }
- function buttonPress(caller, victim)
- {
- if(caller.hitTest(player) || caller.hitTest(victim))
- {
- if(caller.debounce != 10)
- {
- caller.debounce = caller.debounce + 1;
- }
- }
- else if(caller.debounce != 0)
- {
- caller.debounce = caller.debounce - 1;
- }
- if(caller.debounce >= 5 && caller.debounce <= 10)
- {
- caller.nextFrame();
- }
- else
- {
- caller.prevFrame();
- }
- }
- function attachFrames(caller)
- {
- caller.gotoAndStop(ground.button._currentframe);
- }
- function oilSlick(caller)
- {
- if(caller.hitTest(player._x,player._y + 13,true))
- {
- friction = 1.6666666666666667;
- }
- else
- {
- friction = 1;
- }
- }
- function affectPad(caller, victim)
- {
- if(player.hitTest(caller))
- {
- victim.nextFrame();
- }
- }
- function groundFall(caller)
- {
- if(player.hitTest(caller))
- {
- caller.play();
- }
- }
- function lowGravity()
- {
- if(ground.button._currentframe != 1)
- {
- yforce /= 0.95;
- }
- }
- function controlVolume()
- {
- if(vol == 100)
- {
- vol = 0;
- }
- else
- {
- vol = 100;
- }
- sound.setVolume(vol);
- }
- function reset()
- {
- gotoAndStop("menu");
- player._x = 70;
- player._y = 220;
- sound.start(1);
- }
- var State = "falling";
- var xforce = 0;
- var yforce = 0;
- var maxspeed = 5;
- var djump = "fresh";
- var hangside = "left";
- var watchStatee = new Array();
- var sfError = 0;
- var where = 2;
- var playerscore = 0;
- var timer;
- var friction = 1;
- var vol = 100;
- var sound = new Sound(song);
- nextFrame();
-