Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.  
  3.     // IMPORTATIONS =======================================================
  4.     import flash.display.MovieClip;
  5.     import flash.events.*;
  6.    
  7.     public class Obstacle extends MovieClip {
  8.  
  9.         // PROPRIÉTÉS ======================================================
  10.         private var _vitesse: Number; // vitesse de chute (pxl/frame)
  11.         private var _vitesseR: Number; // vitesse de rotation (degrés/frame)
  12.  
  13.         // CONSTRUCTEUR ====================================================
  14.         public function Obstacle() {
  15.             addEventListener(Event.ADDED_TO_STAGE, init);
  16.         }
  17.  
  18.         // MÉTHODES PRIVÉES ================================================
  19.  
  20.         private function init(e: Event): void {
  21.             removeEventListener(Event.ADDED_TO_STAGE, init);
  22.             addEventListener(Event.ENTER_FRAME, loop);
  23.             respawn();
  24.             x = rand(-width, stage.stageHeight - 1);
  25.         }
  26.        
  27.         private function loop(e: Event): void {
  28.             x += _vitesse;
  29.             rotation += _vitesseR;
  30.  
  31.             if (x > stage.stageWidth + width) {
  32.                 respawn();
  33.             }
  34.         }
  35.  
  36.         private function respawn(): void {
  37.             _vitesse = rand(3, 10);
  38.             _vitesseR = rand(-10, 10);
  39.            
  40.             scaleX = scaleY = _vitesse / 20;
  41.             x = -width;
  42.             y = rand(-height, stage.stageHeight);
  43.         }
  44.  
  45.         private function rand(min: int, max: int): int {
  46.             return Math.floor(Math.random() * (max - min + 1)) + min;
  47.         }
  48.  
  49.     } // classe  
  50. } // package
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement