/Flash project/src/com/danta/radialFortress/components/EnemyBullet.as
ActionScript | 162 lines | 63 code | 29 blank | 70 comment | 1 complexity | f0f982ae80507d97aed9ee687fc927ef MD5 | raw file
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Zemoga Inc
- // Copyright 2011 Zemoga Inc
- // All Rights Reserved.
- //
- ////////////////////////////////////////////////////////////////////////////////
- package com.danta.radialFortress.components
- {
- import com.danta.radialFortress.FortressEvent;
- import com.danta.radialfortress.lib.Beam;
- import com.danta.util.ArcHelper;
-
- import flash.display.BlendMode;
- import flash.display.Sprite;
- import flash.filters.GlowFilter;
-
-
- /**
- * Class description here
- *
- * @author camilosoto <email>
- */
- public class EnemyBullet extends Sprite
- {
- //------------------------------------------------------------------------------
- //
- // Constants
- //
- //------------------------------------------------------------------------------
-
- //--------------------------------------
- // Public
- //--------------------------------------
-
- public static var BULLET_SPEED:Number=0.2;
-
- //--------------------------------------
- // Private
- //--------------------------------------
-
- //------------------------------------------------------------------------------
- //
- // Static Methods
- //
- //------------------------------------------------------------------------------
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Constructor
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- public function EnemyBullet(angularPosition:Number, radialDistance:Number)
- {
- createBody();
- this.radialVelocity=BULLET_SPEED;
- this.radialDistance=radialDistance;
- this.angularPosition=angularPosition;
- rotation=ArcHelper.toDeg(-angularPosition);
- this.x=Math.sin(angularPosition)*radialDistance;
- this.y=Math.cos(angularPosition)*radialDistance;
-
- }
-
- //------------------------------------------------------------------------------
- //
- // Variables
- //
- //------------------------------------------------------------------------------
-
- //--------------------------------------
- // Public
- //--------------------------------------
-
- //--------------------------------------
- // Private
- //--------------------------------------
-
- private var _angularPosition:Number;
- private var _radialDistance:Number;
- private var radialVelocity:Number;
- private var lastDeltaT:Number;
-
- //------------------------------------------------------------------------------
- //
- // Properties (getters/setters)
- //
- //------------------------------------------------------------------------------
-
- //------------------------------------------------------------------------------
- //
- // Overriden methods
- //
- //------------------------------------------------------------------------------
-
- //------------------------------------------------------------------------------
- //
- // Methods
- //
- //------------------------------------------------------------------------------
-
- //--------------------------------------
- // Public
- //--------------------------------------
-
- public function get angularPosition():Number
- {
- return _angularPosition;
- }
-
- public function set angularPosition(value:Number):void
- {
- _angularPosition = value;
- }
-
- public function get radialDistance():Number
- {
- return _radialDistance;
- }
-
- public function get collisionRadialDistances():Array
- {
- return [_radialDistance, radialDistance+radialVelocity*lastDeltaT];
- }
-
- public function set radialDistance(value:Number):void
- {
- _radialDistance = value;
- }
-
- public function draw(deltaT:uint):void
- {
- radialDistance+=radialVelocity*deltaT;
- this.x=Math.sin(angularPosition)*radialDistance;
- this.y=Math.cos(angularPosition)*radialDistance;
-
- if(radialDistance<=0)
- {
- dispatchEvent(new FortressEvent(FortressEvent.BULLET_REACHED_CENTER));
- }
- lastDeltaT=deltaT;
- }
-
- //--------------------------------------
- // Private
- //--------------------------------------
-
- private function createBody():void
- {
- this.addChild(new Beam());
- this.filters=[new GlowFilter(0xff0000,1,3,8,4)];
- }
-
- //------------------------------------------------------------------------------
- //
- // Event Handlers
- //
- //------------------------------------------------------------------------------
-
- }
- }