file refactor

This commit is contained in:
Rendo 2025-07-11 22:35:36 +05:00
commit bffb012a26
175 changed files with 1086 additions and 1107 deletions

View file

@ -0,0 +1,18 @@
using Godot;
using Newlon.Components.Zombies;
namespace Newlon.Components.Plants;
public partial class AreaAttack : Area2D
{
[Export] private int _damage;
public void Attack()
{
foreach (var zombie in GetOverlappingAreas())
{
var zombieData = zombie.GetParent<RuntimeZombieData>();
zombieData?.TakeDamage(_damage,GetParent());
}
}
}

View file

@ -0,0 +1 @@
uid://co7ttejdo2qot

View file

@ -0,0 +1,26 @@
using Godot;
using Newlon.Components.Level;
using Newlon.Components.Zombies;
namespace Newlon.Components.Plants;
public partial class ExplosionComponent : Area2D
{
[Export] private int damage;
[Export] private PackedScene particles;
public void Explode()
{
foreach (var zombie in GetOverlappingAreas())
{
var zombieData = zombie.GetParent<RuntimeZombieData>();
zombieData?.TakeDamage(damage, GetParent());
}
PoolContainer.Instance.SpawnParticles(particles, GetParent<RuntimePlantData>().GlobalPosition);
GetNode<ChannelPlayer>("ExplosionPlayer").Play();
GetParent<RuntimePlantData>().Kill();
}
}

View file

@ -0,0 +1 @@
uid://bhl6o2m3fn4xg

View file

@ -0,0 +1,44 @@
using Godot;
using System.Collections.Generic;
namespace Newlon.Components.Plants;
public partial class Eyesight : Area2D
{
private bool _enemyDetected;
public bool EnemyDetected => _enemyDetected;
private readonly List<Entity> _detectedEntities = new List<Entity>();
private RuntimePlantData _plantData;
public override void _Ready()
{
_plantData = GetParent<RuntimePlantData>();
AreaEntered += OnAreaEntered;
AreaExited += OnAreaExited;
}
public void OnAreaEntered(Area2D area)
{
var entity = area.GetParent<Entity>();
if (entity != null)
{
_detectedEntities.Add(entity);
}
_enemyDetected = _detectedEntities.Count > 0;
}
public void OnAreaExited(Area2D area)
{
var entity = area.GetParent<Entity>();
if (entity != null)
{
if (_detectedEntities.Contains(entity))
{
_detectedEntities.Remove(entity);
}
}
_enemyDetected = _detectedEntities.Count > 0;
}
}

View file

@ -0,0 +1 @@
uid://dn53jvpjyg63l

View file

@ -0,0 +1,18 @@
using Godot;
namespace Newlon.Components.Plants;
public partial class LoseZone : RuntimePlantData
{
public override void TakeDamage(float amount, Node origin)
{
}
public override void Kill()
{
}
}

View file

@ -0,0 +1 @@
uid://c0ov2bq5er0gh

View file

@ -0,0 +1,14 @@
using Godot;
namespace Newlon.Components.Plants;
public partial class PlantEyesightLimiter : CollisionShape2D
{
public override void _Process(double delta)
{
if (Shape is SegmentShape2D segment)
{
segment.B = new Vector2(Utility.RightFieldBoundary.X - GlobalPosition.X, 0);
}
}
}

View file

@ -0,0 +1 @@
uid://hccb0aee0x0o

View file

@ -0,0 +1,21 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.Plants;
public partial class PlantSunSpawner : Node2D
{
[Export]
private PackedScene _sunScene;
[Export]
private int _amountPerSun;
public void Spawn()
{
var sun = _sunScene.Instantiate<Sun>();
sun.amount = _amountPerSun;
PoolContainer.Instance.Projectiles.AddChild(sun);
sun.GlobalPosition = GlobalPosition;
}
}

View file

@ -0,0 +1 @@
uid://b71gebny84s81

View file

@ -0,0 +1,20 @@
using Godot;
using Newlon.Components.Zombies;
using Newlon.Systems.Effects;
namespace Newlon.Components.Plants;
public partial class ReturnEffect : Node
{
[Export]
private Effect _effectToReturn;
public void OnDamageRecieved(int delta,Node origin)
{
if (delta >= 0) return;
if (origin is RuntimeZombieData zombie)
{
zombie.GiveEffect(_effectToReturn);
}
}
}

View file

@ -0,0 +1 @@
uid://bmtukcq10m8wo

View file

@ -0,0 +1,25 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.Plants;
//
// Data that plant stores during runtime
//
public partial class RuntimePlantData : Entity
{
public int Line { get; set; }
public PlantResource Resource;
private AudioStream eatenSound = ResourceLoader.Load<AudioStream>("res://assets/audio/sfx/gulp.mp3");
public override void KillByDamage()
{
AudioSequencer.Play("plant_eaten", eatenSound);
base.KillByDamage();
}
public override void Kill()
{
PoolContainer.Instance.EntityField[Resource.Layer].Remove(GlobalPosition);
QueueFree();
}
}

View file

@ -0,0 +1 @@
uid://dli2i6albvugt

34
scripts/plants/Shooter.cs Normal file
View file

