Files
Ecosystem-Project/scenes/entities/fly/Fly.cs
gdz 802918e5b8 Version 0.1 - 0.3.1
Added the World
Added Mobs, and spawning those mobs at runtime
Added simple camera movement
Added simple UI/HUD
2025-07-29 23:21:53 +02:00

65 lines
1.6 KiB
C#

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();
}
}