using Godot; using System; using Math = Ecosystem.utility.Math; public partial class Fly : BaseEntity { [Export] public float _tx = 0; [Export] public float _ty = 10000f; [Export] public float StepSizeX = .01f; [Export] public float StepSizeY = .1f; // private Perlin perlin = new Perlin(); private FastNoiseLite noise = new FastNoiseLite(); public override void _Ready() { base._Ready(); noise.SetSeed(GD.RandRange(int.MinValue, int.MaxValue)); // Position = ScreenSize / 2; animationPlayer.Play("fly"); } public void CreateRandom() { float randomTX = GD.Randf() % 10000; float randomTY = GD.Randf() % 10000; float randomStepSizeX = GD.Randf() % .1f; float randomStepSizeY = GD.Randf() % .1f; _tx = randomTX; _ty = randomTY; StepSizeX = randomStepSizeX; StepSizeY = randomStepSizeY; } private void step() { // double xNoise = perlin.Noise(_tx); // double yNoise = perlin.Noise(_ty); // var xNoise = noise.GetNoise1D(_tx); var yNoise = noise.GetNoise1D(_ty); // var noiseVal = noise.GetNoise2D(_tx, _ty); float x = Math.Map(xNoise, 0, 1, 0, ScreenSize.X); float y = Math.Map(yNoise, 0, 1, 0, ScreenSize.Y); Position = new Vector2( x: Mathf.Clamp(x, 0, ScreenSize.X), y: Mathf.Clamp(y, 0, ScreenSize.Y)); _tx += StepSizeX; _ty += StepSizeY; } public override void _Process(double delta) { step(); } }