Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package actors
- {
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import utils.IPoolable;
- import utils.ObjectPool;
- public class Bullet extends Actor implements IPoolable
- {
- private var _pool:ObjectPool; //reference
- private var _nextObject:IPoolable; //reference, singly linked list
- private var _alive:Boolean = false;
- //private var _gfx:RotAnimSprite = null; //reference
- //private var _scrollRect:Rectangle = null;
- //private var _time:int = 0;
- //private var _currFrame:int = 0;
- //private var _behaviorFunction:Function;
- private var _vel:Number = 0; //pixels per frame, magnitude
- private var _velx:Number = 0; //pixels per frame
- private var _vely:Number = 0; //pixels per frame
- private var _acc:Number = 0; //magnitude
- //private var _accx:Number = 0;
- //private var _accy:Number = 0;
- //private var _point:Point = null;
- //private var _dir:Number = 0; //degrees
- private var _veldir:Number = 0;
- private var _accdir:Number = 0;
- private var _a:Number = 0; //misc factors
- private var _b:Number = 0;
- private var _c:Number = 0;
- public function Bullet(pool:ObjectPool)
- {
- super();
- this._pool = pool;
- }
- public override function update():void
- {
- if (_alive) {
- super.update();
- }
- }
- public function revive():void
- {
- _alive = true;
- }
- //Defines new attributes and behavior for the bullet object. Some attributes passed may
- //not be used by the defined behavior.
- public function fire(image:RotAnimSprite, funct:Function, x:Number, y:Number, dir:Number, vel:Number, acc:Number = 0, veldir:Number = 0, accdir:Number = 0):void
- {
- if (funct != null) {
- _behaviorFunction = funct;
- }
- gfx = image;
- resetAnimation();
- _point.x = x - _gfx.width * 0.5;
- _point.y = y - _gfx.height * 0.5;
- _dir = dir;
- _vel = vel;
- _velx = _vel * Math.cos(_dir * Main.CONVERT_TO_RADIANS);
- _vely = _vel * Math.sin(_dir * Main.CONVERT_TO_RADIANS);
- _acc = acc;
- //_accx = _acc * Math.cos(_dir * Main.CONVERT_TO_RADIANS);
- //_accy = _acc * Math.sin(_dir * Main.CONVERT_TO_RADIANS);
- _veldir = veldir;
- _accdir = accdir;
- revive();
- }
- public function recycle():void
- {
- _pool.recycle(this);
- _alive = false;
- }
- public function behaviorBasic():void {
- _point.x += _velx;
- _point.y += _vely;
- if (checkOutOfScreen()) recycle();
- }
- public function behaviorAdvanced():void {
- var n:int = (_vel + _acc) / _vel;
- _velx *= n;
- _vely *= n;
- _point.x += _velx;
- _point.y += _vely;
- if (checkOutOfScreen()) recycle();
- }
- public function behaviorSpiral():void {
- _dir += _veldir;
- _velx = _vel * Math.cos(_dir * Main.CONVERT_TO_RADIANS);
- _vely = _vel * Math.sin(_dir * Main.CONVERT_TO_RADIANS);
- _point.x += _velx;
- _point.y += _vely;
- if (checkOutOfScreen()) recycle();
- }
- public function get alive():Boolean {
- return _alive;
- }
- public function get nextObject():IPoolable {
- return _nextObject;
- }
- public function set nextObject(obj:IPoolable):void {
- _nextObject = obj;
- }
- public function get pool():ObjectPool {
- return _pool;
- }
- public override function trash():void
- {
- super.trash();
- _pool = null;
- _nextObject = null;
- _gfx = null;
- _vel = 0;
- _velx = 0;
- _vely = 0;
- _acc = 0;
- //_accx = 0;
- //_accy = 0;
- _point = null;
- _veldir = 0;
- _accdir = 0;
- _alive = false;
- _behaviorFunction = null;
- //this = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement