Files
FOU/Scripts/Main.cs
rogo ea34b8ecc0 moved tick to process from physics process
fixed fall speed
improved naming
2025-05-01 22:46:51 +02:00

65 lines
1.7 KiB
C#

using FOU.Scripts;
using FOU.Scripts.Elements;
using Godot;
public partial class Main : Node2D {
[Export] public bool DebugMode = false;
[Export] public bool AllowOverwrite = true;
[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;
public float RainAmount {
get => rainAmount;
set {
rainAmount = value;
Level?.SetRainAmount(rainAmount);
}
}
public override void _Ready() {
Level = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
(int)(GetViewportRect().Size.Y * TextureResolution));
Level.SetRainAmount(rainAmount);
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
Instance = this;
}
public override void _PhysicsProcess(double delta) {
base._PhysicsProcess(delta);
}
public override void _Process(double delta) {
Level.Update();
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<Dirt>((int)mappedX, (int)mappedY, BrushSize);
}
} else if (@event is InputEventKey keyEvent && keyEvent.Pressed) {
if (keyEvent.Keycode == Key.F9)
Level.StartBenchmark();
}
else base._UnhandledInput(@event);
}
}