Shovel done
This commit is contained in:
parent
47a3ca3db2
commit
c1f9f61b0c
5 changed files with 18 additions and 6 deletions
|
|
@ -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<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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public partial class PlantField : Node2D
|
|||
var plant = _resource.Scene.Instantiate<RuntimePlantData>();
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue