Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- // IMPORTATIONS =======================================================
- import flash.display.MovieClip;
- import flash.events.*;
- public class Obstacle extends MovieClip {
- // PROPRIÉTÉS ======================================================
- private var _vitesse: Number; // vitesse de chute (pxl/frame)
- private var _vitesseR: Number; // vitesse de rotation (degrés/frame)
- // CONSTRUCTEUR ====================================================
- public function Obstacle() {
- addEventListener(Event.ADDED_TO_STAGE, init);
- }
- // MÉTHODES PRIVÉES ================================================
- private function init(e: Event): void {
- removeEventListener(Event.ADDED_TO_STAGE, init);
- addEventListener(Event.ENTER_FRAME, loop);
- respawn();
- x = rand(-width, stage.stageHeight - 1);
- }
- private function loop(e: Event): void {
- x += _vitesse;
- rotation += _vitesseR;
- if (x > stage.stageWidth + width) {
- respawn();
- }
- }
- private function respawn(): void {
- _vitesse = rand(3, 10);
- _vitesseR = rand(-10, 10);
- scaleX = scaleY = _vitesse / 20;
- x = -width;
- y = rand(-height, stage.stageHeight);
- }
- private function rand(min: int, max: int): int {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- } // classe
- } // package
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement