Advertisement
terorama

lesson7 AS2

Aug 28th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //--------------------------------------------------------------------
  2. //                            Frame 1
  3. //--------------------------------------------------------------------
  4.  stop();  
  5.  Mouse.hide();
  6.  glo_color=0xff0000;
  7.  _root.createEmptyMovieClip("drawfld",1);
  8.  drawfld._x=20;
  9.  drawfld._y=20;
  10.  
  11.  
  12. //---------------------  
  13.    mango.x_speed=3;
  14.    mango._xscale*=-1;
  15.    mango.y_speed=3;
  16.    
  17.    n_mangos=0;
  18.  
  19. //mango.onLoad=mangoload;
  20. mango.onEnterFrame=mangoEntFrame;
  21. //---------------------
  22.  
  23. ball_a.psy=0;
  24. ball_a.rad=70;
  25. ball_a.get_x= function () {
  26.    
  27.     return 200+this.rad*Math.cos(this.psy);
  28. }
  29.  
  30. ball_a.get_y= function () {
  31.     return 200+this.rad*Math.sin(this.psy);
  32. }
  33.  
  34. ball_a.onEnterFrame=ballEntFrame;
  35.  
  36. //---------------------
  37. /*var ball_arr:Array =[];
  38.  
  39. for (var i=0; i<5; i++) {
  40.     ball_arr[i]=attachMovie("ball"+i,"ball"+i,i);
  41.     ball_arr[i]._x=10;
  42.     ball_arr[i]._y=10;
  43.     ball_arr[i].psy=random(5);
  44.     ball_arr[i].rad=random(100);
  45.    
  46.     ball_arr[i].onEnterFrame=ballEntFrame;
  47. }*/
  48.  
  49. //-----------------------------------
  50. r_mcc.onRelease = function() {glo_color=0xff0000};
  51. g_mcc.onRelease =function() {glo_color=0x00ff00};
  52.  
  53. z_box.onEnterFrame = z_box_test;
  54.  
  55. function  z_box_test() {
  56.    
  57.     if (this.hitTest(human3)) {
  58.        
  59.        this.onEnterFrame=null;
  60.        //stopDrag();   
  61.        this.gotoAndPlay(2);
  62.        
  63.     }
  64. }
  65. //-----------------------------------
  66. for (i=0; i<5; i++) {
  67.     duplicateMovieClip(z_box,"z_box"+i,i);
  68.     f=eval("z_box"+i)
  69.     f._x=random(Stage.width);
  70.     f._y=random(Stage.height);
  71.     f.onEnterFrame=z_box.onEnterFrame;
  72. }
  73. //-----------------------------------
  74.  
  75. ris = function() {
  76.     lineTo(z_poin3._x,z_poin3._y);
  77. }
  78.  
  79. z_poin3.onEnterFrame = function () {
  80.     this._x=_root._xmouse;
  81.     this._y=_root._ymouse;
  82. }
  83.  
  84.  
  85. z_poin3.onMouseDown = function () {
  86.     lineStyle(1, glo_color, 60);
  87.     moveTo(this._x, this._y);
  88.     uu=setInterval(ris,10);
  89. }
  90.  
  91. z_poin3.onMouseUp = function() {
  92.     clearInterval(uu);
  93. }
  94.  
  95. //-----------------------------------
  96. human3.onPress = function() {
  97.     startDrag(this);
  98. }
  99. human3.onRelease = function() {
  100.     stopDrag();
  101. }
  102. human3.onReleaseOutside = function () {
  103.     stopDrag();
  104. }
  105.  
  106. //-----------------------------------
  107. mango.onRollOver= function () {
  108.    
  109.    this.s0=200;
  110.  
  111. }
  112. //-----------------------------------
  113. mango.onRollOut = function () {
  114.  
  115.     this.s0=100;
  116. }
  117. //-----------------------------------
  118. function mangoload() {
  119.    this.x_speed=3;
  120.    this.y_speed=3;
  121. }
  122. //-----------------------------------
  123.  
  124.  
  125. function ballEntFrame() {
  126.     this.psy+=.1;
  127.     this.rad+=-1+random(3);
  128.     this._x=this.get_x();
  129.     this._y=this.get_y();
  130.    
  131.     //_root.lineStyle(random(5),0x880000);
  132.    
  133.    
  134.     drawfld.lineStyle(random(8),random(256)*256*256);
  135.    
  136.     drawfld.beginFill(0x7878ff);
  137.     drawfld.moveTo(
  138.                     this._x-1-drawfld._x,this._y-1-drawfld._y);
  139.     drawfld.lineTo(
  140.                 this._x-drawfld._x,this._y-drawfld._y);
  141.     drawfld.endFill();
  142.  
  143. }
  144. //-----------------------------------
  145. function mangoEntFrame() {
  146.    
  147.     //-------------------------
  148.     if (Key.isDown(Key.LEFT)) {
  149.         this.x_speed--;
  150.     }
  151.     if (Key.isDown(Key.RIGHT)) {
  152.         this.x_speed++;
  153.     }
  154.     if (Key.isDown(Key.UP)) {
  155.         this.y_speed--;
  156.     }
  157.     if (Key.isDown(Key.DOWN)) {
  158.         this.y_speed++;
  159.     }
  160.     code=Key.getAscii();
  161.     code3=Key.getCode();
  162.     code4=chr(code);
  163.    
  164.     if (code4=='q') {
  165.         this.x_speed/=1.1;
  166.         this.y_speed/=1.1;
  167.     }
  168.        
  169.     //-------------------------
  170.     this._x+=this.x_speed;
  171.     this._y+=this.y_speed;
  172.     //-------------------------
  173.    
  174.     sclx=this._width/2*
  175.           Math.abs(this._xscale/100);
  176.          
  177.     scly=this._height/2*
  178.           Math.abs(this._yscale/100);  
  179.          
  180.     if ((this._x>(Stage.width-sclx)) || (this._x<sclx)){
  181.        
  182.        this.x_speed*=-1;       
  183.        this._xscale*=-1;
  184.        
  185.        this._x+=this.x_speed;
  186.     }
  187.     //-------------------------
  188.     if ((this._y>(Stage.height-scly)) || (this._y<scly)) {
  189.         this.y_speed*=-1;
  190.         this._y+=this.y_speed;
  191.     }
  192.    
  193.     vx=this.s0-this._yscale;
  194.     this._yscale+=vx/20;
  195.     this._xscale+= this._xscale<0 ? -vx/20 : vx/20;
  196.    
  197.     //this._rotation=
  198.     //   Math.atan2(this.y_speed,this.x_speed)*180/3.14;
  199.    
  200. }
  201.  
  202.  
  203. //--------------------------------------------------------------------
  204. //                       human symbol
  205. //--------------------------------------------------------------------
  206. //----------------------------------------
  207. onClipEvent(load) {
  208.     this.angl=0;
  209.     this.sp=0;
  210. }
  211.  
  212. //----------------------------------------
  213. onClipEvent(enterFrame) {
  214.    
  215.    
  216.    
  217.     this._x+=this.sp*Math.cos(this.angl);
  218.     this._y+=this.sp*Math.sin(this.angl);
  219.    
  220.     this._rotation=this.angl/3.14*180;
  221.    
  222.     if (this._x<0) this._x=Stage.width;
  223.     if (this._x>Stage.width) this._x=0;
  224.     if (this._y<0) this._y=Stage.height;
  225.     if (this._y>Stage.height) this._y=0;
  226.          
  227.        
  228.    
  229.    
  230.     //_root.inf_t.text=this.sp;
  231.     //_root.z_tt=this.sp;
  232.    
  233. }
  234.  
  235. //----------------------------------------
  236. on (keyPress "<Right>") {
  237.     this.angl+=.05;
  238. }
  239. //----------------------------------------
  240. on (keyPress "<Left>") {
  241.     this.angl-=.05;
  242. }
  243. //----------------------------------------
  244. on (keyPress "<Up>") {
  245.     this.sp+=1;
  246. }
  247. //----------------------------------------
  248. on (keyPress "<Down>") {
  249.     this.sp-=1;
  250.     if (this.sp<0)  this.sp=0;
  251. }
  252. //----------------------------------------
  253.  
  254. //--------------------------------------------------------------------
  255. //                       button stop
  256. //--------------------------------------------------------------------
  257. on (release) {
  258.     if (n_mangos>0) {
  259.         removeMovieClip("mango"+n_mangos);
  260.         n_mangos--;
  261.     } else {
  262.         gotoAndStop(2);
  263.         Mouse.show();
  264.        
  265.     }
  266.    
  267. }
  268.  
  269. //--------------------------------------------------------------------
  270. //                       button go
  271. //--------------------------------------------------------------------
  272. on (release) {
  273.    
  274.     n_mangos++;
  275.     duplicateMovieClip(_root.mango,
  276.             "mango"+n_mangos,n_mangos);
  277.    
  278.     z_mag=eval("mango"+n_mangos);
  279.    
  280.     z_mag.x_speed=4;
  281.     z_mag.y_speed=4;
  282.     z_mag.onEnterFrame=mangoEntFrame;
  283.     z_mag.onRollOver=mango.onRollOver;
  284.     z_mag.onRollOut=mango.onRollOut;
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement