Вы находитесь на странице: 1из 6

//

// Flock
//
// Created by Duran Rose on 2010-08-06.
// Copyright (c) 2010 Duran Rose. All rights reserved.
//
package effects
{
! import flash.display.Sprite;
! import flash.display.MovieClip;
! import flash.events.Event;
! import flash.events.MouseEvent;
!
! import effects.effectsHelper.SteeredVehicle;
! import effects.effectsHelper.Vector2D;
! import effects.effectsHelper.Vehicle;
! import setup.StageSetup;
! import effects.effectsHelper.BenjiMotionTracker;
! import shapes.Square;
! import math.VerMath;
! import time.Delay;
!
!
! public class Flock extends MovieClip
! {

! ! //--------------------------------------
! ! // PRIVATE VARIABLES
! ! //--------------------------------------
! !
! ! private var _vehicles:Vector.<SteeredVehicle>;
! ! private var _maxBirds:uint = 50;
! ! private var _numVehicles:int = 25;
! ! private var _motionTracker:BenjiMotionTracker;
! ! private var _bg:FlockBg = new FlockBg();
! !
! ! private var _stage:StageSetup;
! ! private var _tempObj:Object;
! !
! ! private var _invisVehicle:SteeredVehicle;
! ! private var _roomColors:Array = new Array();
! !
! ! private var _getMicLevel:Function
! !
! ! private var _springNum:Number = 0.3;
! ! private var _easeNum:Number = 0.0;
! ! //--------------------------------------
! ! // PUBLIC VARIABLES
! ! //--------------------------------------

! ! public function Flock($stage:StageSetup,


$motionTracker:BenjiMotionTracker, $roomColors:Array, $micLevel:Function)
! ! {
! ! ! _stage = $stage;
! ! ! _stage.addEventListener(StageSetup.STAGE_SIZE,
resizeHandler);
! ! !
! ! ! _motionTracker = $motionTracker;
! ! ! _roomColors = $roomColors;
! ! !
! ! ! _getMicLevel = $micLevel;
! ! !
! ! ! Delay.create(init, 2);
! ! }//end constructor

! ! //--------------------------------------
! ! // PRIVATE & PROTECTED INSTANCE METHODS
! ! //--------------------------------------
! ! private function init():void
! ! {
! ! ! _roomColors.splice(0);
! ! ! _roomColors = _motionTracker.roomColors;
! ! !
! ! ! addChild(_bg);
! ! !
! ! ! _invisVehicle = new SteeredVehicle(0x000000)
! ! ! _invisVehicle.position = new Vector2D(_stage.sW * 0.5, _stage.sH *
0.5 );
! ! ! _invisVehicle.velocity = new Vector2D(Math.random() * 20 - 10,
Math.random() * 20 - 10);
! ! ! _invisVehicle.edgeBehavior = Vehicle.BOUNCE;
! ! ! //addChild(_invisVehicle);
! ! !
! ! ! _vehicles = new Vector.<SteeredVehicle>();//<SteeredVehicle>();
! ! !
! ! ! for(var i:int = 0; i < _numVehicles; i++)
! ! ! {
! ! ! ! var vehicle:SteeredVehicle = new SteeredVehicle
(_roomColors[VerMath.randRange(1, (_roomColors.length - 1) )]);
! ! ! ! vehicle.scaleX = vehicle.scaleY = VerMath.randRange(0.8,
1.1, false)
! ! ! ! vehicle.position = new Vector2D(Math.random() * _stage.sW,
Math.random() * _stage.sH );
! ! ! ! vehicle.velocity = new Vector2D(Math.random() * 20 - 10,
Math.random() * 20 - 10);
! ! ! ! vehicle.edgeBehavior = Vehicle.BOUNCE;
! ! ! ! _vehicles.push(vehicle);
! ! ! ! addChild(vehicle);
! ! ! }//end for
! ! ! //addEventListener(Event.ENTER_FRAME, enterFrameHandler);
! ! }//end function
! !

!
! ! //--------------------------------------
! ! // EVENT HANDLERS
! ! //--------------------------------------
! ! private function resizeHandler($e:Event):void
! ! {
! ! ! _bg.width = _stage.sW;
! ! ! _bg.height = _stage.sH;
! ! }//end function
! !
! ! private function enterFrameHandler($e:Event):void
! ! {
! ! ! //*
! ! ! _motionTracker.track();
! ! !
! ! ! if( _motionTracker.hasMovement )
! ! ! {
! ! ! ! _invisVehicle.seek(new Vector2D(_motionTracker.x,
_motionTracker.y));
! ! ! !
! ! ! }//end if */
! ! ! _invisVehicle.update();
! ! !
! ! ! var mL:int = _getMicLevel();
! ! !
! ! ! //trace("LEVEL", mL);
! ! !
! ! ! for(var i:int = 0; i < _numVehicles; i++)
! ! ! {
! ! ! ! _tempObj = _vehicles[i];
! ! ! ! _tempObj.flock(_vehicles);
! ! ! ! //*
! ! ! ! if( _motionTracker.hasMovement && mL >= 50)
! ! ! ! {
! ! ! ! ! _tempObj.pursue(_invisVehicle);//new Vector2D
(_motionTracker.x, _motionTracker.y))
! ! ! ! }else if(_motionTracker.hasMovement && mL <= 49){
! ! ! ! ! _tempObj.evade(_invisVehicle);//new Vector2D
(_motionTracker.x, _motionTracker.y))
! ! ! ! }//end if*/
! ! ! ! _tempObj.update();
! ! ! }//end for
! ! }//end for

!
! ! //--------------------------------------
! ! // PUBLIC METHODS
! ! //--------------------------------------
! ! public function stopTracking()
! ! {
! ! ! if(_motionTracker.userHasCamera)
! ! ! {
! ! ! ! this.removeEventListener(Event.ENTER_FRAME,
enterFrameHandler);
! ! ! ! _motionTracker.detachCamera(true);
! ! ! ! //_video.attachCamera(null);
! ! ! }else{
! ! ! ! //removeEventListener( MouseEvent.MOUSE_DOWN,
oMD );
! ! ! }//end if
! ! }//end function

! ! public function startTracking()


! ! {
! ! ! if(_motionTracker.userHasCamera)
! ! ! {
! ! ! ! this.addEventListener(Event.ENTER_FRAME,
enterFrameHandler);
! ! ! ! _motionTracker.detachCamera(false);
! ! ! }else{
! ! ! ! //addEventListener( MouseEvent.MOUSE_DOWN, oMD );
! ! ! }//end if
! ! }//end function
! !
! ! public function updateColors($colorRay:Array):void
! ! {
! ! ! _roomColors.splice(0);
! ! ! _roomColors = $colorRay;
! ! !
! ! ! for(var i:uint = 0; i < _vehicles.length; ++i)
! ! ! {
! ! ! ! _vehicles[i].updateColor(_roomColors[VerMath.randRange
(1, (_roomColors.length - 1) )])
! ! ! }//end function
! ! }//end function
! !
! ! public function oldUpdateNumbers($num):void
! ! {!
! ! ! /*! !
! ! ! var n:uint = $num - _numVehicles;
! ! !
! ! ! if($num <= 5)
! ! ! {
! ! ! ! _numVehicles = 15;
! ! ! }else{
! ! ! ! _numVehicles = 25;
! ! ! }//end if
! ! !
! ! ! if(n == 10)
! ! ! {
! ! ! ! _vehicles.splice(0,10)
! ! ! }else{
! ! ! ! for(var i:int = 0; i < _numVehicles; i++)
! ! ! ! {
! ! ! ! ! var vehicle:SteeredVehicle = new SteeredVehicle
(_roomColors[VerMath.randRange(1, (_roomColors.length - 1) )]);
! ! ! ! ! vehicle.scaleX = vehicle.scaleY = VerMath.randRange
(0.8, 1.1, false)
! ! ! ! ! vehicle.position = new Vector2D(Math.random() *
_stage.sW, Math.random() * _stage.sH );
! ! ! ! ! vehicle.velocity = new Vector2D(Math.random() * 20 -
10, Math.random() * 20 - 10);
! ! ! ! ! vehicle.edgeBehavior = Vehicle.BOUNCE;
! ! ! ! ! _vehicles.push(vehicle);
! ! ! ! ! addChild(vehicle);
! ! ! ! }//end for
! ! ! }//end if*/
! ! }//end function

! ! public function updateNumbers($rates:Object):void


! ! {
! ! !
! ! }//end function
! !
! }//end class
}//end package

Вам также может понравиться