Initial commit
This commit is contained in:
commit
c266d22f58
85 changed files with 1649 additions and 0 deletions
43
scripts/components/plants/Eyesight.cs
Normal file
43
scripts/components/plants/Eyesight.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class Eyesight : Area2D
|
||||
{
|
||||
private bool _enemyDetected;
|
||||
public bool EnemyDetected => _enemyDetected;
|
||||
private List<IEntity> _detectedEntities = new List<IEntity>();
|
||||
private RuntimePlantData _plantData;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_plantData = GetParent<RuntimePlantData>();
|
||||
}
|
||||
|
||||
public void OnAreaEntered(Area2D area)
|
||||
{
|
||||
var entity = area.GetParent<IEntity>();
|
||||
if (entity != null)
|
||||
{
|
||||
if (_plantData.Line == entity.Line)
|
||||
{
|
||||
_detectedEntities.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
_enemyDetected = _detectedEntities.Count > 0;
|
||||
}
|
||||
|
||||
public void OnAreaExited(Area2D area)
|
||||
{
|
||||
var entity = area.GetParent<IEntity>();
|
||||
if (entity != null)
|
||||
{
|
||||
if (_detectedEntities.Contains(entity))
|
||||
{
|
||||
_detectedEntities.Remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
_enemyDetected = _detectedEntities.Count > 0;
|
||||
}
|
||||
}
|
||||
13
scripts/components/plants/PlantEyesightLimiter.cs
Normal file
13
scripts/components/plants/PlantEyesightLimiter.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PlantEyesightLimiter : CollisionShape2D
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Shape is SegmentShape2D segment)
|
||||
{
|
||||
segment.B = new Vector2(Utility.RightFieldBoundary.X-GlobalPosition.X, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
scripts/components/plants/RuntimePlantData.cs
Normal file
43
scripts/components/plants/RuntimePlantData.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
//
|
||||
// Data that plant stores during runtime
|
||||
//
|
||||
|
||||
public partial class RuntimePlantData : Node2D, IEntity
|
||||
{
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
private int _hp;
|
||||
[Export]
|
||||
private int _line;
|
||||
public int Hp => _hp;
|
||||
public int MaxHp => _maxHP;
|
||||
public int Line => _line;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_hp = _maxHP;
|
||||
}
|
||||
|
||||
public void Heal(int amount)
|
||||
{
|
||||
_hp += amount;
|
||||
|
||||
if (MaxHp > 0)
|
||||
{
|
||||
_hp = MaxHp;
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(int amount)
|
||||
{
|
||||
_hp -= amount;
|
||||
|
||||
if (_hp <= 0)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
31
scripts/components/plants/Shooter.cs
Normal file
31
scripts/components/plants/Shooter.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Godot;
|
||||
|
||||
// Shoot component of some plants
|
||||
public partial class Shooter : Node2D
|
||||
{
|
||||
[Export] private PackedScene _projectile;
|
||||
[Export] private Timer _timer;
|
||||
|
||||
private RuntimePlantData _plantData;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_plantData = GetParent<RuntimePlantData>();
|
||||
}
|
||||
|
||||
|
||||
public void Shoot()
|
||||
{
|
||||
if (_timer.TimeLeft > 0) return;
|
||||
|
||||
_timer.Start();
|
||||
var instance = _projectile.Instantiate<Node2D>();
|
||||
LevelController.Instance.Pools.Projectiles.AddChild(instance);
|
||||
instance.GlobalTransform = GlobalTransform;
|
||||
|
||||
if (instance is IProjectile projectile)
|
||||
{
|
||||
projectile.Line = _plantData.Line;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
scripts/components/plants/behaviours/PeashooterBehaviour.cs
Normal file
16
scripts/components/plants/behaviours/PeashooterBehaviour.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class PeashooterBehaviour : Node
|
||||
{
|
||||
[Export] private AnimationTree _animationTree;
|
||||
[Export] private Timer _shootTimer;
|
||||
[Export] private Eyesight _sight;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
bool readyToShoot = _sight.EnemyDetected && _shootTimer.TimeLeft <= 0;
|
||||
|
||||
_animationTree.Set("parameters/conditions/ready", readyToShoot);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue