home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / attention_hog.swf / scripts / __Packages / com / leadpipe / attentionhog / Player.as < prev    next >
Encoding:
Text File  |  2008-09-22  |  14.3 KB  |  472 lines

  1. class com.leadpipe.attentionhog.Player extends MovieClip
  2. {
  3.    var startPos;
  4.    var speed;
  5.    var accel;
  6.    var accelCntr;
  7.    var accelInc;
  8.    var spinInc;
  9.    var gotoX;
  10.    var gotoY;
  11.    var moveMode;
  12.    var ghostMode;
  13.    var baconMode;
  14.    var timerBacon;
  15.    var grunt;
  16.    var squeal;
  17.    var timerAttentionSpan;
  18.    var attentionSpan_mc;
  19.    var attentionSpanShowSwitch;
  20.    var redTrans;
  21.    var normalTrans;
  22.    var trans;
  23.    var body_mc;
  24.    var warningSwitch;
  25.    var dead;
  26.    var abilities;
  27.    var radiant_mc;
  28.    var isPaused;
  29.    var lastXMouse;
  30.    var lastYMouse;
  31.    var warningInterval;
  32.    var warningThresholdLow;
  33.    var warningThresholdHigh;
  34.    var feelingLove;
  35.    var delta_x;
  36.    var delta_y;
  37.    var angle;
  38.    var greasedPowerMode;
  39.    var wholeHogMode;
  40.    var hogTiedMode;
  41.    var radiantMask_mc;
  42.    var mouseIsDown;
  43.    var captured;
  44.    static var posX;
  45.    static var posY;
  46.    static var instance = null;
  47.    static var play_maxY = 380;
  48.    function Player()
  49.    {
  50.       super();
  51.       this.startPos = new flash.geom.Point(Stage.width / 2,205);
  52.       this._x = Stage.width / 2;
  53.       this._y = 230;
  54.       this.speed = 0;
  55.       this.accel = 0;
  56.       this.accelCntr = 0;
  57.       this.accelInc = 1;
  58.       this.spinInc = 0;
  59.       this.gotoX = _root._xmouse;
  60.       this.gotoY = _root._ymouse;
  61.       this.moveMode = "WALK";
  62.       this.ghostMode = false;
  63.       com.leadpipe.attentionhog.Player.instance = this;
  64.       this.baconMode = false;
  65.       this.timerBacon = new com.leadpipe.attentionhog.Timer(this,"stopBaconMode",5000,5000);
  66.       this.grunt = new Sound(this);
  67.       this.grunt.attachSound("grunt2");
  68.       this.squeal = new Sound(this);
  69.       this.squeal.attachSound("squeal");
  70.       this.timerAttentionSpan = new com.leadpipe.attentionhog.Timer(this,"fadeAttentionSpan",30,30);
  71.       this.attentionSpan_mc._alpha = 0;
  72.       this.attentionSpanShowSwitch = 0;
  73.       this.redTrans = new flash.geom.ColorTransform(1,0.2,0.2,1,0,0,0,0);
  74.       this.normalTrans = new flash.geom.ColorTransform(1,1,1,1,0,0,0,0);
  75.       this.trans = new flash.geom.Transform(this.body_mc);
  76.       this.trans.colorTransform = null;
  77.       _root.bgBacon_mc._alpha = 0;
  78.       this.warningSwitch = 0;
  79.       this.dead = false;
  80.       this.abilities = new Array(new com.leadpipe.attentionhog.Ability(this,"setGreasedPig",49,_root.hud_mc.gauge0.icon_mc,com.leadpipe.attentionhog.Game.instance.gaugeSlop[0],false),new com.leadpipe.attentionhog.Ability(this,"setWholeHog",50,_root.hud_mc.gauge1.icon_mc,com.leadpipe.attentionhog.Game.instance.gaugeSlop[1],false),new com.leadpipe.attentionhog.Ability(this,"setSwineAndDine",51,_root.hud_mc.gauge2.icon_mc,com.leadpipe.attentionhog.Game.instance.gaugeSlop[2],true),new com.leadpipe.attentionhog.Ability(this,"setBigHam",52,_root.hud_mc.gauge3.icon_mc,com.leadpipe.attentionhog.Game.instance.gaugeSlop[3],false),new com.leadpipe.attentionhog.Ability(this,"setPigsEye",53,_root.hud_mc.gauge4.icon_mc,com.leadpipe.attentionhog.Game.instance.gaugeSlop[4],false),new com.leadpipe.attentionhog.Ability(this,"setHogTied",54,_root.hud_mc.gauge5.icon_mc,com.leadpipe.attentionhog.Game.instance.gaugeSlop[5],false));
  81.       this.radiant_mc._alpha = 0;
  82.    }
  83.    function pause(p)
  84.    {
  85.       this.isPaused = p;
  86.    }
  87.    function soundOn(s)
  88.    {
  89.       if(s)
  90.       {
  91.          this.grunt.setVolume(100);
  92.          this.squeal.setVolume(100);
  93.       }
  94.       else
  95.       {
  96.          this.grunt.setVolume(0);
  97.          this.squeal.setVolume(0);
  98.       }
  99.    }
  100.    function startGrunt()
  101.    {
  102.       this.grunt.start(0,1);
  103.    }
  104.    function onMouseMove()
  105.    {
  106.       if(this.isPaused)
  107.       {
  108.          return undefined;
  109.       }
  110.       this.lastXMouse = _root._xmouse;
  111.       if(_root._ymouse >= 30 && _root._ymouse <= com.leadpipe.attentionhog.Player.play_maxY)
  112.       {
  113.          this.lastYMouse = _root._ymouse;
  114.       }
  115.       this.gotoX = this.lastXMouse;
  116.       this.gotoY = this.lastYMouse;
  117.    }
  118.    function warningFlash()
  119.    {
  120.       if(this._alpha == 0)
  121.       {
  122.          this._alpha = 100;
  123.       }
  124.       else
  125.       {
  126.          this._alpha = 0;
  127.       }
  128.    }
  129.    function go()
  130.    {
  131.       if(this.dead)
  132.       {
  133.          return undefined;
  134.       }
  135.       var _loc2_ = com.leadpipe.attentionhog.Game.instance.gaugeMain.getLevel();
  136.       if(_loc2_ <= 0)
  137.       {
  138.          this.dead = true;
  139.          this.gotoAndPlay("dead");
  140.          com.leadpipe.attentionhog.Game.instance.die();
  141.          clearInterval(this.warningInterval);
  142.          this._alpha = 100;
  143.          return undefined;
  144.       }
  145.       if(_loc2_ <= 20)
  146.       {
  147.          this.warningSwitch = this.warningSwitch + 1;
  148.          if(this.warningSwitch == 1)
  149.          {
  150.             this.warningThresholdLow = 0;
  151.             this.warningThresholdHigh = 15;
  152.             if(this.warningInterval != null)
  153.             {
  154.                clearInterval(this.warningInterval);
  155.             }
  156.             this.warningInterval = setInterval(this,"warningFlash",100);
  157.          }
  158.       }
  159.       if(_loc2_ <= this.warningThresholdLow || _loc2_ >= this.warningThresholdHigh)
  160.       {
  161.          clearInterval(this.warningInterval);
  162.          this._alpha = 100;
  163.          this.warningSwitch = 0;
  164.       }
  165.       for(var _loc3_ in this.abilities)
  166.       {
  167.          this.abilities[_loc3_].check();
  168.       }
  169.       this.checkCapture();
  170.       if(!this.feelingLove)
  171.       {
  172.          com.leadpipe.attentionhog.Game.instance.gaugeMain.decrease();
  173.       }
  174.       this.delta_x = this._x - this.gotoX;
  175.       this.delta_y = this._y - this.gotoY;
  176.       this.angle = (- Math.atan2(this.delta_x,this.delta_y)) / 0.017453292519943295;
  177.       this.rotatePlayer();
  178.       this.moveWalk();
  179.       com.leadpipe.attentionhog.Player.posX = this._x;
  180.       com.leadpipe.attentionhog.Player.posY = this._y;
  181.    }
  182.    function setGreasedPig(isActive, isPowerUp)
  183.    {
  184.       if(isActive && isPowerUp)
  185.       {
  186.          this.accelInc = 1000;
  187.       }
  188.       else if(isActive)
  189.       {
  190.          this.accelInc = 10;
  191.       }
  192.       else
  193.       {
  194.          this.greasedPowerMode = false;
  195.          this.accelInc = 1;
  196.       }
  197.    }
  198.    function setWholeHog(isActive, isPowerUp)
  199.    {
  200.       if(isActive && isPowerUp)
  201.       {
  202.          com.leadpipe.attentionhog.Game.instance.proxThreshold = 175;
  203.          this.spinInc = 45;
  204.          this.wholeHogMode = true;
  205.       }
  206.       else if(isActive)
  207.       {
  208.          com.leadpipe.attentionhog.Game.instance.proxThreshold = 125;
  209.          this.spinInc = 20;
  210.          this.wholeHogMode = true;
  211.       }
  212.       else
  213.       {
  214.          com.leadpipe.attentionhog.Game.instance.proxThreshold = 75;
  215.          this.spinInc = 0;
  216.          this.wholeHogMode = false;
  217.       }
  218.       this.attentionSpan_mc._width = com.leadpipe.attentionhog.Game.instance.proxThreshold * 2;
  219.       this.attentionSpan_mc._height = com.leadpipe.attentionhog.Game.instance.proxThreshold * 2;
  220.    }
  221.    function setSwineAndDine(isActive, isPowerUp)
  222.    {
  223.       if(isActive && isPowerUp)
  224.       {
  225.          var _loc3_ = com.leadpipe.attentionhog.Ghost.instanceList.length;
  226.          var _loc4_ = com.leadpipe.attentionhog.Game.instance.ghostDepthInit + _loc3_;
  227.          _root.attachMovie("hog_mc","ghost" + _loc3_,_loc4_,{_alpha:60,_x:this._x,_y:this._y});
  228.          com.leadpipe.attentionhog.Ghost.instanceList[_loc3_]._rotation = this.body_mc._rotation;
  229.       }
  230.       else if(isActive)
  231.       {
  232.          _loc3_ = com.leadpipe.attentionhog.Ghost.instanceList.length;
  233.          _loc4_ = com.leadpipe.attentionhog.Game.instance.ghostDepthInit + _loc3_;
  234.          _root.attachMovie("hog_mc","ghost" + _loc3_,_loc4_,{_alpha:60,_x:this._x,_y:this._y});
  235.          com.leadpipe.attentionhog.Ghost.instanceList[_loc3_]._rotation = this.body_mc._rotation;
  236.          this.ghostMode = true;
  237.       }
  238.       else
  239.       {
  240.          com.leadpipe.attentionhog.Ghost.beginFadeAll();
  241.          this.ghostMode = false;
  242.       }
  243.    }
  244.    function setBigHam(isActive, isPowerUp)
  245.    {
  246.       if(isActive && isPowerUp)
  247.       {
  248.          this.body_mc.gotoAndPlay("jump");
  249.          this.body_mc.scale_mc.gotoAndPlay("jump");
  250.          com.leadpipe.attentionhog.Game.instance.gaugeMain.setSpeed(0.03,0.2);
  251.       }
  252.       else if(isActive)
  253.       {
  254.          this.body_mc.gotoAndPlay("jump");
  255.          this.body_mc.scale_mc.gotoAndPlay("jump");
  256.          com.leadpipe.attentionhog.Game.instance.gaugeMain.setSpeed(0.02,0.2);
  257.       }
  258.       else
  259.       {
  260.          this.body_mc.gotoAndStop(1);
  261.          this.body_mc.scale_mc.gotoAndStop(1);
  262.          com.leadpipe.attentionhog.Game.instance.gaugeMain.setSpeed(0.01,0.2);
  263.       }
  264.    }
  265.    function setPigsEye(isActive, isPowerUp)
  266.    {
  267.       if(isActive && isPowerUp)
  268.       {
  269.          this.body_mc.scale_mc.eye1_mc.gotoAndPlay("flashPowerUp");
  270.          this.body_mc.scale_mc.eye2_mc.gotoAndPlay("flashPowerUp");
  271.          for(var _loc2_ in com.leadpipe.attentionhog.Person.instanceList)
  272.          {
  273.             com.leadpipe.attentionhog.Person.instanceList[_loc2_].gauge.setSpeed(1,0.25);
  274.          }
  275.       }
  276.       else if(isActive)
  277.       {
  278.          this.body_mc.scale_mc.eye1_mc.gotoAndPlay("flash");
  279.          this.body_mc.scale_mc.eye2_mc.gotoAndPlay("flash");
  280.          for(_loc2_ in com.leadpipe.attentionhog.Person.instanceList)
  281.          {
  282.             com.leadpipe.attentionhog.Person.instanceList[_loc2_].gauge.setSpeed(1,0.5);
  283.          }
  284.       }
  285.       else
  286.       {
  287.          this.body_mc.scale_mc.eye1_mc.gotoAndStop(1);
  288.          this.body_mc.scale_mc.eye2_mc.gotoAndStop(1);
  289.          for(_loc2_ in com.leadpipe.attentionhog.Person.instanceList)
  290.          {
  291.             com.leadpipe.attentionhog.Person.instanceList[_loc2_].gauge.setSpeed(1,1);
  292.          }
  293.       }
  294.    }
  295.    function setHogTied(isActive, isPowerUp)
  296.    {
  297.       if(isActive && isPowerUp)
  298.       {
  299.          this.hogTiedMode = true;
  300.          this.radiant_mc._alpha = 65;
  301.          this.radiant_mc.gotoAndPlay(1);
  302.          this.radiantMask_mc.gotoAndPlay(1);
  303.          com.leadpipe.attentionhog.Person.followPlayerAll(true,2);
  304.       }
  305.       else if(isActive)
  306.       {
  307.          this.hogTiedMode = true;
  308.          this.radiant_mc._alpha = 65;
  309.          this.radiant_mc.gotoAndPlay(1);
  310.          this.radiantMask_mc.gotoAndPlay(1);
  311.          com.leadpipe.attentionhog.Person.followPlayerAll(true,1);
  312.       }
  313.       else
  314.       {
  315.          this.hogTiedMode = false;
  316.          this.radiant_mc._alpha = 0;
  317.          com.leadpipe.attentionhog.Person.followPlayerAll(false,1);
  318.       }
  319.    }
  320.    function setBaconMode(b)
  321.    {
  322.       this.baconMode = b;
  323.       if(this.baconMode)
  324.       {
  325.          this.squeal.start(0,1);
  326.          this.timerBacon.start();
  327.          this.trans.colorTransform = this.redTrans;
  328.          _root.bgBacon_mc._alpha = 100;
  329.          com.leadpipe.attentionhog.Ability.disableAll(true);
  330.       }
  331.    }
  332.    function stopBaconMode()
  333.    {
  334.       this.timerBacon.clear();
  335.       this.baconMode = false;
  336.       this.trans.colorTransform = this.normalTrans;
  337.       _root.bgBacon_mc._alpha = 0;
  338.       com.leadpipe.attentionhog.Ability.disableAll(false);
  339.    }
  340.    function fadeAttentionSpan()
  341.    {
  342.       if(this.attentionSpan_mc._alpha <= 0)
  343.       {
  344.          this.timerAttentionSpan.clear();
  345.          this.attentionSpanShowSwitch = 0;
  346.          this.attentionSpan_mc._alpha = 0;
  347.       }
  348.       else
  349.       {
  350.          this.attentionSpan_mc._alpha -= 2;
  351.       }
  352.    }
  353.    function onMouseDown()
  354.    {
  355.       if(this.isPaused)
  356.       {
  357.          return undefined;
  358.       }
  359.       this.mouseIsDown = true;
  360.       this.attentionSpanShowSwitch = this.attentionSpanShowSwitch + 1;
  361.       if(this.attentionSpanShowSwitch == 1)
  362.       {
  363.          this.attentionSpan_mc._alpha = 80;
  364.          this.timerAttentionSpan.clear();
  365.          this.timerAttentionSpan.start();
  366.       }
  367.    }
  368.    function onMouseUp()
  369.    {
  370.       if(this.isPaused)
  371.       {
  372.          return undefined;
  373.       }
  374.       this.attentionSpanShowSwitch = 0;
  375.       this.mouseIsDown = false;
  376.       if(this.moveMode == "WALK")
  377.       {
  378.          this.moveMode = "JUMP";
  379.          this.gotoAndPlay("jump");
  380.       }
  381.    }
  382.    function checkCapture()
  383.    {
  384.       this.captured = 0;
  385.       var _loc2_ = 0;
  386.       while(_loc2_ < com.leadpipe.attentionhog.Person.instanceList.length)
  387.       {
  388.          if(com.leadpipe.attentionhog.Person.instanceList[_loc2_].checkCapture())
  389.          {
  390.             this.captured = this.captured + 1;
  391.          }
  392.          _loc2_ = _loc2_ + 1;
  393.       }
  394.       if(this.captured > 0)
  395.       {
  396.          this.feelingLove = true;
  397.       }
  398.       else
  399.       {
  400.          this.feelingLove = false;
  401.       }
  402.       com.leadpipe.attentionhog.Game.instance.setScore(this.captured);
  403.       this.captured = 0;
  404.    }
  405.    function rotatePlayer()
  406.    {
  407.       if(this.wholeHogMode)
  408.       {
  409.          this.body_mc._rotation += this.spinInc;
  410.       }
  411.       else if(!(this.delta_x == 0 && this.delta_y == 0))
  412.       {
  413.          this.body_mc._rotation = this.angle;
  414.       }
  415.    }
  416.    function moveWalk()
  417.    {
  418.       if(this.greasedPowerMode == true)
  419.       {
  420.          this._x = this.lastXMouse;
  421.          this._y = this.lastYMouse;
  422.          this.speed = 0;
  423.          this.accel = 0;
  424.          this.accelCntr = 0;
  425.       }
  426.       else
  427.       {
  428.          this.accelCntr += this.accelInc;
  429.          this.accel = Math.pow(this.accelCntr,2);
  430.          if(this.baconMode)
  431.          {
  432.             this.speed = 1;
  433.             this.accelCntr = 0;
  434.          }
  435.          else
  436.          {
  437.             this.speed += this.accel / 3000;
  438.          }
  439.          if(Math.sqrt(this.delta_x * this.delta_x + this.delta_y * this.delta_y) > this.speed)
  440.          {
  441.             this._y -= this.speed * Math.cos(this.angle * 0.017453292519943295);
  442.             this._x += this.speed * Math.sin(this.angle * 0.017453292519943295);
  443.          }
  444.          else
  445.          {
  446.             this.speed = 0;
  447.             this.accel = 0;
  448.             this.accelCntr = 0;
  449.             this._x = this.lastXMouse;
  450.             this._y = this.lastYMouse;
  451.          }
  452.       }
  453.    }
  454.    function moveJump()
  455.    {
  456.       this._x += (this.lastXMouse - this._x) / 5;
  457.       this._y += (this.lastYMouse - this._y) / 5;
  458.    }
  459.    function destroy()
  460.    {
  461.       this.removeMovieClip();
  462.    }
  463.    static function getInstance()
  464.    {
  465.       if(com.leadpipe.attentionhog.Player.instance == null)
  466.       {
  467.          com.leadpipe.attentionhog.Player.instance = new com.leadpipe.attentionhog.Player();
  468.       }
  469.       return com.leadpipe.attentionhog.Player.instance;
  470.    }
  471. }
  472.