the most beautiful grid of fields you can imagine
This commit is contained in:
@@ -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)
|
||||
{
|
||||
@@ -94,14 +96,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)
|
||||
return;
|
||||
|
||||
|
||||
// only try to instantiate a field if you're in the allowed area
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user