diff --git a/puki.txt b/puki.txt index 06eb39f..7948cdf 100644 --- a/puki.txt +++ b/puki.txt @@ -30,4 +30,4 @@ И благословил их Бог, и сказал им Бог: плодитесь и размножайтесь, и наполняйте землю, и обладайте ею, и владычествуйте над рыбами морскими [и над зверями,] и над птицами небесными, [и над всяким скотом, и над всею землею,] и над всяким животным, пресмыкающимся по земле. И сказал Бог: вот, Я дал вам всякую траву, сеющую семя, какая есть на всей земле, и всякое дерево, у которого плод древесный, сеющий семя; – вам сие будет в пищу; а всем зверям земным, и всем птицам небесным, и всякому [гаду,] пресмыкающемуся по земле, в котором душа живая, дал Я всю зелень травную в пищу. И стало так. -И увидел Бог все, что Он создал, и вот, хорошо весьма. И был вечер, и было утро: день шестой. \ No newline at end of file +И увидел Бог все, что Он создал, и вот, хорошо весьма. И был вечер, и было утро: день шестой. diff --git a/scripts/Utility.cs b/scripts/Utility.cs index 7b5d9b0..7fc941b 100644 --- a/scripts/Utility.cs +++ b/scripts/Utility.cs @@ -9,6 +9,9 @@ public partial class Utility { public const int TileWidth = 50; public const int TileHeight = 60; + + public const int LayersCount = 3; public static readonly Vector2I LeftFieldBoundary = new Vector2I(305,76); public static readonly Vector2I RightFieldBoundary = new Vector2I(755,376); + } diff --git a/scripts/components/gui/ShovelButton.cs b/scripts/components/gui/ShovelButton.cs index 35a281f..5402248 100644 --- a/scripts/components/gui/ShovelButton.cs +++ b/scripts/components/gui/ShovelButton.cs @@ -29,9 +29,18 @@ public partial class ShovelButton : TextureButton { if (@event.IsActionPressed("primary_action")) { - if (_shovelCast.IsColliding() && (_shovelCast.GetCollider() as CollisionObject2D).GetParent() is RuntimePlantData plant) + if (_shovelCast.IsColliding()) { - plant.Kill(); + var checkedPosition = (_shovelCast.GetCollider() as Node).GetParent().GlobalPosition; + + for (int i = Utility.LayersCount-1; i >= 0; i--) + { + if (LevelController.Instance.Pools.EntityField[i].TryGetValue(checkedPosition, out var entity) && entity is RuntimePlantData plantData) + { + plantData.Kill(); + break; + } + } } ButtonPressed = false; } diff --git a/scripts/components/level/PlantField.cs b/scripts/components/level/PlantField.cs index aaaf5ab..65c19aa 100644 --- a/scripts/components/level/PlantField.cs +++ b/scripts/components/level/PlantField.cs @@ -71,7 +71,7 @@ public partial class PlantField : Node2D var plant = _resource.Scene.Instantiate(); LevelController.Instance.Pools.Plants.AddChild(plant); plant.GlobalPosition = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14); - plant.Layer = _resource.Layer; + plant.Resource = _resource; LevelController.Instance.Pools.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity); diff --git a/scripts/components/plants/RuntimePlantData.cs b/scripts/components/plants/RuntimePlantData.cs index fe72a3e..8f3697a 100644 --- a/scripts/components/plants/RuntimePlantData.cs +++ b/scripts/components/plants/RuntimePlantData.cs @@ -15,7 +15,7 @@ public partial class RuntimePlantData : Node2D, IEntity public int Hp => _hp; public int MaxHp => _maxHP; public int Line => _line; - public int Layer; + public PlantResource Resource; public override void _Ready() { @@ -44,7 +44,7 @@ public partial class RuntimePlantData : Node2D, IEntity public void Kill() { - LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition); + LevelController.Instance.Pools.EntityField[Resource.Layer].Remove(GlobalPosition); QueueFree(); } }