All pastes #2124773 Raw Edit

Anonymous

public text v1 · immutable
#2124773 ·published 2012-03-06 06:21 UTC
rendered paste body
package  
{
	import flash.events.Event;
	import flash.display.MovieClip;
	import flash.geom.Point;
	import flash.utils.getTimer;
	
	/*
	 *
	 * IAT 167 - Week 7
	 * Tower Defense Game
	 * Janelynn Chan, 301178319, D102
	 *
	 */
	public class Bullet extends MovieClip implements IGameDisplayObject 
	{
		public static const BULLET_COLOR:int = 0xFFFFFF;
		public static const DAMAGE:int = 5;
		public static const MAX_SPEED:int = 5;
		
		public var damage:int = DAMAGE;
		public var target:Enemy;
		public var nextLocation:Point;
		public var lastTime:int = 0;
		public var turret:Turret;
		public var xSpeed:Number;
		public var ySpeed:Number;

		private var maxSpeed:Number = MAX_SPEED;
		
		public function Bullet(startX:Number, startY:Number, inpTarget:Enemy) 
		{
			super();
			
			this.x = startX;
			this.y = startY;
			target = inpTarget;
			
			init();
			
		}
		
		public function hitTarget():Boolean {
			var target:Enemy;
			
			var returnVal:Boolean = false;
			
			if (this.hitTestObject(target)) {
				returnVal = true;
				}
				
			return returnVal;
		}

		
		/* INTERFACE IGameDisplayObject */
		
		public function init():void 
		{
			nextLocation = new Point(target.x, target.y);
			this.graphics.beginFill(BULLET_COLOR);
			this.graphics.drawCircle(0,0,2);
			this.graphics.endFill();
		}
		
		public function update():void 
		{
			var yDist:Number=target.y+12.5 - this.y;//how far this guy is from the enemy (x)
			var xDist:Number=target.x+12.5 - this.x;//how far it is from the enemy (y)
			var angle:Number=Math.atan2(yDist,xDist);//the angle that it must move
			ySpeed=Math.sin(angle) * maxSpeed;//calculate how much it should move the enemy vertically
			xSpeed=Math.cos(angle) * maxSpeed;//calculate how much it should move the enemy horizontally
			
			//move the bullet towards the enemy
			
			nextLocation = new Point(target.x, target.y);
			
			nextLocation.x += xSpeed;
			nextLocation.y += ySpeed;
			
		}
		
		public function render():void 
		{
			this.x = nextLocation.x;
			this.y = nextLocation.y;
			
		}
		
		public function dispose():void 
		{
			
		}
		
	}

}