Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package classes
- {
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.geom.Vector3D;
- import flash.events.MouseEvent;
- import flash.utils.Timer;
- import flash.media.Sound;
- import flash.net.URLRequest;
- import flash.display.Stage;
- import flash.media.SoundChannel;
- import flash.utils.getDefinitionByName;
- import flash.utils.getQualifiedClassName;
- public class enemy_ez extends MovieClip
- {
- var enemyPosition:Vector3D = new Vector3D();
- var enemyDirection:Vector3D = new Vector3D();
- public var index:Number;
- var speed:Number = 3;
- var currentTarget:int = 0;
- public var enemyType:String = "ez";
- var health:Number = 100;
- var myStage:Stage;
- public function enemy_ez(s:Stage)
- {
- // constructor code
- myStage = s;
- this.addEventListener(Event.ENTER_FRAME, loop);
- }
- public function TakeDamage(t:Turret, d:Number)
- {
- if (health - d > 0)
- {
- health -= d;
- }
- else
- {
- Die(t);
- }
- }
- function Die(t:Turret)
- {
- this.removeEventListener(Event.ENTER_FRAME, loop);
- if (myStage.contains(this))
- {
- Game.waveArray.splice(index,1);
- t.target = null;
- myStage.removeChild(this);
- }
- function getCurrentAngle():Number
- {
- var perpendicular:Number = (Game.pathArray[currentTarget].y - y);
- var base:Number = (Game.pathArray[currentTarget].x - x);
- var angle:Number = Math.atan2(perpendicular,base);// in radians
- return (angle * 180 / Math.PI);// in degrees
- }
- function loop(e:Event)
- {
- x += 4;
- enemyPosition.x = x;
- enemyPosition.y = y;
- var targetPosition:Vector3D = new Vector3D();
- targetPosition.x = Game.pathArray[currentTarget].x;
- targetPosition.y = Game.pathArray[currentTarget].y;
- enemyDirection = targetPosition.subtract(enemyPosition);
- var distance:Number = enemyDirection.length;
- enemyDirection.normalize();
- if (distance <= 5)
- {
- if (currentTarget < Game.pathArray.length -1 )
- {
- currentTarget++;
- }
- else
- {
- this.removeEventListener(Event.ENTER_FRAME, loop);
- if (stage.contains(this))
- {
- stage.removeChild(this);
- }
- }
- }
- x += enemyDirection.x * speed;
- y += enemyDirection.y * speed;
- rotation = getCurrentAngle();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement