filesystem rework
This commit is contained in:
parent
64323290cc
commit
2905db3dce
174 changed files with 93 additions and 353 deletions
18
scripts/entities/plants/AreaAttack.cs
Normal file
18
scripts/entities/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/entities/plants/AreaAttack.cs.uid
Normal file
1
scripts/entities/plants/AreaAttack.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://co7ttejdo2qot
|
||||
26
scripts/entities/plants/ExplosionComponent.cs
Normal file
26
scripts/entities/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/entities/plants/ExplosionComponent.cs.uid
Normal file
1
scripts/entities/plants/ExplosionComponent.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bhl6o2m3fn4xg
|
||||
44
scripts/entities/plants/Eyesight.cs
Normal file
44
scripts/entities/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/entities/plants/Eyesight.cs.uid
Normal file
1
scripts/entities/plants/Eyesight.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dn53jvpjyg63l
|
||||
18
scripts/entities/plants/LoseZone.cs
Normal file
18
scripts/entities/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/entities/plants/LoseZone.cs.uid
Normal file
1
scripts/entities/plants/LoseZone.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c0ov2bq5er0gh
|
||||
48
scripts/entities/plants/NerdusReturnAttack.cs
Normal file
48
scripts/entities/plants/NerdusReturnAttack.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Godot;
|
||||
using Newlon.Systems.Effects;
|
||||
using System.Collections.Generic;
|
||||
namespace Newlon.Components.Plants;
|
||||
|
||||
public partial class NerdusReturnAttack : Area2D
|
||||
{
|
||||
private float returnAmount;
|
||||
[Export] private Effect returnEffect;
|
||||
[Export] private float bitesToPeas = 1;
|
||||
public bool triggered = false;
|
||||
private List<Entity> entities = new();
|
||||
public override void _Ready()
|
||||
{
|
||||
AreaEntered += OnAreaEntered;
|
||||
AreaExited += OnAreaExited;
|
||||
}
|
||||
private void OnAreaEntered(Area2D area)
|
||||
{
|
||||
if (area.GetParent() is Entity entity)
|
||||
{
|
||||
entities.Add(entity);
|
||||
}
|
||||
}
|
||||
private void OnAreaExited(Area2D area)
|
||||
{
|
||||
if (area.GetParent() is Entity entity && entities.Contains(entity))
|
||||
{
|
||||
entities.Remove(entity);
|
||||
}
|
||||
}
|
||||
private void OnHPChanged(float delta, Node source)
|
||||
{
|
||||
if (delta >= 0) return;
|
||||
returnAmount -= delta;
|
||||
triggered = true;
|
||||
}
|
||||
public void ReturnAllDamage()
|
||||
{
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
entity.TakeDamage(returnAmount * bitesToPeas, GetParent<Entity>());
|
||||
entity.GiveEffect(returnEffect);
|
||||
}
|
||||
returnAmount = 0;
|
||||
triggered = false;
|
||||
}
|
||||
}
|
||||
1
scripts/entities/plants/NerdusReturnAttack.cs.uid
Normal file
1
scripts/entities/plants/NerdusReturnAttack.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dcokqes5wwo3k
|
||||
14
scripts/entities/plants/PlantEyesightLimiter.cs
Normal file
14
scripts/entities/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(FieldParams.RightFieldBoundary.X - GlobalPosition.X+FieldParams.TileWidth/2.0f, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/entities/plants/PlantEyesightLimiter.cs.uid
Normal file
1
scripts/entities/plants/PlantEyesightLimiter.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://hccb0aee0x0o
|
||||
21
scripts/entities/plants/PlantSunSpawner.cs
Normal file
21
scripts/entities/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/entities/plants/PlantSunSpawner.cs.uid
Normal file
1
scripts/entities/plants/PlantSunSpawner.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b71gebny84s81
|
||||
20
scripts/entities/plants/ReturnEffect.cs
Normal file
20
scripts/entities/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/entities/plants/ReturnEffect.cs.uid
Normal file
1
scripts/entities/plants/ReturnEffect.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bmtukcq10m8wo
|
||||
27
scripts/entities/plants/RuntimePlantData.cs
Normal file
27
scripts/entities/plants/RuntimePlantData.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using Godot;
|
||||
using Newlon.Components.Level;
|
||||
|
||||
namespace Newlon.Components.Plants;
|
||||
|
||||
//
|
||||
// Data that plant stores during runtime
|
||||
//
|
||||
|
||||
public partial class RuntimePlantData : Entity
|
||||
{
|
||||
[Export]
|
||||
public string internal_id;
|
||||
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/entities/plants/RuntimePlantData.cs.uid
Normal file
1
scripts/entities/plants/RuntimePlantData.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dli2i6albvugt
|
||||
34
scripts/entities/plants/Shooter.cs
Normal file
34
scripts/entities/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/entities/plants/Shooter.cs.uid
Normal file
1
scripts/entities/plants/Shooter.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ceprqkraw3v6m
|
||||
26
scripts/entities/plants/ThreepeaterShooter.cs
Normal file
26
scripts/entities/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*FieldParams.TileHeight >= FieldParams.RightFieldBoundary.Y || GetParent<Node2D>().GlobalPosition.Y+i*FieldParams.TileHeight <= FieldParams.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*FieldParams.TileHeight,0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
scripts/entities/plants/ThreepeaterShooter.cs.uid
Normal file
1
scripts/entities/plants/ThreepeaterShooter.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://djpc0kvagpadv
|
||||
47
scripts/entities/plants/behaviours/AloeBehaviour.cs
Normal file
47
scripts/entities/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 * FieldParams.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 * FieldParams.TileWidth;
|
||||
if (PoolContainer.Instance.TryGetEntity(checkPos, out RuntimePlantData plantData))
|
||||
{
|
||||
plantData.Heal(1200 + 0.5f * plantData.MaxHP, GetParent());
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTimeout()
|
||||
{
|
||||
_charge = true;
|
||||
}
|
||||
}
|
||||
1
scripts/entities/plants/behaviours/AloeBehaviour.cs.uid
Normal file
1
scripts/entities/plants/behaviours/AloeBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cljytsmqac0w7
|
||||
12
scripts/entities/plants/behaviours/BaseBehaviour.cs
Normal file
12
scripts/entities/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/entities/plants/behaviours/BaseBehaviour.cs.uid
Normal file
1
scripts/entities/plants/behaviours/BaseBehaviour.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://3dbmgnr7qxee
|
||||
25
scripts/entities/plants/behaviours/HpBasedBehaviour.cs
Normal file
25
scripts/entities/plants/behaviours/HpBasedBehaviour.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class HpBasedBehaviour : BaseBehaviour
|
||||
{
|
||||
private RuntimePlantData _data;
|
||||
[Export] private Array<string> parameters;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_data = GetParent<RuntimePlantData>();
|
||||
}
|
||||
|
||||
public void OnHPChanged(float amount, Node origin)
|
||||
{
|
||||
var calc = _data.HP / _data.MaxHP;
|
||||
foreach (var par in parameters)
|
||||
{
|
||||
_tree.Set(par, calc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://btkmd86pn828y
|
||||
16
scripts/entities/plants/behaviours/PeashooterBehaviour.cs
Normal file
16
scripts/entities/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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bdk5iqtw4xbkl
|
||||
38
scripts/entities/plants/behaviours/PotatomineBehaviour.cs
Normal file
38
scripts/entities/plants/behaviours/PotatomineBehaviour.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using Godot;
|
||||
|
||||
namespace Newlon.Components.Plants.Behaviours;
|
||||
|
||||
public partial class PotatomineBehaviour : BaseBehaviour
|
||||
{
|
||||
[Export] private Area2D _hitbox;
|
||||
[Export] private Area2D detectionBox;
|
||||
[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;
|
||||
|
||||
if (detectionBox.HasOverlappingAreas())
|
||||
{
|
||||
SetupExplosion();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAreaEntered(Area2D area)
|
||||
{
|
||||
if (_primed == false) return;
|
||||
SetupExplosion();
|
||||
}
|
||||
private void SetupExplosion()
|
||||
{
|
||||
_tree.Set("parameters/Tree/conditions/explode", true);
|
||||
_primed = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://c7qfh4py0uulo
|
||||
19
scripts/entities/plants/behaviours/SpikeweedBehaviour.cs
Normal file
19
scripts/entities/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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dqquodxaijmem
|
||||
12
scripts/entities/plants/behaviours/SunflowerBehaviour.cs
Normal file
12
scripts/entities/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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bth7gah4tn7uj
|
||||
Loading…
Add table
Add a link
Reference in a new issue