Shovel done

This commit is contained in:
Фёдор Веселов 2024-09-16 17:05:57 +05:00
commit c1f9f61b0c
5 changed files with 18 additions and 6 deletions

View file

@ -9,6 +9,9 @@ public partial class Utility
{ {
public const int TileWidth = 50; public const int TileWidth = 50;
public const int TileHeight = 60; public const int TileHeight = 60;
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);
} }

View file

@ -29,9 +29,18 @@ public partial class ShovelButton : TextureButton
{ {
if (@event.IsActionPressed("primary_action")) 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<RuntimePlantData>().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; ButtonPressed = false;
} }

View file

@ -71,7 +71,7 @@ public partial class PlantField : Node2D
var plant = _resource.Scene.Instantiate<RuntimePlantData>(); var plant = _resource.Scene.Instantiate<RuntimePlantData>();
LevelController.Instance.Pools.Plants.AddChild(plant); LevelController.Instance.Pools.Plants.AddChild(plant);
plant.GlobalPosition = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14); 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); LevelController.Instance.Pools.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity);

View file

@ -15,7 +15,7 @@ public partial class RuntimePlantData : Node2D, IEntity
public int Hp => _hp; public int Hp => _hp;
public int MaxHp => _maxHP; public int MaxHp => _maxHP;
public int Line => _line; public int Line => _line;
public int Layer; public PlantResource Resource;
public override void _Ready() public override void _Ready()
{ {
@ -44,7 +44,7 @@ public partial class RuntimePlantData : Node2D, IEntity
public void Kill() public void Kill()
{ {
LevelController.Instance.Pools.EntityField[Layer].Remove(GlobalPosition); LevelController.Instance.Pools.EntityField[Resource.Layer].Remove(GlobalPosition);
QueueFree(); QueueFree();
} }
} }