home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / Antitude-Pong.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2005-09-27  |  4.3 KB  |  183 lines

  1. function createArea()
  2. {
  3.    _root.createEmptyMovieClip("area",0);
  4.    with(_root.area)
  5.    {
  6.    }
  7. }
  8. function textBoxes(new_score_p, new_score_e)
  9. {
  10.    _root.createTextField("player_score",1,20,10,20,40);
  11.    _root.createTextField("enemy_score",2,w - 40,10,20,40);
  12.    score_style = new TextFormat();
  13.    score_style.font = "Verdana";
  14.    score_style.size = 20;
  15.    score_style.bold = true;
  16.    score_style.color = 16777215;
  17.    score_style.align = "center";
  18.    player_score.selectable = false;
  19.    player_score.text = new_score_p;
  20.    player_score.setTextFormat(score_style);
  21.    enemy_score.text = new_score_e;
  22.    enemy_score.selectable = false;
  23.    enemy_score.setTextFormat(score_style);
  24. }
  25. function createPlayer(instancename, depth)
  26. {
  27.    _root.createEmptyMovieClip(instancename,depth);
  28.    with(_root[instancename])
  29.    {
  30.       moveTo(0,0);
  31.       beginFill(16777215,100);
  32.       lineStyle(0,16777215,0);
  33.       lineTo(10,0);
  34.       lineTo(10,50);
  35.       lineTo(0,50);
  36.       lineTo(0,0);
  37.    }
  38. }
  39. function createBall()
  40. {
  41.    _root.createEmptyMovieClip("ball",5);
  42.    with(_root.ball)
  43.    {
  44.       moveTo(0,0);
  45.       lineStyle(0,16777215,0);
  46.       beginFill(16777215,100);
  47.       curveTo(0,-5,5,-5);
  48.       curveTo(10,-5,10,0);
  49.       curveTo(10,5,5,5);
  50.       curveTo(0,5,0,0);
  51.    }
  52. }
  53. function int_stuff()
  54. {
  55.    _root.ball._x = w / 2 - 5;
  56.    _root.ball._y = h / 2 - 5;
  57.    _root.enemy._x = w - 20;
  58.    _root.enemy._y = h / 2 - 30;
  59. }
  60. function click_2_play(message)
  61. {
  62.    _root.createTextField("click2play",10,0,20,w,200);
  63.    with(_root.click2play)
  64.    {
  65.       text = message;
  66.       selectable = false;
  67.       setTextFormat(score_style);
  68.    }
  69. }
  70. function createBigButton()
  71. {
  72.    _root.createEmptyMovieClip("big_button",20);
  73.    with(_root.big_button)
  74.    {
  75.       beginFill(0,0);
  76.       moveTo(0,0);
  77.       lineTo(w,0);
  78.       lineTo(w,h);
  79.       lineTo(0,h);
  80.       lineTo(0,0);
  81.    }
  82. }
  83. function controlPlayer()
  84. {
  85.    if(playing)
  86.    {
  87.       _root.player._x = 20;
  88.       _root.player._y = _root._ymouse - 25;
  89.    }
  90. }
  91. function moveBall()
  92. {
  93.    if(playing)
  94.    {
  95.       _root.ball._y += ball_y;
  96.       if(_root.ball._y <= 0 || _root.ball._y + 10 >= h)
  97.       {
  98.          ball_y *= -1;
  99.       }
  100.       _root.ball._x += ball_speed;
  101.       if(_root.ball.hitTest(_root.enemy) || _root.ball.hitTest(_root.player))
  102.       {
  103.          if(ball_speed < max_speed && ball_speed > - max_speed)
  104.          {
  105.             ball_speed *= -1.5;
  106.          }
  107.          else
  108.          {
  109.             ball_speed *= -1;
  110.          }
  111.       }
  112.       if(_root.ball.hitTest(_root.enemy))
  113.       {
  114.          ball_y = (_root.ball._y - (_root.enemy._y + 25)) * 0.2;
  115.       }
  116.       if(_root.ball.hitTest(_root.player))
  117.       {
  118.          ball_y = (_root.ball._y - (_root.player._y + 25)) * 0.2;
  119.       }
  120.       if(_root.ball._x + 10 <= 0)
  121.       {
  122.          enemy_score_one += 1;
  123.          click_2_play("Enemy scored! Click to continue.");
  124.          textBoxes(player_score_one,enemy_score_one);
  125.          playing = false;
  126.          _root.ball._x = w / 2 - 5;
  127.          _root.ball._y = h / 2 - 5;
  128.          ball_y = 0;
  129.          ball_speed = 1.2;
  130.       }
  131.       if(_root.ball._x > w)
  132.       {
  133.          player_score_one += 1;
  134.          click_2_play("You scored! Click to continue.");
  135.          textBoxes(player_score_one,enemy_score_one);
  136.          playing = false;
  137.          _root.ball._x = w / 2 - 5;
  138.          _root.ball._y = h / 2 - 5;
  139.          _root.ball_speed = -1.2;
  140.          ball_y = 0;
  141.       }
  142.    }
  143. }
  144. function enemyMove()
  145. {
  146.    if(playing)
  147.    {
  148.       stupidity = 7;
  149.       if(_root.ball._x + 10 >= w / 2)
  150.       {
  151.          _root.enemy._y += (_root.ball._y - (_root.enemy._y + 25)) / stupidity;
  152.       }
  153.    }
  154. }
  155. Mouse.hide();
  156. w = Stage.width;
  157. h = Stage.height;
  158. ball_speed = -1.2;
  159. ball_y = 0;
  160. fps = 120;
  161. interval = Math.round(1000 / fps);
  162. max_speed = 4;
  163. enemy_score_one = 0;
  164. player_score_one = 0;
  165. new_score_p = 0;
  166. new_score_e = 0;
  167. _root.onLoad = createArea();
  168. createBall();
  169. textBoxes(player_score_one,enemy_score_one);
  170. createPlayer("player",3);
  171. createPlayer("enemy",4);
  172. int_stuff();
  173. click_2_play("Click Anywhere To Play");
  174. createBigButton();
  175. _root.big_button.onPress = function()
  176. {
  177.    playing = true;
  178.    click_2_play("");
  179. };
  180. setInterval(moveBall,interval);
  181. setInterval(controlPlayer,interval);
  182. setInterval(enemyMove,interval);
  183.