Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package actors
- {
- import flash.display.BitmapData;
- import flash.geom.Point;
- import flash.geom.Rectangle;
- import actors.Bullet;
- import utils.IPoolable;
- import utils.ObjectPool;
- public class EnemyShip extends Actor implements IPoolable
- {
- private var _bulletPool:ObjectPool = null;
- private var _pool:ObjectPool;
- private var _nextObject:IPoolable;
- private var _alive:Boolean = false;
- private var _time:int = 0;
- private var _hitPoints:Number = 7;
- 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 _a:Number = 0;
- private var _b:Number = 0;
- private var _c:Number = 0;
- private var _d:Number = 0;
- private var _e:Number = 0;
- private var _f:Number = 0;
- private var _g:Number = 0;
- public function EnemyShip(pool:ObjectPool)
- {
- super();
- _pool = pool;
- }
- public override function update():void
- {
- if (_alive) {
- super.update();
- }
- }
- public function revive():void
- {
- _alive = true;
- }
- public function spawn(image:RotAnimSprite, funct:Function, bulletPool:ObjectPool, x:Number, y:Number):void {
- gfx = image;
- _behaviorFunction = funct;
- _bulletPool = bulletPool;
- _point.x = x - _gfx.width * 0.5;
- _point.y = y - _gfx.height * 0.5;
- _a = 0;
- _b = 0;
- _c = 0;
- _d = 0;
- _e = 0;
- _f = 0;
- _g = 0
- revive();
- }
- public function recycle():void
- {
- _pool.recycle(this);
- _alive = false;
- }
- public function behaviorDefault():void {
- defaultBehavior();
- }
- public function behaviorTestInit():void {
- _vel = 0.4;
- dir = 90;
- _behaviorFunction = behaviorTest;
- }
- private function behaviorTest():void {
- //Movement
- //Does not work correctly
- _f++;
- if(_f > 20){
- if(Math.random() > 1.08 - ((_point.x - 319) * 0.01 + (_point.y - 19) * 0.02)){ //change direction randomly
- if (Math.random() < 0.5 + _g * 0.25) {
- dir = _dir - 45; //left
- _g--;
- }
- else {
- dir = _dir + 45; //right
- _g++;
- }
- _f = 0;
- }
- }
- _point.x += _velx;
- _point.y += _vely;
- //Firing bullets
- _time++;
- _e++;
- if (_e > 3) {
- if (_d == 0) {
- _d = 1;
- _e = 0;
- }
- }
- if (_e > 11) {
- if (_d == 1) {
- _d = 0;
- _e = 0;
- }
- }
- if(_d == 1){
- if (_time % 4 == 0) {
- _b += 1;
- var bullet:Bullet = null;
- _a += Math.random() + 0.5;
- if (_a > 2) {
- _a = Math.random() - 0.5;
- if (_a < 0) _c = -5 + _a * 7.5;
- else _c = 5 + _a * 7.5;
- _a = 0;
- }
- if(_c != 0){
- for (var i:int = 0; i < 3; i++) {
- bullet = Bullet(_bulletPool.getNext());
- bullet.fire(GameEngine.rotatableBulletRed, bullet.behaviorBasic, _point.x + 81, _point.y + 101, 70 + _c + 20 * i, 4.5 + _b * 0.025);
- }
- _c = 0;
- }
- else {
- for (i = 0; i < 3; i++) {
- bullet = Bullet(_bulletPool.getNext());
- bullet.fire(GameEngine.rotatableBulletRed, bullet.behaviorBasic, _point.x + 81, _point.y + 101, 70 + 20 * i, 5.5 + _b * 0.025);
- }
- }
- }
- }
- if (_time % 450 == 0) {
- _b = 0;
- }
- }
- public function get pool():ObjectPool {
- return _pool;
- }
- public function get nextObject():IPoolable {
- return _nextObject;
- }
- public function set nextObject(obj:IPoolable):void {
- _nextObject = obj;
- }
- public function get alive():Boolean {
- return _alive;
- }
- private function set dir(a:Number):void {
- _dir = a;
- _velx = _vel * Math.cos(_dir * Main.CONVERT_TO_RADIANS);
- _vely = _vel * Math.sin(_dir * Main.CONVERT_TO_RADIANS);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement