added chunks

This commit is contained in:
2024-07-14 17:22:37 +02:00
parent 5d07477de5
commit 31edd511e0
8 changed files with 213 additions and 124 deletions

View File

@@ -1,3 +1,4 @@
using System.Reflection;
using FOU.Scripts;
using FOU.Scripts.Elements;
using Godot;
@@ -7,6 +8,7 @@ public partial class Main : Node2D {
[Export] public int BrushSize = 5;
[Export] public float TextureResolution = 0.5f;
[Export] public int ChunksPerAxis = 2;
[Export] public float RainAmount = 0.01f;
public static Main Instance;
@@ -15,16 +17,14 @@ public partial class Main : Node2D {
private Level mLevel;
public override void _Ready() {
mLevel = new Level((int)(GetViewportRect().Size.X * TextureResolution),
(int)(GetViewportRect().Size.Y * TextureResolution), this
);
mLevel = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
(int)(GetViewportRect().Size.Y * TextureResolution));
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
Instance = this;
}
public override void _Process(double delta) {
mLevel.Update();
mLevelDrawer.Texture = ImageTexture.CreateFromImage(mLevel.DrawLevel());
}
@@ -34,8 +34,8 @@ public partial class Main : Node2D {
Vector2 mouse = GetViewport().GetMousePosition();
float mappedX = mouse.X / GetViewportRect().Size.X * mLevel.SizeX;
float mappedY = mouse.Y / GetViewportRect().Size.Y * mLevel.SizeY;
float mappedX = mouse.X / (GetViewportRect().Size.X / mLevel.Resolution.X);
float mappedY = mouse.Y / (GetViewportRect().Size.Y / mLevel.Resolution.Y);
mLevel.WritePixel<Dirt>((int)mappedX, (int)mappedY, BrushSize);
}