@ -0,0 +1,34 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.Plants;
// Shoot component of some plants
public partial class Shooter : Node2D
{
[Export] protected PackedScene _projectile;
[Export] protected Timer _timer;
protected RuntimePlantData _plantData;
public override void _Ready()
{
_plantData = GetParent<RuntimePlantData>();
}
public void Shoot()
{
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;
}
}

View file

@ -0,0 +1 @@
uid://ceprqkraw3v6m

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 (GetParent<Node2D>().GlobalPosition.Y+i*Utility.TileHeight >= Utility.RightFieldBoundary.Y || GetParent<Node2D>().GlobalPosition.Y+i*Utility.TileHeight <= Utility.LeftFieldBoundary.Y)
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

@ -0,0 +1 @@
uid://djpc0kvagpadv

View file

@ -0,0 +1,47 @@
using Godot;
using Newlon.Components.Level;
namespace Newlon.Components.Plants.Behaviours;
public partial class AloeBehaviour : BaseBehaviour
{
[Export] private float _hpTreshold = 0.25f;
private Timer _timer;
private bool _charge = true;
public override void _Ready()
{
base._Ready();
_timer = GetNode<Timer>("Timer");
}
public override void _Process(double delta)
{
_tree.Set("parameters/Tree/conditions/charged",_charge);
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
if(_charge && PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
{
if((float)plantData.HP / (float)plantData.MaxHP < _hpTreshold)
{
_charge = false;
_tree.Set("parameters/Tree/conditions/heal",true);
_timer.Start();
}
}
}
public void Heal()
{
var checkPos = GetParent<Node2D>().GlobalPosition + Vector2.Right * Utility.TileWidth;
if (PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
{
plantData.Heal(3000 + 25 * plantData.MaxHP, GetParent());
}
}
public void OnTimeout()
{
_charge = true;
}
}

View file

@ -0,0 +1 @@
uid://cljytsmqac0w7

View file

@ -0,0 +1,12 @@
using Godot;
namespace Newlon.Components;
public abstract partial class BaseBehaviour : Node
{
protected AnimationTree _tree;
public override void _Ready()
{
_tree = GetNode<AnimationTree>("../AnimationTree");
}
}

View file

@ -0,0 +1 @@
uid://3dbmgnr7qxee

View file

@ -0,0 +1,18 @@
using Godot;
namespace Newlon.Components.Plants.Behaviours;
public partial class HpBasedBehaviour : BaseBehaviour
{
private RuntimePlantData _data;
public override void _Ready()
{
base._Ready();
_data = GetParent<RuntimePlantData>();
}
public void OnHPChanged(int amount,Node origin)
{
_tree.Set("parameters/Tree/blend_position",(float)_data.HP/_data.MaxHP);
}
}

View file

@ -0,0 +1 @@
uid://btkmd86pn828y

View file

@ -0,0 +1,16 @@
using Godot;
namespace Newlon.Components.Plants.Behaviours;
public partial class PeashooterBehaviour : BaseBehaviour
{
[Export] private Timer _shootTimer;
[Export] private Eyesight _sight;
public override void _Process(double delta)
{
bool readyToShoot = _sight.EnemyDetected && _shootTimer.TimeLeft <= 0;
_tree.Set("parameters/Tree/conditions/ready",readyToShoot);
}
}

View file

@ -0,0 +1 @@
uid://bdk5iqtw4xbkl

View file

@ -0,0 +1,28 @@
using Godot;
namespace Newlon.Components.Plants.Behaviours;
public partial class PotatomineBehaviour : BaseBehaviour
{
[Export] private Area2D _hitbox;
[Export] private CollisionShape2D _unprimedShape;
[Export] private CollisionShape2D _primedShape;
private bool _primed = false;
public void Prime()
{
_tree.Set("parameters/Tree/conditions/primed",true);
_hitbox.Monitorable = false;
_primed = true;
_unprimedShape.Disabled = true;
_primedShape.Disabled = false;
}
public void OnAreaEntered(Area2D area)
{
if (_primed == false) return;
_tree.Set("parameters/Tree/conditions/explode",true);
_primed = false;
}
}

View file

@ -0,0 +1 @@
uid://c7qfh4py0uulo

View file

@ -0,0 +1,19 @@
using Godot;
namespace Newlon.Components.Plants.Behaviours;
public partial class SpikeweedBehaviour : BaseBehaviour
{
private int _inCount = 0;
public void OnHitboxEntered(Area2D _area)
{
if (_inCount++ == 0)
_tree.Set("parameters/Tree/blend_position",1);
}
public void OnHitboxExited(Area2D _area)
{
if (--_inCount == 0)
_tree.Set("parameters/Tree/blend_position",0);
}
}

View file

@ -0,0 +1 @@
uid://dqquodxaijmem

View file

@ -0,0 +1,12 @@
using Godot;
namespace Newlon.Components.Plants.Behaviours;
public partial class SunflowerBehaviour : BaseBehaviour
{
public void Timeout()
{
_tree.Set("parameters/Tree/conditions/produce", true);
}
}

View file

@ -0,0 +1 @@
uid://bth7gah4tn7uj