Tile vector

This commit is contained in:
Фёдор Веселов 2024-09-29 19:44:50 +05:00
commit 9197d0a939
2 changed files with 5 additions and 5 deletions

View file

@ -15,5 +15,7 @@ public partial class Utility
public const int LayersCount = 3; public const int LayersCount = 3;
public static readonly Vector2I LeftFieldBoundary = new Vector2I(305,76); public static readonly Vector2I LeftFieldBoundary = new Vector2I(305,76);
public static readonly Vector2I RightFieldBoundary = new Vector2I(755,376); public static readonly Vector2I RightFieldBoundary = new Vector2I(755,376);
public static readonly Vector2 Tile = new Vector2(Utility.TileWidth, Utility.TileHeight);
} }

View file

@ -7,8 +7,6 @@ namespace Newlon.Components.Level;
public partial class PlantField : Node2D public partial class PlantField : Node2D
{ {
private Sprite2D _plantSetter; private Sprite2D _plantSetter;
private readonly Vector2 tile = new Vector2(Utility.TileWidth, Utility.TileHeight);
private PlantResource _resource; private PlantResource _resource;
private Seedpacket _slot; private Seedpacket _slot;
private bool _previousCanPlace; private bool _previousCanPlace;
@ -39,7 +37,7 @@ public partial class PlantField : Node2D
_plantSetter.GlobalPosition = mouse_pos; _plantSetter.GlobalPosition = mouse_pos;
// Getting position in grid coordinates // Getting position in grid coordinates
var expected_pos = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14); var expected_pos = (_plantSetter.GlobalPosition / Utility.Tile).Ceil() * Utility.Tile - new Vector2(20, 14);
// Checking for boundaries // Checking for boundaries
bool inBoundary = expected_pos.X > Utility.LeftFieldBoundary.X && expected_pos.X < Utility.RightFieldBoundary.X && expected_pos.Y > Utility.LeftFieldBoundary.Y && expected_pos.Y < Utility.RightFieldBoundary.Y; bool inBoundary = expected_pos.X > Utility.LeftFieldBoundary.X && expected_pos.X < Utility.RightFieldBoundary.X && expected_pos.Y > Utility.LeftFieldBoundary.Y && expected_pos.Y < Utility.RightFieldBoundary.Y;
@ -82,11 +80,11 @@ public partial class PlantField : Node2D
{ {
var plant = _resource.Scene.Instantiate<RuntimePlantData>(); var plant = _resource.Scene.Instantiate<RuntimePlantData>();
PoolContainer.Instance.Plants.AddChild(plant); PoolContainer.Instance.Plants.AddChild(plant);
plant.GlobalPosition = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14); plant.GlobalPosition = (_plantSetter.GlobalPosition / Utility.Tile).Ceil() * Utility.Tile - new Vector2(20, 14);
plant.Resource = _resource; plant.Resource = _resource;
plant.Line = (int)plant.GlobalPosition.Y/Utility.TileHeight; plant.Line = (int)plant.GlobalPosition.Y/Utility.TileHeight;
PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity); PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant);
RuntimeLevelData.Instance.SpendSun(_resource.Cost); RuntimeLevelData.Instance.SpendSun(_resource.Cost);