
using System;
using Math2D;

namespace PlanetExpress.items.enemys.masters {
	
	
	public class ChaoticEnemyMaster : BaseEnemyMaster {
		
		Vector2D Target = new Vector2D();
		static Random rnd = new Random();
		float tick;
		public ChaoticEnemyMaster(EnemyClass enemy) : base(enemy) {
			tick = GetHashCode()/10000f;
			NewTarget();
		}
		
		void NewTarget() {
			Target = new Vector2D(
			                      rnd.Next(GameApp.ScreenWidth),
			                      rnd.Next(GameApp.ScreenHeight));
		}
		
		bool doShoot = false;
		public override void Action (double timer) {
			tick += 10f * (float)timer;
			if ((((int)tick) % 25) == 0) {
				NewTarget();
				if (doShoot) Enemy.Shoot();
				doShoot = false;
			} else {
				doShoot = true;	
			}
			
			Vector2D Va = new Vector2D(Enemy.X, Enemy.Y) - Target;
			
			
			Va.Length = 100f * Enemy.SpeedScale * (float)timer;
			if (Enemy.Fixed) Enemy.X -= Va.X;
			Enemy.Y -= Va.Y;
		}

	}
}
