/// <summary> /// Установить скорость объект для преследования /// </summary> /// <param name="direction">1 - towards object, 0 - backward</param> public void SetTargetPointSpeed(Target t) { Vector2f targetOrigin = t.entity.Position; var absoluteSpeed = Speed.AbsoluteValue(); Vector2f targetSpeed = new Vector2f(targetOrigin.X - e.Position.X, targetOrigin.Y - e.Position.Y); Speed = targetSpeed.Normalize(absoluteSpeed, t.inversion); }
public Projectile(Vector2f p, Vector2f v, float rotation) { Id = "P" + idCount.ToString(); idCount++; movement = new Movement(this); #region Constants size = Constants.Projectile.radius; baseSpeed = Constants.Projectile.speed; maxSpeed = Constants.Projectile.maxSpeed; maxLifetime = Constants.Projectile.maxLifetime; baseDamage = Constants.Projectile.baseDamage; BoundReflection = false; #endregion shape = new RectangleShape(new Vector2f(size, size * 7)) { Origin = new Vector2f(size / 2, size * 2), Position = p }; movement.Rotation = rotation; Vector2f components = new Vector2f((float)Math.Sin(movement.Rotation.ToRadians()), (float)Math.Cos(movement.Rotation.ToRadians()) * -1); float scale = v.AbsoluteValue() / 100 + baseSpeed; if (scale > maxSpeed) { scale = maxSpeed; } movement.Speed = components * scale; SoundEngine.missleSound.Play(); }