file refactor
This commit is contained in:
parent
da5a3e874b
commit
bffb012a26
175 changed files with 1086 additions and 1107 deletions
18
scripts/plants/AreaAttack.cs
Normal file
18
scripts/plants/AreaAttack.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/plants/AreaAttack.cs.uid
Normal file
1
scripts/plants/AreaAttack.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://co7ttejdo2qot
|
||||
26
scripts/plants/ExplosionComponent.cs
Normal file
26
scripts/plants/ExplosionComponent.cs
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
1
scripts/plants/ExplosionComponent.cs.uid
Normal file
1
scripts/plants/ExplosionComponent.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bhl6o2m3fn4xg
|
||||
44
scripts/plants/Eyesight.cs
Normal file
44
scripts/plants/Eyesight.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
scripts/plants/Eyesight.cs.uid
Normal file
1
scripts/plants/Eyesight.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dn53jvpjyg63l
|
||||
18
scripts/plants/LoseZone.cs
Normal file
18
scripts/plants/LoseZone.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/plants/LoseZone.cs.uid
Normal file
1
scripts/plants/LoseZone.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c0ov2bq5er0gh
|
||||
14
scripts/plants/PlantEyesightLimiter.cs
Normal file
14
scripts/plants/PlantEyesightLimiter.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/plants/PlantEyesightLimiter.cs.uid
Normal file
1
scripts/plants/PlantEyesightLimiter.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://hccb0aee0x0o
|
||||
21
scripts/plants/PlantSunSpawner.cs
Normal file
21
scripts/plants/PlantSunSpawner.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
scripts/plants/PlantSunSpawner.cs.uid
Normal file
1
scripts/plants/PlantSunSpawner.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b71gebny84s81
|
||||
20
scripts/plants/ReturnEffect.cs
Normal file
20
scripts/plants/ReturnEffect.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/plants/ReturnEffect.cs.uid
Normal file
1
scripts/plants/ReturnEffect.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bmtukcq10m8wo
|
||||
25
scripts/plants/RuntimePlantData.cs
Normal file
25
scripts/plants/RuntimePlantData.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
1
scripts/plants/RuntimePlantData.cs.uid
Normal file
1
scripts/plants/RuntimePlantData.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dli2i6albvugt
|
||||
34
scripts/plants/Shooter.cs
Normal file
34
scripts/plants/Shooter.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
scripts/plants/Shooter.cs.uid
Normal file
1
scripts/plants/Shooter.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ceprqkraw3v6m
|
||||
26
scripts/plants/ThreepeaterShooter.cs
Normal file
26
scripts/plants/ThreepeaterShooter.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/plants/ThreepeaterShooter.cs.uid
Normal file
1
scripts/plants/ThreepeaterShooter.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://djpc0kvagpadv
|
||||
47
scripts/plants/behaviours/AloeBehaviour.cs
Normal file
47
scripts/plants/behaviours/AloeBehaviour.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/AloeBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/AloeBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cljytsmqac0w7
|
||||
12
scripts/plants/behaviours/BaseBehaviour.cs
Normal file
12
scripts/plants/behaviours/BaseBehaviour.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/BaseBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/BaseBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://3dbmgnr7qxee
|
||||
18
scripts/plants/behaviours/HpBasedBehaviour.cs
Normal file
18
scripts/plants/behaviours/HpBasedBehaviour.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/HpBasedBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/HpBasedBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://btkmd86pn828y
|
||||
16
scripts/plants/behaviours/PeashooterBehaviour.cs
Normal file
16
scripts/plants/behaviours/PeashooterBehaviour.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/PeashooterBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/PeashooterBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bdk5iqtw4xbkl
|
||||
28
scripts/plants/behaviours/PotatomineBehaviour.cs
Normal file
28
scripts/plants/behaviours/PotatomineBehaviour.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/PotatomineBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/PotatomineBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c7qfh4py0uulo
|
||||
19
scripts/plants/behaviours/SpikeweedBehaviour.cs
Normal file
19
scripts/plants/behaviours/SpikeweedBehaviour.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
1
scripts/plants/behaviours/SpikeweedBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/SpikeweedBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dqquodxaijmem
|
||||
12
scripts/plants/behaviours/SunflowerBehaviour.cs
Normal file
12
scripts/plants/behaviours/SunflowerBehaviour.cs
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
1
scripts/plants/behaviours/SunflowerBehaviour.cs.uid
Normal file
1
scripts/plants/behaviours/SunflowerBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bth7gah4tn7uj
|
||||
Loading…
Add table
Add a link
Reference in a new issue