Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import flash.display.MovieClip;
  2. import flash.events.MouseEvent;
  3.  
  4. //COMMENTS ARE IN DOUBLE SLASH, PLEASE READ THEM VERY CAREFULLY, dont understand anything,
  5. //js call me ok
  6.  
  7. //Creating null variables before initialization to store stage objects
  8. var stain:StainBlack;
  9. var cuiBrush:BrushCui;
  10. var upzBrush:BrushCui;
  11. var empty:Empty;
  12. var empty1:Empty;
  13. var selected:int = 0; // 0= nth, 1=cui,2=good
  14.  
  15. //Holding values
  16. var cleaning:Boolean = false;
  17. var opacity:Number = 0;
  18.  
  19. //Called on initialization of object
  20. function init():void{
  21.    
  22.     //Constructor - This is defined by right click library > Advance > ActionScript
  23.     //Linkage > Class > (the class name +() will be the constructor of the object type)
  24.     stain = new StainBlack();
  25.     cuiBrush = new BrushCui();
  26.     upzBrush = new BrushCui();
  27.     empty = new Empty();
  28.     empty1 = new Empty();
  29.     //Global event handlers, passing delegates to child objects
  30.     stage.addEventListener(MouseEvent.MOUSE_DOWN, startCleaning);
  31.     stage.addEventListener(MouseEvent.MOUSE_MOVE, inCleaning);
  32.     stage.addEventListener(MouseEvent.MOUSE_UP, endCleaning);
  33.    
  34.  
  35.     //Selecting the brush
  36.     cuiBrush.addEventListener(MouseEvent.CLICK,
  37.         function():void{
  38.             selected = 1;
  39.         }
  40.     );
  41.     upzBrush.addEventListener(MouseEvent.CLICK,
  42.         function():void{
  43.             selected = 2;
  44.         }
  45.     );
  46.    
  47.    
  48.     //Adding the newly created objects (at line 20 and 21) to the stage
  49.     addChild(stain);
  50.     addChild(empty);
  51.     addChild(empty1);
  52.     addChild(cuiBrush);
  53.     addChild(upzBrush);
  54.  
  55.     //Sets the coordinates of stain n cuibrush on stage
  56.     stain.x = 500;
  57.     stain.y = 500;
  58.     cuiBrush.x = 200;
  59.     cuiBrush.y =50;
  60.     upzBrush.x =100;
  61.     upzBrush.y =50;
  62.    
  63.     //Resize the stain to be smaller
  64.     stain.width = 300;
  65.     stain.height= 300;
  66.    
  67.     //NOT SURE WHAT THESE IS SUPPOSE TO DO??
  68.     /*
  69.     wallBracket_mc.cuiBrush_mc.addEventListener(MouseEvent.CLICK, function():void{
  70.             opacity = 0.3
  71.             cuiBrush_mc.startDrag("true");
  72.             Mouse.hide();
  73.             cui = true;
  74.     });
  75.    
  76.     wallBracket_mc.upzBrush_mc.addEventListener(MouseEvent.CLICK, function():void{
  77.             opacity = 1.0
  78.             upzBrush_mc.startDrag("true");
  79.             Mouse.hide();
  80.     });
  81.     */
  82.    
  83.     //this is when click on wall bracket swap, but i will remove it for now
  84.     //swapChildren(clean_mc, wallBracket_mc);
  85.    
  86. }
  87.  
  88. //Calling initialization
  89. init();
  90.  
  91. //The cleanning called to start cleaning (called when the mouse is down ANYWHR on the screen)
  92. function startCleaning(e:MouseEvent):void{
  93.    
  94.     //Sys out for debugging
  95.     trace("You have begun cleaning");
  96.    
  97.     //Raises the cleaning flag
  98.     cleaning = true;
  99.    
  100.     empty.graphics.lineStyle(100,0xffffff,0.5);
  101.     empty1.graphics.lineStyle(100,0xffffff,1.0);
  102.    
  103.     if(selected==1){
  104.         //The bursh to mouse position
  105.         cuiBrush.x = mouseX;
  106.         cuiBrush.y = mouseY-cuiBrush.height+5;
  107.     }else if(selected == 2){
  108.         upzBrush.x = mouseX;
  109.         upzBrush.y = mouseY-upzBrush.height+5;
  110.     }
  111.        
  112. }
  113.  
  114. //Check whether the first 2 poarameters are within the 3-6th parameters (in whether the mouse is
  115. //over the box
  116. function withinBB(mx:Number, my:Number, xi:Number, yi:Number, xsize:Number,ysize:Number):Boolean{
  117.     if(mx > xi && mx < xi+xsize){
  118.         if(my>yi && my<yi+ysize){
  119.             return true;
  120.         }
  121.     }
  122.     return false;
  123. }
  124.  
  125. //Called when the mouse move ANYWHR on the screen
  126. function inCleaning(e:MouseEvent):void{
  127.    
  128.     /*Check if the cleaning flag is raised
  129.     if(cleaning && withinBB(mouseX,mouseY,stain.x,stain.y,stain.width,stain.height)){
  130.         //Added a listener to the stain, to change its own transparency to half if,
  131.         //if the bursh is moving
  132.         stain.addEventListener(MouseEvent.MOUSE_MOVE, function():void{
  133.             stain.graphics.lineTo
  134.         });
  135.     }*/
  136.     //While mouse is moving, move the bursh to the mouse
  137.     if(cleaning && selected == 1){
  138.         cuiBrush.x = mouseX;
  139.         cuiBrush.y=mouseY-cuiBrush.height+5;
  140.         empty.graphics.lineTo(mouseX,mouseY);
  141.         if(withinBB(mouseX,mouseY,stain.x,stain.y,stain.width,stain.height)){
  142.             if(Math.random()>0.01){
  143.                 littering(Math.round(Math.random()*2),mouseX, mouseY+5);
  144.             }
  145.         }
  146.     }
  147.    
  148.     if(cleaning && selected == 2){
  149.         upzBrush.x = mouseX;
  150.         upzBrush.y = mouseY-upzBrush.height+5;
  151.         empty1.graphics.lineTo(mouseX,mouseY);
  152.     }
  153.  
  154. }
  155.  
  156.  
  157. function littering(num:int, cx:Number, cy:Number):void{
  158.     for(var i:int = 0; i<num; i++){
  159.         var litter:MovieClip;
  160.         var yyy:int = Math.round(Math.random()*3);
  161.         trace("Random Value: "+yyy);
  162.         switch(yyy){
  163.             case 0:
  164.                 litter = new RedBig();
  165.                 break;
  166.             case 1:
  167.                 litter = new RedSmall();
  168.                 break;
  169.             case 2:
  170.                 litter = new GreenBig();
  171.                 break;
  172.             case 3:
  173.                 litter = new GreenSmall();
  174.                 break;
  175.             default: break;
  176.         }
  177.         litter.rotation = Math.random()*360;
  178.         litter.width = (Math.random()*0.4+0.8)*litter.width;
  179.         litter.height = (Math.random()*0.4+0.8)*litter.height;
  180.         litter.x = Math.random() > 0.5 ? -Math.random()*8 + cx : Math.random()*8 + cx;
  181.         litter.y = Math.random() > 0.5 ? -Math.random()*8 + cy : Math.random()*8 + cy;
  182.         addChild(litter);
  183.     }
  184. }
  185.  
  186. //Lower the cleaning flag
  187. function endCleaning(e:MouseEvent):void{
  188.     trace("You have stopped cleaning");
  189.     cleaning = false;
  190.     selected =0;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement