Initial commit
This commit is contained in:
commit
c266d22f58
85 changed files with 1649 additions and 0 deletions
18
scripts/Cursor.cs
Normal file
18
scripts/Cursor.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Cursor : Node
|
||||
{
|
||||
public static Cursor Instance { get; private set; }
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
SetDefaultCursorSet();
|
||||
}
|
||||
|
||||
public void SetDefaultCursorSet()
|
||||
{
|
||||
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/default_arrow.png"));
|
||||
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/default_point.png"),shape:Input.CursorShape.PointingHand);
|
||||
}
|
||||
}
|
||||
12
scripts/LevelButton.cs
Normal file
12
scripts/LevelButton.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
//
|
||||
// Button that contains level to load
|
||||
//
|
||||
|
||||
public partial class LevelButton : Node
|
||||
{
|
||||
[Export] private Script _levelScript;
|
||||
[Export] private PackedScene _levelTileset;
|
||||
}
|
||||
50
scripts/LevelController.cs
Normal file
50
scripts/LevelController.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
//
|
||||
// Class that gives access to level data, pools and etc.
|
||||
//
|
||||
|
||||
public partial class LevelController : Node
|
||||
{
|
||||
public static LevelController Instance { get; private set; }
|
||||
|
||||
private bool _isLevelRunning = false;
|
||||
|
||||
public RuntimeLevelData LevelData { get; set; }
|
||||
public PoolContainer Pools { get; set; }
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
public void StartLevel(PackedScene levelTileset, Script levelScript = null)
|
||||
{
|
||||
if (_isLevelRunning)
|
||||
return;
|
||||
|
||||
GetTree().ChangeSceneToPacked(levelTileset);
|
||||
|
||||
if (levelScript != null)
|
||||
GetTree().CurrentScene.SetScript(levelScript);
|
||||
|
||||
_isLevelRunning = true;
|
||||
}
|
||||
|
||||
public void EndLevel()
|
||||
{
|
||||
if (_isLevelRunning == false)
|
||||
return;
|
||||
|
||||
LevelData = null;
|
||||
Pools = null;
|
||||
|
||||
_isLevelRunning = false;
|
||||
}
|
||||
}
|
||||
31
scripts/LinearProjectile.cs
Normal file
31
scripts/LinearProjectile.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
//
|
||||
// Projectile that travels from left to right
|
||||
//
|
||||
|
||||
public partial class LinearProjectile : Area2D, IProjectile
|
||||
{
|
||||
[Export(hintString: "suffix:tile/sec")]
|
||||
private float _speed;
|
||||
[Export]
|
||||
private int _damage;
|
||||
private int _line;
|
||||
public int Line { get => _line; set { _line = value; } }
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Translate(Vector2.Right * _speed * (float)delta * Utility.TileWidth);
|
||||
}
|
||||
|
||||
public void OnAreaEntered(Area2D area)
|
||||
{
|
||||
var entity = area.GetParent<IEntity>();
|
||||
if (entity != null && entity.Line == _line)
|
||||
{
|
||||
entity.TakeDamage(_damage);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
scripts/Utility.cs
Normal file
14
scripts/Utility.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
//
|
||||
// Class for general-used constants and utility tools
|
||||
//
|
||||
|
||||
public partial class Utility
|
||||
{
|
||||
public const int TileWidth = 50;
|
||||
public const int TileHeight = 60;
|
||||
public static readonly Vector2I LeftFieldBoundary = new Vector2I(305,76);
|
||||
public static readonly Vector2I RightFieldBoundary = new Vector2I(755,376);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
scripts/debug/Cheats.cs
Normal file
13
scripts/debug/Cheats.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Cheats : Node
|
||||
{
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("cheat_add_sun"))
|
||||
{
|
||||
LevelController.Instance.LevelData.AddSun(50);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
scripts/debug/Clock.cs
Normal file
18
scripts/debug/Clock.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
//
|
||||
// Debug tool to check time since clock loaded
|
||||
//
|
||||
|
||||
public partial class Clock : Label
|
||||
{
|
||||
private ulong _time = 0;
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_time += (ulong)(delta*1000);
|
||||
ulong seconds = _time / 1000 % 60;
|
||||
ulong minutes = seconds / 60 % 60;
|
||||
Text = minutes.ToString()+":"+seconds.ToString();
|
||||
}
|
||||
}
|
||||
17
scripts/resources/PlantResource.cs
Normal file
17
scripts/resources/PlantResource.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class PlantResource : Resource
|
||||
{
|
||||
[Export]
|
||||
public int Cost;
|
||||
[Export]
|
||||
public PackedScene Scene;
|
||||
[Export]
|
||||
public float ReloadTime;
|
||||
[Export]
|
||||
public float StartReloadTime;
|
||||
[Export]
|
||||
public Texture Preview;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue