the most beautiful grid of fields you can imagine

remotes/checkIfPRContentChanged-1749880758504311652/farming_mechanic
kziolkowski 8 months ago
parent 222c10fe0a
commit 0de6bc0c04

@ -67,8 +67,10 @@ public partial class FarmingControls2D : Node2D
public override void _Input(InputEvent @event)
{
Vector2 mousePosition = _camera.GetGlobalMousePosition();
Vector2I adjustedPosition = new Vector2I(AdjustValue(mousePosition.X), AdjustValue(mousePosition.Y));
Vector2I mousePositionInteger = (Vector2I) mousePosition;
GD.Print(mousePosition);
Vector2I adjustedPosition = AdjustValue(mousePositionInteger, new Vector2I(735, 651));
GD.Print(adjustedPosition);
if (@event.IsActionPressed("click") && _toolId == 0)
{
@ -95,14 +97,10 @@ public partial class FarmingControls2D : Node2D
if(FieldParent == null || _fieldPrefab == null)
return;
bool fieldAllowed = FieldParent.FieldAllowed();
GD.Print($"Field allowed at {fieldPosition}: {fieldAllowed}");
// only try to instantiate a field if you're in the allowed area
if (!fieldAllowed)
if (!FieldParent.FieldAllowed())
return;
// only instantiate a field if there isn't one already.
if(FieldParent.Get(fieldPosition) == null)
{
@ -123,6 +121,14 @@ public partial class FarmingControls2D : Node2D
private int AdjustValue(float value)
{
return (int) Mathf.Floor(value);
float adjustedValue = value / 500;
adjustedValue = Mathf.RoundToInt(adjustedValue);
adjustedValue *= 500;
return (int)adjustedValue;
}
private Vector2I AdjustValue(Vector2I input, Vector2I step)
{
return input.Snapped(step);
}
}
Loading…
Cancel
Save