home *** CD-ROM | disk | FTP | other *** search
/ Champak 112 / jogo-disk-112.iso / Games / barrels_of_monkey.swf / scripts / DefineSprite_76 / frame_1 / DoAction_2.as next >
Text File  |  2010-07-14  |  3KB  |  104 lines

  1. function mainLoop()
  2. {
  3.    if(!gameOver)
  4.    {
  5.       f++;
  6.    }
  7.    else if(crosshair._xscale < 1000)
  8.    {
  9.       crosshair._xscale = crosshair._yscale *= 1.2;
  10.       crosshair2._xscale = crosshair2._yscale *= 1.3;
  11.    }
  12.    else
  13.    {
  14.       crosshair2._visible = crosshair._visible = false;
  15.    }
  16.    if(f == totalFrames)
  17.    {
  18.       endGame();
  19.    }
  20.    else
  21.    {
  22.       counter++;
  23.       if(counter > alienFrequency)
  24.       {
  25.          popUpAlien();
  26.       }
  27.       if(shotsMissed > lastShotsMissed)
  28.       {
  29.       }
  30.       lastShotsMissed = shotsMissed;
  31.    }
  32. }
  33. function popUpAlien()
  34. {
  35.    counter = 0;
  36.    do
  37.    {
  38.       selectedAlien = Math.ceil(Math.random() * 5);
  39.    }
  40.    while(this["alien" + selectedAlien].active);
  41.    
  42.    totalAliens++;
  43.    this["alien" + selectedAlien].gotoAndPlay("alive");
  44.    this["alien" + selectedAlien].active = true;
  45. }
  46. function shotAlien()
  47. {
  48.    if(!this.dead)
  49.    {
  50.       if(!gameOver)
  51.       {
  52.          this.dead = true;
  53.          master.playSound("yes");
  54.          this.anim.gotoAndPlay("dead");
  55.          updateScore(hitScore);
  56.          nextAlienFrequency = Math.ceil(alienStartFrequency - score);
  57.          if(nextAlienFrequency < minAlienFrequency)
  58.          {
  59.             nextAlienFrequency = minAlienFrequency;
  60.          }
  61.          alienFrequency = nextAlienFrequency;
  62.          shotsMissed--;
  63.       }
  64.    }
  65. }
  66. function updateScore(n)
  67. {
  68.    score += n;
  69. }
  70. function endGame()
  71. {
  72.    finalScore = 1;
  73.    if(!endGameOnce)
  74.    {
  75.       master.show();
  76.       gameOver = true;
  77.       finalScore = score / totalAliens;
  78.       finalScore = Math.floor(finalScore * 100);
  79.       trace("MISSED=" + shotsMissed + ", shotindex:" + shotIndex);
  80.       accuracy = 1 - shotsMissed / shotIndex;
  81.       trace("accuracy=" + accuracy * 100 + "%");
  82.       trace(score + "/" + totalAliens + "=" + finalScore);
  83.       finalScore *= (accuracy + 1) / 2;
  84.       finalScore = Math.floor(finalScore);
  85.       master.playSound("timeup");
  86.       finalScore = !isNaN(finalScore) ? finalScore : 1;
  87.       trace("FINAL SCORE=" + finalScore);
  88.       _parent.endGameBlackOut(finalScore,"timeup");
  89.       endGameOnce = true;
  90.    }
  91. }
  92. onMouseDown = function()
  93. {
  94.    if(!gameOver)
  95.    {
  96.       shotIndex++;
  97.       duplicateMovieClip(this.shot,"shot" + shotIndex,16384 + this.getNextHighestDepth());
  98.       this["shot" + shotIndex]._x = crosshair._x;
  99.       this["shot" + shotIndex]._y = crosshair._y;
  100.       shotsMissed++;
  101.    }
  102. };
  103. controller.onEnterFrame = mainLoop;
  104.