Initial commit
This commit is contained in:
commit
c266d22f58
85 changed files with 1649 additions and 0 deletions
11
scripts/components/IEntity.cs
Normal file
11
scripts/components/IEntity.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
//
|
||||
// Base interface for entities
|
||||
//
|
||||
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);
|
||||
}
|
||||
7
scripts/components/IProjectile.cs
Normal file
7
scripts/components/IProjectile.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
//
|
||||
// Base interface for entities
|
||||
//
|
||||
public interface IProjectile
|
||||
{
|
||||
public int Line { get; set; }
|
||||
}
|
||||
10
scripts/components/gui/SunCounter.cs
Normal file
10
scripts/components/gui/SunCounter.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class SunCounter : Label
|
||||
{
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
Text = LevelController.Instance.LevelData.SunCount.ToString();
|
||||
}
|
||||
}
|
||||
24
scripts/components/level/PoolContainer.cs
Normal file
24
scripts/components/level/PoolContainer.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
//
|
||||
// PoolContainer contains nodes that contain different elemnts that generate during runtime
|
||||
// Is not pool in traditional sense, but named like that to prevent repetition
|
||||
//
|
||||
|
||||
public partial class PoolContainer : Node
|
||||
{
|
||||
[Export]
|
||||
public Node Zombies { get; private set; }
|
||||
[Export]
|
||||
public Node Plants { get; private set; }
|
||||
[Export]
|
||||
public Node Projectiles { get; private set; }
|
||||
[Export]
|
||||
public Node Structures { get; private set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
LevelController.Instance.Pools = this;
|
||||
}
|
||||
}
|
||||
33
scripts/components/level/RuntimeLevelData.cs
Normal file
33
scripts/components/level/RuntimeLevelData.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Godot;
|
||||
//using Godot.Collections;
|
||||
using System;
|
||||
|
||||
public partial class RuntimeLevelData : Node
|
||||
{
|
||||
public int SunCount { get; private set; } = 0;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
LevelController.Instance.LevelData = this;
|
||||
}
|
||||
|
||||
public void AddSun(int amount)
|
||||
{
|
||||
SunCount += amount;
|
||||
}
|
||||
|
||||
public bool TrySpendSun(int amount)
|
||||
{
|
||||
if (SunCount - amount < 0) return false;
|
||||
|
||||
SunCount -= amount;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//private Array<PlantResource> _selectedPlants;
|
||||
//private bool _selected;
|
||||
//public Array<PlantResource> GetSelectedPlants();
|
||||
//public bool TrySelectPlants(Array<PlantResource>);
|
||||
//public void ResetSelection();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
41
scripts/components/zombies/RuntimeZombieData.cs
Normal file
41
scripts/components/zombies/RuntimeZombieData.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class RuntimeZombieData : Node2D, IEntity
|
||||
{
|
||||
private int _hp;
|
||||
[Export]
|
||||
private int _maxHP;
|
||||
[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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue