home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 October - Disc 1 / PCNET_CD_2006_10_1.iso / surpriz / circle.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2004-07-29  |  9.1 KB  |  230 lines

  1. function rotateInner()
  2. {
  3.    mcInnerHolder.circle1._rotation += oGunPos.directionOuter * oGunPos.speedOuter;
  4.    mcInnerHolder.circle2._rotation += oGunPos.directionOuter * oGunPos.speedOuter;
  5.    mcInnerHolder.smallCircle1._rotation += oGunPos.directionInner * oGunPos.speedInner;
  6.    mcInnerHolder.smallCircle2._rotation += oGunPos.directionInner * oGunPos.speedInner;
  7.    mcInnerHolder.mcScoreHolder.tScore.text = "Score: " + oGunPos.score;
  8.    mcInnerHolder.mcScoreHolder.tScore.border = true;
  9.    mcInnerHolder.mcTimeHolder.tTime.text = Math.ceil(oGunPos.timer);
  10.    var _loc2_ = new TextFormat();
  11.    _loc2_.bold = true;
  12.    _loc2_.color = 0;
  13.    _loc2_.size = 20;
  14.    mcInnerHolder.mcScoreHolder.tScore.setTextFormat(_loc2_);
  15.    var _loc1_ = new TextFormat();
  16.    _loc1_.bold = true;
  17.    _loc1_.color = 102;
  18.    _loc1_.size = 20;
  19.    mcInnerHolder.mcTimeHolder.tTime.setTextFormat(_loc1_);
  20.    oGunPos.timer -= 0.02;
  21.    if(oGunPos.timer < 0)
  22.    {
  23.       clearInterval(nSendShot);
  24.       summary();
  25.    }
  26.    updateAfterEvent();
  27. }
  28. function moveGun()
  29. {
  30.    if(Key.isDown(37))
  31.    {
  32.       mcInnerHolder.gun._rotation -= 1.5;
  33.       oGunPos.x = Math.cos(mcInnerHolder.gun._rotation / 180 * 3.141592653589793);
  34.       oGunPos.y = Math.sin(mcInnerHolder.gun._rotation / 180 * 3.141592653589793);
  35.    }
  36.    if(Key.isDown(39))
  37.    {
  38.       mcInnerHolder.gun._rotation += 1.5;
  39.       oGunPos.x = Math.cos(mcInnerHolder.gun._rotation / 180 * 3.141592653589793);
  40.       oGunPos.y = Math.sin(mcInnerHolder.gun._rotation / 180 * 3.141592653589793);
  41.    }
  42.    if(Key.isDown(32))
  43.    {
  44.       if(oGunPos.oneShot)
  45.       {
  46.          oGunPos.oneShot = false;
  47.          oGunPos.x = Math.cos(mcInnerHolder.gun._rotation / 180 * 3.141592653589793);
  48.          oGunPos.y = Math.sin(mcInnerHolder.gun._rotation / 180 * 3.141592653589793);
  49.          mcShotHolder.shot._x = oGunPos.x * 225 + Stage.width / 2;
  50.          mcShotHolder.shot._y = oGunPos.y * 225 + Stage.height / 2;
  51.          mcShotHolder.shot._visible = true;
  52.          nSendShot = setInterval(sendShot,10,oGunPos.x,oGunPos.y);
  53.       }
  54.    }
  55.    updateAfterEvent();
  56. }
  57. function sendShot(x, y)
  58. {
  59.    mcShotHolder.shot._x += (- x) * oGunPos.speedShot;
  60.    mcShotHolder.shot._y += (- y) * oGunPos.speedShot;
  61.    if(mcInnerHolder.circle1.hitTest(mcShotHolder.shot._x,mcShotHolder.shot._y,true) || mcInnerHolder.circle2.hitTest(mcShotHolder.shot._x,mcShotHolder.shot._y,true) || mcInnerHolder.smallCircle1.hitTest(mcShotHolder.shot._x,mcShotHolder.shot._y,true) || mcInnerHolder.smallCircle2.hitTest(mcShotHolder.shot._x,mcShotHolder.shot._y,true))
  62.    {
  63.       clearInterval(nSendShot);
  64.       youLose();
  65.    }
  66.    if(Math.abs(mcShotHolder.shot._x - Stage.width / 2) < 40 && Math.abs(mcShotHolder.shot._y - Stage.height / 2) < 40)
  67.    {
  68.       clearInterval(nSendShot);
  69.       youWin();
  70.    }
  71.    updateAfterEvent();
  72. }
  73. function youWin()
  74. {
  75.    oGunPos.score = oGunPos.score + 1;
  76.    _root.mcShotHolder.removeMovieClip();
  77.    _root.mcInnerHolder.removeMovieClip();
  78.    newLevel();
  79. }
  80. function youLose()
  81. {
  82.    oGunPos.timer -= 10;
  83.    if(oGunPos.timer < 0)
  84.    {
  85.       summary();
  86.    }
  87.    _root.mcShotHolder.removeMovieClip();
  88.    _root.mcInnerHolder.removeMovieClip();
  89.    newLevel();
  90. }
  91. function summary()
  92. {
  93.    clearInterval(nRotInr);
  94.    clearInterval(nSendShot);
  95.    removeMovieClip(mcShotHolder);
  96.    removeMovieClip(mcInnerHolder);
  97.    _root.createEmptyMovieClip("mcSummaryHolder",_root.getNextHighestDepth());
  98.    mcSummaryHolder.attachMovie("SummarySymbol","summary",2,{_x:Stage.width / 2,_y:Stage.height / 2 + 70});
  99.    mcSummaryHolder.summary._visible = true;
  100.    mcSummaryHolder.summary.onPress = function()
  101.    {
  102.       _root.intro();
  103.    };
  104.    var _loc2_ = SharedObject.getLocal("topScores");
  105.    if(isNaN(_loc2_.data.normal))
  106.    {
  107.       _loc2_.data.normal = 0;
  108.    }
  109.    if(isNaN(_loc2_.data.difficult))
  110.    {
  111.       _loc2_.data.difficult = 0;
  112.    }
  113.    if(oGunPos.choice == 1)
  114.    {
  115.       _loc2_.data.normal = Math.max(oGunPos.score,_loc2_.data.normal);
  116.    }
  117.    else
  118.    {
  119.       _loc2_.data.difficult = Math.max(oGunPos.score,_loc2_.data.difficult);
  120.    }
  121.    mcSummaryHolder.createTextField("tSummary",mcIntro.getNextHighestDepth(),Stage.width / 2 - 230,Stage.height / 2 - 90,460,180);
  122.    mcSummaryHolder.tSummary.border = false;
  123.    mcSummaryHolder.tSummary.wordWrap = true;
  124.    if(oGunPos.choice == 1)
  125.    {
  126.       mcSummaryHolder.tSummary.text = "Your score was: " + oGunPos.score + "\nHighest NORMAL score on this computer: " + _loc2_.data.normal;
  127.    }
  128.    else
  129.    {
  130.       mcSummaryHolder.tSummary.text = "Your score was: " + oGunPos.score + "\nHighest DIFFICULT score on this computer: " + _loc2_.data.difficult;
  131.    }
  132.    var _loc3_ = new TextFormat();
  133.    _loc3_.align = "center";
  134.    _loc3_.font = "_sans";
  135.    _loc3_.color = 0;
  136.    _loc3_.size = 20;
  137.    mcSummaryHolder.tSummary.setTextFormat(_loc3_);
  138. }
  139. function newLevel()
  140. {
  141.    removeMovieClip(mcIntro);
  142.    clearInterval(nRotInr);
  143.    this.createEmptyMovieClip("mcInnerHolder",this.getNextHighestDepth());
  144.    mcInnerHolder.attachMovie("circle1Symbol","circle1",mcInnerHolder.getNextHighestDepth(),{_x:Stage.width / 2,_y:Stage.height / 2});
  145.    mcInnerHolder.attachMovie("circle2Symbol","circle2",mcInnerHolder.getNextHighestDepth(),{_x:Stage.width / 2,_y:Stage.height / 2});
  146.    mcInnerHolder.attachMovie("SmallCircle1Symbol","smallCircle1",mcInnerHolder.getNextHighestDepth(),{_x:Stage.width / 2,_y:Stage.height / 2});
  147.    mcInnerHolder.attachMovie("SmallCircle2Symbol","smallCircle2",mcInnerHolder.getNextHighestDepth(),{_x:Stage.width / 2,_y:Stage.height / 2});
  148.    mcInnerHolder.attachMovie("gunSymbol","gun",mcInnerHolder.getNextHighestDepth(),{_x:Stage.width / 2,_y:Stage.height / 2});
  149.    this.createEmptyMovieClip("mcShotHolder",this.getNextHighestDepth());
  150.    mcShotHolder.attachMovie("shotSymbol","shot",mcShotHolder.getNextHighestDepth());
  151.    mcShotHolder.shot._visible = false;
  152.    mcInnerHolder.createEmptyMovieClip("mcTimeHolder",mcInnerHolder.getNextHighestDepth());
  153.    mcInnerHolder.mcTimeHolder.createTextField("tTime",mcInnerHolder.mcTimeHolder.getNextHighestDepth(),Stage.width / 2 - 15,Stage.height / 2 - 10,35,30);
  154.    mcInnerHolder.createEmptyMovieClip("mcScoreHolder",mcInnerHolder.getNextHighestDepth());
  155.    mcInnerHolder.mcScoreHolder.createTextField("tScore",mcInnerHolder.mcScoreHolder.getNextHighestDepth(),Stage.width - 170,50,130,30);
  156.    oGunPos.oneShot = true;
  157.    nRotInr = setInterval(rotateInner,10);
  158.    mcInnerHolder.circle2._rotation = Math.random() * 360;
  159.    mcInnerHolder.circle1._rotation = mcInnerHolder.circle2._rotation + Math.random() * (55 - oGunPos.difficultRot1) + (30 - oGunPos.difficultRot1);
  160.    mcInnerHolder.smallCircle2._rotation = Math.random() * 360;
  161.    mcInnerHolder.smallCircle1._rotation = mcInnerHolder.smallCircle2._rotation + Math.random() * (55 - oGunPos.difficultRot2) + (30 - oGunPos.difficultRot2);
  162.    oGunPos.speedInner = Math.random() + 0.8 + oGunPos.difficultSpeed;
  163.    oGunPos.directionInner = Math.random() <= 0.5 ? 1 : -1;
  164.    oGunPos.speedOuter = Math.random() + 1.3 + oGunPos.difficultSpeed;
  165.    oGunPos.directionOuter = oGunPos.directionInner * -1;
  166.    oGunPos.speedShot = 9;
  167. }
  168. function intro()
  169. {
  170.    removeMovieClip(mcSummaryHolder);
  171.    removeMovieClip(mcShotHolder);
  172.    removeMovieClip(mcInnerHolder);
  173.    clearInterval(nRotInr);
  174.    oGunPos.score = 0;
  175.    oGunPos.timer = 100;
  176.    _root.createEmptyMovieClip("mcIntro",_root.getNextHighestDepth());
  177.    mcIntro.createTextField("tIntro",mcIntro.getNextHighestDepth(),Stage.width / 2 - 200,Stage.height / 2 - 120,400,220);
  178.    mcIntro.tIntro.border = false;
  179.    mcIntro.tIntro.wordWrap = true;
  180.    mcIntro.tIntro.text = "You have 100 seconds to get as many shots as you can into the center of the spinning circles. Move the spaceship around with LEFT or RIGHT arrow keys, shoot using the SPACEBAR. Every time you hit the walls you lose 10 seconds.";
  181.    var _loc2_ = new TextFormat();
  182.    _loc2_.align = "center";
  183.    _loc2_.font = "_sans";
  184.    _loc2_.size = 18;
  185.    mcIntro.tIntro.setTextFormat(_loc2_);
  186.    mcIntro.attachMovie("NormalSymbol","mcNormal",mcIntro.getNextHighestDepth(),{_x:Stage.width / 2 - 70,_y:Stage.height / 2 + 40});
  187.    mcIntro.attachMovie("DifficultSymbol","mcDifficult",mcIntro.getNextHighestDepth(),{_x:Stage.width / 2 + 70,_y:Stage.height / 2 + 40});
  188.    mcIntro.mcNormal._xscale = 80;
  189.    mcIntro.mcDifficult._xscale = 80;
  190.    mcIntro.mcNormal._yscale = 80;
  191.    mcIntro.mcDifficult._yscale = 80;
  192.    mcIntro.mcNormal.onPress = function()
  193.    {
  194.       oGunPos.difficultSpeed = 0;
  195.       oGunPos.difficultRot1 = 0;
  196.       oGunPos.difficultRot2 = 0;
  197.       oGunPos.choice = 1;
  198.       _root.newLevel();
  199.    };
  200.    mcIntro.mcDifficult.onPress = function()
  201.    {
  202.       oGunPos.difficultSpeed = 0.3;
  203.       oGunPos.difficultRot1 = 10;
  204.       oGunPos.difficultRot2 = 15;
  205.       oGunPos.choice = 2;
  206.       _root.newLevel();
  207.    };
  208.    oGunPos.score = 0;
  209.    oGunPos.timer = 100;
  210. }
  211. var oKeyListener = new Object();
  212. oKeyListener.onKeyDown = function()
  213. {
  214.    if(nKeyID == null)
  215.    {
  216.       nKeyID = setInterval(moveGun,10);
  217.    }
  218. };
  219. oKeyListener.onKeyUp = function()
  220. {
  221.    if(nKeyID != null)
  222.    {
  223.       clearInterval(nKeyID);
  224.       delete nKeyID;
  225.    }
  226. };
  227. var oGunPos = new Object();
  228. Key.addListener(oKeyListener);
  229. intro();
  230.