Threepeater added and line system removed

This commit is contained in:
Фёдор Веселов 2024-10-03 01:21:02 +05:00
commit b5d2466be4
16 changed files with 131 additions and 209 deletions

View file

@ -19,6 +19,7 @@ public class Utility
#endregion
public const int EffectSlotCount = 3;
public const int LineCount = 5;
public const int TileWidth = 50;
public const int TileHeight = 60;
public const int LayersCount = 3;

View file

@ -7,7 +7,6 @@ public interface IEntity
{
public int Hp { get; }
public int MaxHp { get; }
public int Line { get; }
public void TakeDamage(int amount);
public void Heal(int amount);
}

View file

@ -26,7 +26,7 @@ public partial class LinearProjectile : Area2D, IProjectile
public void OnAreaEntered(Area2D area)
{
var entity = area.GetParent<IEntity>();
if (entity != null && entity.Line == _line)
if (entity != null)
{
entity.TakeDamage(_damage);
if (entity is IEffectHandler effectHandler && _impactEffect != null)

View file

@ -91,7 +91,6 @@ public partial class PlantField : Node2D
PoolContainer.Instance.Plants.AddChild(plant);
plant.GlobalPosition = (_plantSetter.GlobalPosition / Utility.Tile).Ceil() * Utility.Tile - new Vector2(20, 14);
plant.Resource = _resource;
plant.Line = (int)plant.GlobalPosition.Y/Utility.TileHeight;
PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant);

View file

@ -7,12 +7,14 @@ public partial class Eyesight : Area2D
{
private bool _enemyDetected;
public bool EnemyDetected => _enemyDetected;
private List<IEntity> _detectedEntities = new List<IEntity>();
private readonly List<IEntity> _detectedEntities = new List<IEntity>();
private RuntimePlantData _plantData;
public override void _Ready()
{
_plantData = GetParent<RuntimePlantData>();
AreaEntered += OnAreaEntered;
AreaExited += OnAreaExited;
}
public void OnAreaEntered(Area2D area)
@ -20,10 +22,7 @@ public partial class Eyesight : Area2D
var entity = area.GetParent<IEntity>();
if (entity != null)
{
if (_plantData.Line == entity.Line)
{
_detectedEntities.Add(entity);
}
_detectedEntities.Add(entity);
}
_enemyDetected = _detectedEntities.Count > 0;

View file

@ -6,10 +6,10 @@ namespace Newlon.Components.Plants;
// Shoot component of some plants
public partial class Shooter : Node2D
{
[Export] private PackedScene _projectile;
[Export] private Timer _timer;
[Export] protected PackedScene _projectile;
[Export] protected Timer _timer;
private RuntimePlantData _plantData;
protected RuntimePlantData _plantData;
public override void _Ready()
{
@ -22,13 +22,13 @@ public partial class Shooter : Node2D
if (_timer.TimeLeft > 0) return;
_timer.Start();
SpawnProjectile();
}
public virtual void SpawnProjectile()
{
var instance = _projectile.Instantiate<Node2D>();
PoolContainer.Instance.Projectiles.AddChild(instance);
instance.GlobalTransform = GlobalTransform;
if (instance is IProjectile projectile)
{
projectile.Line = _plantData.Line;
}
}
}

View file

@ -0,0 +1,26 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.Plants;
public partial class ThreepeaterShooter : Shooter
{
public override void SpawnProjectile()
{
for(int i = -1; i <= 1; i++)
{
if ((int)GetParent<Node2D>().GlobalPosition.Y/Utility.TileHeight+i < 0 || (int)GetParent<Node2D>().GlobalPosition.Y/Utility.TileHeight+i > Utility.LineCount+1)
continue;
var instance = _projectile.Instantiate<Node2D>();
PoolContainer.Instance.Projectiles.AddChild(instance);
instance.GlobalTransform = GlobalTransform;
if(i != 0)
{
var tween = CreateTween().SetEase(Tween.EaseType.Out).SetTrans(Tween.TransitionType.Sine);
tween.TweenProperty(instance,"position:y",instance.Position.Y+i*Utility.TileHeight,0.5);
}
}
}
}

View file

@ -4,14 +4,19 @@ namespace Newlon.Components.Plants.Behaviours;
public partial class PeashooterBehaviour : Node
{
[Export] private AnimationTree _animationTree;
[Export] private AnimationPlayer _player;
[Export] private Timer _shootTimer;
[Export] private Eyesight _sight;
[Export] private string _libName;
public override void _Process(double delta)
{
bool readyToShoot = _sight.EnemyDetected && _shootTimer.TimeLeft <= 0;
_animationTree.Set("parameters/conditions/ready", readyToShoot);
if(readyToShoot)
{
_player.Play(_libName+"/shoot");
_player.Queue(_libName+"/idle");
}
}
}