/// <summary> /// initialise an ammo object /// </summary> /// <param name="pos">spawning position</param> /// <param name="dir">spawning direction</param> /// <param name="vel">spawning velocity</param> public virtual void Init(Point2D pos, Vector dir, Vector vel) { //set position and direction of ammo to that of the passed in parent entity TeleportTo(pos); theta = Dir.AngleTo(dir) * Math.PI / 180; MaxVel += vel.Magnitude; cdHandler = new CooldownHandler(lifetime * 1000); cdHandler.StartCooldown(); }
/// <summary> /// Initialise the particle /// </summary> /// <param name="pos">spawning position</param> /// <param name="dir">spawning direction</param> public void Init(Point2D pos, Vector dir) { thrustForce = Util.RandomInRange(velRange); turnRate = Util.RandomInRange(turnRateRange); lifetime = Util.RandomInRange(lifetimeRange); cdHandler = new CooldownHandler(lifetime * 1000); cdHandler.StartCooldown(); TeleportTo(pos); double theta = Dir.AngleTo(dir) * Math.PI / 180; this.theta = theta; Vector deltaV = dir.Multiply(-thrustForce); Vel = (Vel.AddVector(deltaV)).LimitToMagnitude(thrustForce); }
/// <summary> /// checks if the difference between the target direction and the current direction is small enough to start thrusting forward /// </summary> public bool ShouldThrust(Vector targetDir) { return(Math.Abs(Dir.AngleTo(targetDir)) < 45); }