home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / breakawish.swf / scripts / __Packages / PlayerStatus.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  3.8 KB  |  131 lines

  1. class PlayerStatus
  2. {
  3.    var nScore;
  4.    var nShownScore;
  5.    var nMaxCombo;
  6.    var nLevelToPlay;
  7.    var nRemainingLives;
  8.    var mcHUD;
  9.    static var nTIME_FOR_EXTRA_POINTS = 30000;
  10.    static var aSPEED_ADDONS = [1.25,1.5,1.75,2,2.25,2.25,2.5,2.5,2.75,2.75,3,3,3.25,3.25,3.5,3.5,3.75,3.75,4,4];
  11.    static var nTOTAL_LEVELS = 20;
  12.    static var nTOTAL_LIVES = 5;
  13.    static var nSCORE_CHANGE_RATE = 15;
  14.    static var nMAX_SCORE_GAP = 280;
  15.    static var nPOINTS_COMBO_LEVEL = 250;
  16.    static var nPOINTS_BLOCK_HIT = 10;
  17.    static var nPOINTS_BLOCK_CRUSH = 50;
  18.    static var nPOINTS_BONUS = 150;
  19.    static var nPOINTS_LEVEL_END = 750;
  20.    static var nPOINTS_PER_MILLISECONDS = 0.25;
  21.    function PlayerStatus()
  22.    {
  23.       this.nScore = 0;
  24.       this.nShownScore = 0;
  25.       this.nMaxCombo = 0;
  26.       this.nLevelToPlay = 1;
  27.       this.nRemainingLives = PlayerStatus.nTOTAL_LIVES;
  28.       this.doUpdateStaticHud();
  29.       this.doUpdatePoints();
  30.       Main.Instance.doAddListener(this);
  31.    }
  32.    function doEnterFrame()
  33.    {
  34.       if(this.nShownScore != this.nScore)
  35.       {
  36.          this.doUpdatePoints();
  37.       }
  38.    }
  39.    function setHud(_mcHUD)
  40.    {
  41.       this.mcHUD = _mcHUD;
  42.       this.doUpdateStaticHud();
  43.       this.doUpdatePoints();
  44.    }
  45.    function onGainLive()
  46.    {
  47.       this.nRemainingLives = this.nRemainingLives + 1;
  48.       this.doUpdateStaticHud();
  49.    }
  50.    function onLoseLive()
  51.    {
  52.       this.nRemainingLives = this.nRemainingLives - 1;
  53.       this.doUpdateStaticHud();
  54.    }
  55.    function getPlayerCanContinue()
  56.    {
  57.       return this.nRemainingLives >= 0;
  58.    }
  59.    function onPlayerCompleteLevel(_nTimeRemaining)
  60.    {
  61.       this.doAddPoints(PlayerStatus.nPOINTS_LEVEL_END + _nTimeRemaining * PlayerStatus.nPOINTS_PER_MILLISECONDS);
  62.       this.nLevelToPlay = this.nLevelToPlay + 1;
  63.       this.doUpdateStaticHud();
  64.    }
  65.    function getIsMoreLevelToPlay()
  66.    {
  67.       return this.nLevelToPlay <= PlayerStatus.nTOTAL_LEVELS;
  68.    }
  69.    function getLevelToPlay()
  70.    {
  71.       return this.nLevelToPlay;
  72.    }
  73.    function onNewCombo(_nCombo)
  74.    {
  75.       var _loc2_ = this.nMaxCombo;
  76.       this.nMaxCombo = Math.max(this.nMaxCombo,_nCombo);
  77.       this.doUpdateStaticHud();
  78.       this.doAddPoints(PlayerStatus.nPOINTS_COMBO_LEVEL * (this.nMaxCombo - _loc2_));
  79.    }
  80.    function doAddPoints(_nPoints)
  81.    {
  82.       this.nScore += Math.floor(_nPoints);
  83.    }
  84.    function onBlockHit()
  85.    {
  86.       this.doAddPoints(PlayerStatus.nPOINTS_BLOCK_HIT);
  87.    }
  88.    function onBlockCrushed()
  89.    {
  90.       this.doAddPoints(PlayerStatus.nPOINTS_BLOCK_CRUSH);
  91.    }
  92.    function onCatchBonus()
  93.    {
  94.       this.doAddPoints(PlayerStatus.nPOINTS_BONUS);
  95.    }
  96.    function doDestroy()
  97.    {
  98.       Main.Instance.doRemoveListener(this);
  99.       delete this.mcHUD;
  100.    }
  101.    function get SpeedAddon()
  102.    {
  103.       return PlayerStatus.aSPEED_ADDONS[this.nLevelToPlay - 1];
  104.    }
  105.    function get Score()
  106.    {
  107.       return Math.floor(this.nScore);
  108.    }
  109.    function doUpdateStaticHud()
  110.    {
  111.       this.mcHUD.txtLives.text = Math.max(0,this.nRemainingLives);
  112.       this.mcHUD.txtCombo.text = Library.Utils.Tools.getFormatedNumber(this.nMaxCombo,3);
  113.       this.mcHUD.txtLevel.text = Library.Utils.Tools.getFormatedNumber(Math.min(PlayerStatus.nTOTAL_LEVELS,this.nLevelToPlay),2);
  114.    }
  115.    function doUpdatePoints()
  116.    {
  117.       this.nScore = Math.floor(this.nScore);
  118.       if(this.nShownScore + PlayerStatus.nMAX_SCORE_GAP < this.nScore)
  119.       {
  120.          var _loc2_ = this.nScore - this.nShownScore;
  121.          this.nShownScore += Math.floor(_loc2_ * 0.6666666666666666);
  122.       }
  123.       else
  124.       {
  125.          this.nShownScore = Library.Utils.MoreMath.getReachNum(this.nShownScore,this.nScore,PlayerStatus.nSCORE_CHANGE_RATE);
  126.       }
  127.       this.nShownScore = Math.floor(this.nShownScore);
  128.       this.mcHUD.txtScore.text = Library.Utils.Tools.getFormatedNumber(this.nShownScore,6);
  129.    }
  130. }
  131.