home *** CD-ROM | disk | FTP | other *** search
/ One Click 5 / ONCE005.iso / Jogos / 1636.swf / scripts / DefineSprite_78 / frame_1 / DoAction.as
Encoding:
Text File  |  2006-05-02  |  11.0 KB  |  436 lines

  1. function initialization()
  2. {
  3.    if(_global.score == undefined)
  4.    {
  5.       _global.score = 0;
  6.    }
  7.    if(_global.Life == undefined)
  8.    {
  9.       _global.Life = 2;
  10.    }
  11.    backgroundList = new Array();
  12.    characterList0 = new Array();
  13.    characterList1 = new Array();
  14.    bulletList0 = new Array();
  15.    bulletList1 = new Array();
  16.    time = 0;
  17.    gravity = 5;
  18.    stageClear = false;
  19.    gameOver = false;
  20.    backgroundX = 0;
  21.    backgroundVX = 0;
  22.    textFormat = new TextFormat();
  23.    textFormat.font = "Arial";
  24.    hitSound = new Sound();
  25.    hitSound.attachSound("hitSound");
  26.    depthUsed = 0;
  27.    _root.stop();
  28.    drawPanel();
  29.    _visible = false;
  30.    initialized = true;
  31. }
  32. function drawPanel()
  33. {
  34.    _parent.createEmptyMovieClip("hpScorePanel",100000);
  35.    with(_parent.hpScorePanel)
  36.    {
  37.       beginFill(0);
  38.       moveTo(0,0);
  39.       lineTo(700,0);
  40.       lineTo(700,80);
  41.       lineTo(0,80);
  42.       lineTo(0,0);
  43.       endFill();
  44.       textFormat.size = 20;
  45.       textFormat.color = 16777215;
  46.       createTextField("text1",1,70,8,50,40);
  47.       text1.text = "HP:";
  48.       text1.setTextFormat(textFormat);
  49.       createTextField("text3",2,20,40,150,40);
  50.       text3.text = "Distance:";
  51.       text3.setTextFormat(textFormat);
  52.       createTextField("text2",3,470,8,200,40);
  53.       text2.text = "Score:";
  54.       text2.setTextFormat(textFormat);
  55.       createTextField("score",4,550,8,200,40);
  56.       score.text = parseInt(_global.score);
  57.       score.setTextFormat(textFormat);
  58.       createTextField("text4",5,470,40,200,40);
  59.       text4.text = "Life:";
  60.       text4.setTextFormat(textFormat);
  61.       createTextField("life",6,550,40,200,40);
  62.       life.text = parseInt(_global.life);
  63.       life.setTextFormat(textFormat);
  64.       createEmptyMovieClip("hpBarBack",7);
  65.       with(hpBarBack)
  66.       {
  67.          beginFill(5570560);
  68.          moveTo(0,0);
  69.          lineTo(300,0);
  70.          lineTo(300,15);
  71.          lineTo(0,15);
  72.          lineTo(0,0);
  73.          endFill();
  74.          _x = 120;
  75.          _y = 15;
  76.       }
  77.       createEmptyMovieClip("hpBar",8);
  78.       with(hpBar)
  79.       {
  80.          beginFill(16711680);
  81.          moveTo(0,0);
  82.          lineTo(300,0);
  83.          lineTo(300,15);
  84.          lineTo(0,15);
  85.          lineTo(0,0);
  86.          endFill();
  87.          _x = 120;
  88.          _y = 15;
  89.       }
  90.       createEmptyMovieClip("distanceBarBack",9);
  91.       with(distanceBarBack)
  92.       {
  93.          beginFill(13056);
  94.          moveTo(0,0);
  95.          lineTo(300,0);
  96.          lineTo(300,15);
  97.          lineTo(0,15);
  98.          lineTo(0,0);
  99.          endFill();
  100.          _x = 120;
  101.          _y = 47;
  102.       }
  103.       createEmptyMovieClip("distanceBar",10);
  104.       with(distanceBar)
  105.       {
  106.          beginFill(60928);
  107.          moveTo(0,0);
  108.          lineTo(1,0);
  109.          lineTo(1,15);
  110.          lineTo(0,15);
  111.          lineTo(0,0);
  112.          endFill();
  113.          _x = 120;
  114.          _y = 47;
  115.       }
  116.    }
  117.    var Bounds = _parent.hpScorePanel.getBounds(_root);
  118.    _parent.hpScorePanel._x -= Bounds.xMin;
  119.    _parent.hpScorePanel._y -= Bounds.yMin;
  120. }
  121. function gameIsOver()
  122. {
  123.    gameOver = true;
  124.    stageClear = false;
  125.    with(_parent.hpScorePanel)
  126.    {
  127.       createEmptyMovieClip("message",11);
  128.       with(message)
  129.       {
  130.          textFormat.color = 16777215;
  131.          textFormat.size = 50;
  132.          createTextField("t",6,210,200,500,100);
  133.          t.text = "Game Over!";
  134.          t.setTextFormat(textFormat);
  135.          textFormat.size = 25;
  136.          createTextField("clickHere",7,235,260,500,100);
  137.          clickHere.text = "Press \'C\' to continue.";
  138.          clickHere.setTextFormat(textFormat);
  139.          createTextField("quit",8,235,290,500,100);
  140.          quit.text = "Press \'Q\' to quit.";
  141.          quit.setTextFormat(textFormat);
  142.       }
  143.    }
  144. }
  145. function clearThisStage()
  146. {
  147.    stageClear = true;
  148.    gameOver = false;
  149.    with(_parent.hpScorePanel)
  150.    {
  151.       createEmptyMovieClip("message",11);
  152.       with(message)
  153.       {
  154.          textFormat.color = 16777215;
  155.          textFormat.size = 50;
  156.          createTextField("stagecleartext",6,220,200,500,100);
  157.          stagecleartext.text = "Stage Clear!";
  158.          stagecleartext.setTextFormat(textFormat);
  159.          textFormat.size = 25;
  160.          createTextField("clickHere",7,235,270,500,100);
  161.          clickHere.text = "Press \'C\' to continue.";
  162.          clickHere.setTextFormat(textFormat);
  163.       }
  164.    }
  165. }
  166. function addScore(s)
  167. {
  168.    _global.score += s;
  169.    textFormat.size = 20;
  170.    textFormat.color = 16777215;
  171.    _parent.hpScorePanel.score.text = parseInt(_global.score);
  172.    _parent.hpScorePanel.score.setTextFormat(textFormat);
  173. }
  174. function deductScore(s)
  175. {
  176.    _global.score -= s;
  177.    if(_global.score < 0)
  178.    {
  179.       _global.score = 0;
  180.    }
  181.    textFormat.size = 20;
  182.    textFormat.color = 16777215;
  183.    _parent.hpScorePanel.score.text = parseInt(_global.score);
  184.    _parent.hpScorePanel.score.setTextFormat(textFormat);
  185. }
  186. function addLife(s)
  187. {
  188.    _global.life += s;
  189.    textFormat.size = 20;
  190.    textFormat.color = 16777215;
  191.    _parent.hpScorePanel.life.text = parseInt(_global.life);
  192.    _parent.hpScorePanel.life.setTextFormat(textFormat);
  193. }
  194. function deductLife(s)
  195. {
  196.    _global.life -= s;
  197.    if(_global.life < 0)
  198.    {
  199.       _global.life = 0;
  200.    }
  201.    textFormat.size = 20;
  202.    textFormat.color = 16777215;
  203.    _parent.hpScorePanel.life.text = parseInt(_global.life);
  204.    _parent.hpScorePanel.life.setTextFormat(textFormat);
  205. }
  206. function mainCharHp(hp, fullHp)
  207. {
  208.    _parent.hpScorePanel.hpBar._width = 300 * hp / fullHp;
  209. }
  210. function distanceBar(a, b)
  211. {
  212.    var c = 300 * a / b;
  213.    if(c < 1)
  214.    {
  215.       c = 1;
  216.    }
  217.    _parent.hpScorePanel.distanceBar._width = c;
  218. }
  219. function addToList(listName, item)
  220. {
  221.    var list = eval(listName);
  222.    list.push(item);
  223. }
  224. function deleteFromList(listName, item)
  225. {
  226.    var list = eval(listName);
  227.    var i;
  228.    var deleted = false;
  229.    i = 0;
  230.    while(i < list.length)
  231.    {
  232.       if(list[i].id == item.id && list[i].parent == item.parent)
  233.       {
  234.          list.splice(i,1);
  235.          deleted = true;
  236.          break;
  237.       }
  238.       i++;
  239.    }
  240.    if(deleted == false)
  241.    {
  242.       trace("WARNING! gameEngine:[" + _target + "] --- delete item:[" + item.id + "] from list:[" + listName + "] failed!");
  243.    }
  244. }
  245. function moveBackgroundRequest(vx)
  246. {
  247.    backgroundVX += vx;
  248. }
  249. function moveBackground()
  250. {
  251.    if(backgroundX - backgroundVX < 0)
  252.    {
  253.       backgroundVX = backgroundX;
  254.    }
  255.    if(backgroundX - backgroundVX > distance)
  256.    {
  257.       backgroundVX = backgroundX - distance;
  258.    }
  259.    var i;
  260.    var j;
  261.    i = 0;
  262.    while(i < backgroundList.length)
  263.    {
  264.       backgroundList[i].id.move(backgroundVX);
  265.       i++;
  266.    }
  267.    j = 0;
  268.    while(j < 2)
  269.    {
  270.       var tempList = eval("characterList" + j);
  271.       i = 0;
  272.       while(i < tempList.length)
  273.       {
  274.          tempList[i].id.move(backgroundVX);
  275.          i++;
  276.       }
  277.       var tempList = eval("bulletList" + j);
  278.       i = 0;
  279.       while(i < tempList.length)
  280.       {
  281.          tempList[i].id.move(backgroundVX);
  282.          i++;
  283.       }
  284.       j++;
  285.    }
  286.    backgroundX -= backgroundVX;
  287.    backgroundVX = 0;
  288.    distanceBar(backgroundX,distance);
  289. }
  290. function createBullet(bulletName, position, team, xscale)
  291. {
  292.    _root.attachMovie(bulletName,"bullet" + depthUsed,depthUsed);
  293.    var temp = eval("_root.bullet" + depthUsed);
  294.    temp._x = position.x;
  295.    temp._y = position.y;
  296.    temp.team = team;
  297.    temp._xscale = xscale;
  298.    depthUsed++;
  299. }
  300. function createHiting(attack, body)
  301. {
  302.    var Position1 = {x:attack._x,y:attack._y};
  303.    attack._parent.localToGlobal(Position1);
  304.    var Position2 = {x:body._x,y:body._y};
  305.    body._parent.localToGlobal(Position2);
  306.    _root.attachMovie("hiting","hit" + depthUsed,depthUsed);
  307.    var temp = eval("_root.hit" + depthUsed);
  308.    temp._x = (Position1.x + Position2.x) / 2;
  309.    temp._y = (Position1.y + Position2.y) / 2;
  310.    depthUsed++;
  311. }
  312. function detectBodyAttackCollision(List1, List2)
  313. {
  314.    var i;
  315.    var j;
  316.    var k;
  317.    PlayHitSound = false;
  318.    k = 0;
  319.    while(k < 2)
  320.    {
  321.       var tempList1 = eval(List1 + "List" + k);
  322.       var tempList2 = eval(List2 + "List" + (1 - k));
  323.       j = 0;
  324.       while(j < tempList1.length)
  325.       {
  326.          i = 0;
  327.          while(i < tempList2.length)
  328.          {
  329.             if(tempList1[j].parent.movie.attack != undefined && tempList2[i].parent.movie.body != undefined)
  330.             {
  331.                if(tempList1[j].parent.movie.attack.hitTest(tempList2[i].parent.movie.body))
  332.                {
  333.                   if(!(tempList2[i].id.frozenCounter < 0 || tempList2[i].id.frozenCounter > 0 || tempList2[i].id.invincibleCounter > 0))
  334.                   {
  335.                      playHitSound = true;
  336.                      createHiting(tempList1[j].parent.movie.attack,tempList2[i].parent.movie.body);
  337.                      tempList2[i].id.attackBy(tempList1[j].id,tempList1[j].parent.movie.attack.hp);
  338.                   }
  339.                }
  340.             }
  341.             i++;
  342.          }
  343.          j++;
  344.       }
  345.       k++;
  346.    }
  347.    if(playHitSound)
  348.    {
  349.       hitSound.start();
  350.    }
  351. }
  352. function destroyAllObject()
  353. {
  354.    i = 0;
  355.    while(i < bulletList0.length)
  356.    {
  357.       bulletList1[i].parent.removeMovieClip();
  358.       i++;
  359.    }
  360.    i = 0;
  361.    while(i < bulletList1.length)
  362.    {
  363.       bulletList1[i].parent.removeMovieClip();
  364.       i++;
  365.    }
  366.    _parent.hpScorePanel.removeMovieClip();
  367. }
  368. onEnterFrame = function()
  369. {
  370.    if(initialized == undefined)
  371.    {
  372.       initialization();
  373.    }
  374.    if(stageClear == false && gameOver == false)
  375.    {
  376.       moveBackground();
  377.       detectBodyAttackCollision("character","character");
  378.       detectBodyAttackCollision("character","bullet");
  379.       detectBodyAttackCollision("bullet","character");
  380.       if(backgroundX == distance && characterList0[0].parent._x == width)
  381.       {
  382.          var i;
  383.          i = 0;
  384.          while(i < characterList1.length)
  385.          {
  386.             characterList1[i].id.attackBy(characterList0[0].id,-1000);
  387.             i++;
  388.          }
  389.          i = 0;
  390.          while(i < bulletList1.length)
  391.          {
  392.             bulletList1[i].id.attackBy(characterList0[0].id,-1000);
  393.             i++;
  394.          }
  395.          clearThisStage();
  396.       }
  397.    }
  398.    else if(stageClear == true)
  399.    {
  400.       if(Key.isDown(67))
  401.       {
  402.          stageClear = false;
  403.          destroyAllObject();
  404.          _global.nextStageLabel = String(nextStageLabel);
  405.          tellTarget("_root")
  406.          {
  407.             gotoAndPlay(_global.nextStageLabel);
  408.          }
  409.       }
  410.    }
  411.    else if(gameOver == true)
  412.    {
  413.       if(Key.isDown(81))
  414.       {
  415.          gameOver = false;
  416.          destroyAllObject();
  417.          _global.gameOverLabel = String(gameOverLabel);
  418.          tellTarget("_root")
  419.          {
  420.             gotoAndPlay(_global.gameOverLabel);
  421.          }
  422.       }
  423.       if(Key.isDown(67))
  424.       {
  425.          _parent.hpScorePanel.message.removeMovieClip();
  426.          gameOver = false;
  427.          deductScore(500);
  428.          _global.life = 3;
  429.       }
  430.    }
  431.    if(characterList0[0].id != undefined)
  432.    {
  433.       mainCharHp(characterList0[0].id.hp,characterList0[0].id.fullHp);
  434.    }
  435. };
  436.