using FOU.Scripts; using FOU.Scripts.Elements; using Godot; public partial class Main : Node2D { [Export] public bool DebugMode = false; [Export] public int BrushSize = 5; [Export] public float TextureResolution = 0.5f; [Export] public int ChunksPerAxis = 2; [Export] public float RainAmount = 0; public static Main Instance; public Level Level; private TextureRect mLevelDrawer; private bool enableRain; private float rainAmount; public override void _Ready() { Level = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution), (int)(GetViewportRect().Size.Y * TextureResolution)); Level.SetRainAmount(rainAmount); mLevelDrawer = GetNode("CanvasLayer/LevelDrawer"); Instance = this; } public override void _PhysicsProcess(double delta) { base._PhysicsProcess(delta); Level.Update(); } public override void _Process(double delta) { mLevelDrawer.Texture?.Dispose(); mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel()); } public override void _UnhandledInput(InputEvent @event) { if (@event is InputEventMouseButton eventMouseButton) { if (eventMouseButton.IsPressed()) { Vector2 mouse = GetViewport().GetMousePosition(); float mappedX = mouse.X / (GetViewportRect().Size.X / Level.Resolution.X); float mappedY = mouse.Y / (GetViewportRect().Size.Y / Level.Resolution.Y); Level.WritePixel((int)mappedX, (int)mappedY, BrushSize); } } else if (@event is InputEventKey keyEvent && keyEvent.Pressed) { if (keyEvent.Keycode == Key.F9) Level.StartBenchmark(); } else base._UnhandledInput(@event); } }