diff --git a/resources/effects/SnowSlow.tres b/resources/effects/SnowSlow.tres index 5c422ac..59111f0 100644 --- a/resources/effects/SnowSlow.tres +++ b/resources/effects/SnowSlow.tres @@ -5,5 +5,6 @@ [resource] script = ExtResource("1_8md01") ColorOverride = Color(0, 1, 1, 1) -Duration = 10.0 Multiplier = 0.75 +Duration = 3.25 +Slot = 2 diff --git a/scenes/entities/plants/peashooter.tscn b/scenes/entities/plants/peashooter.tscn index 1c931a2..6b860c7 100644 --- a/scenes/entities/plants/peashooter.tscn +++ b/scenes/entities/plants/peashooter.tscn @@ -15,6 +15,7 @@ size = Vector2(20, 44) [sub_resource type="SegmentShape2D" id="SegmentShape2D_8iovl"] [node name="Peashooter" instance=ExtResource("1_pyk3o")] +_maxHP = 100 [node name="Sprite2D" parent="." index="0"] texture = ExtResource("2_14qlx") @@ -58,14 +59,4 @@ script = ExtResource("7_2bki8") shape = SubResource("SegmentShape2D_8iovl") script = ExtResource("8_nl4jc") -[node name="CollisionShape2D2" type="CollisionShape2D" parent="Eysight" index="1"] -position = Vector2(0, 60) -shape = SubResource("SegmentShape2D_8iovl") -script = ExtResource("8_nl4jc") - -[node name="CollisionShape2D3" type="CollisionShape2D" parent="Eysight" index="2"] -position = Vector2(0, -60) -shape = SubResource("SegmentShape2D_8iovl") -script = ExtResource("8_nl4jc") - [node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="." index="6"] diff --git a/scenes/entities/plants/threepeater.tscn b/scenes/entities/plants/threepeater.tscn index dacaac1..cf08fe9 100644 --- a/scenes/entities/plants/threepeater.tscn +++ b/scenes/entities/plants/threepeater.tscn @@ -1,9 +1,22 @@ -[gd_scene load_steps=3 format=3 uid="uid://eegv1qihfv2q"] +[gd_scene load_steps=5 format=3 uid="uid://eegv1qihfv2q"] [ext_resource type="PackedScene" uid="uid://dy41q1kxray5t" path="res://scenes/entities/plants/peashooter.tscn" id="1_muntu"] [ext_resource type="Script" path="res://scripts/components/plants/ThreepeaterShooter.cs" id="2_ieami"] +[ext_resource type="Script" path="res://scripts/components/plants/PlantEyesightLimiter.cs" id="3_dqn6w"] + +[sub_resource type="SegmentShape2D" id="SegmentShape2D_yb26d"] [node name="Threepeater" instance=ExtResource("1_muntu")] [node name="Shooter" parent="." index="3"] script = ExtResource("2_ieami") + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="Eysight" index="1"] +position = Vector2(0, 60) +shape = SubResource("SegmentShape2D_yb26d") +script = ExtResource("3_dqn6w") + +[node name="CollisionShape2D3" type="CollisionShape2D" parent="Eysight" index="2"] +position = Vector2(0, -60) +shape = SubResource("SegmentShape2D_yb26d") +script = ExtResource("3_dqn6w") diff --git a/scenes/projectiles/snowpea_projectile.tscn b/scenes/projectiles/snowpea_projectile.tscn index 1531a2a..bd0187a 100644 --- a/scenes/projectiles/snowpea_projectile.tscn +++ b/scenes/projectiles/snowpea_projectile.tscn @@ -14,6 +14,7 @@ script = ExtResource("1_fkydi") _speed = 3.0 _damage = 10 _impactEffect = ExtResource("2_txupr") +_damageType = 1 [node name="Sprite" type="Sprite2D" parent="."] texture = ExtResource("2_xt8td") diff --git a/scripts/Utility.cs b/scripts/Utility.cs index 2d8b2fa..ba2e1d2 100644 --- a/scripts/Utility.cs +++ b/scripts/Utility.cs @@ -14,7 +14,9 @@ public class Utility // #region Enums - public enum EffectSlots {FREEZE, STUN, POISON}; + public enum EffectSlots {FREEZE, STUN, POISON, BEBRA}; + + public enum DamageTypes {PHYSICAL, ICE}; #endregion diff --git a/scripts/components/FlashComponent.cs b/scripts/components/FlashComponent.cs index 65eb6eb..4917fe0 100644 --- a/scripts/components/FlashComponent.cs +++ b/scripts/components/FlashComponent.cs @@ -14,7 +14,7 @@ public partial class FlashComponent : CanvasGroup _shaderMaterial = Material as ShaderMaterial; } - public void DamageFlash(int damage) + public void DamageFlash(int damage,Node origin) { Flash(); } diff --git a/scripts/components/IEntity.cs b/scripts/components/IEntity.cs index c49722f..3a6368e 100644 --- a/scripts/components/IEntity.cs +++ b/scripts/components/IEntity.cs @@ -1,3 +1,5 @@ +using Godot; + namespace Newlon.Components; // @@ -7,6 +9,7 @@ public interface IEntity { public int Hp { get; } public int MaxHp { get; } - public void TakeDamage(int amount); - public void Heal(int amount); + public void TakeDamage(int amount,Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL); + public void Heal(int amount, Node origin); } + \ No newline at end of file diff --git a/scripts/components/LinearProjectile.cs b/scripts/components/LinearProjectile.cs index 017a64f..d2ec06a 100644 --- a/scripts/components/LinearProjectile.cs +++ b/scripts/components/LinearProjectile.cs @@ -15,8 +15,12 @@ public partial class LinearProjectile : Area2D, IProjectile private int _damage; [Export] private Effect _impactEffect; + [Export] + private Utility.DamageTypes _damageType = Utility.DamageTypes.PHYSICAL; private int _line; + private bool used = false; public int Line { get => _line; set { _line = value; } } + public override void _PhysicsProcess(double delta) { @@ -25,10 +29,12 @@ public partial class LinearProjectile : Area2D, IProjectile public void OnAreaEntered(Area2D area) { + if (used == true) return; var entity = area.GetParent(); if (entity != null) { - entity.TakeDamage(_damage); + entity.TakeDamage(_damage,this,_damageType); + used = true; if (entity is IEffectHandler effectHandler && _impactEffect != null) effectHandler.GiveEffect(_impactEffect); QueueFree(); diff --git a/scripts/components/plants/AreaAttack.cs b/scripts/components/plants/AreaAttack.cs index abe660d..2def47d 100644 --- a/scripts/components/plants/AreaAttack.cs +++ b/scripts/components/plants/AreaAttack.cs @@ -12,7 +12,7 @@ public partial class AreaAttack : Area2D foreach (var zombie in GetOverlappingAreas()) { var zombieData = zombie.GetParent(); - zombieData?.TakeDamage(_damage); + zombieData?.TakeDamage(_damage,GetParent()); } } } diff --git a/scripts/components/plants/ExplosionComponent.cs b/scripts/components/plants/ExplosionComponent.cs index d0fccd1..01797b3 100644 --- a/scripts/components/plants/ExplosionComponent.cs +++ b/scripts/components/plants/ExplosionComponent.cs @@ -12,7 +12,7 @@ public partial class ExplosionComponent : Area2D foreach(var zombie in GetOverlappingAreas()) { var zombieData = zombie.GetParent(); - zombieData?.TakeDamage(damage); + zombieData?.TakeDamage(damage,GetParent()); } GetParent().Kill(); diff --git a/scripts/components/plants/RuntimePlantData.cs b/scripts/components/plants/RuntimePlantData.cs index 134fc8b..d2174c7 100644 --- a/scripts/components/plants/RuntimePlantData.cs +++ b/scripts/components/plants/RuntimePlantData.cs @@ -18,18 +18,18 @@ public partial class RuntimePlantData : Node2D, IEntity public PlantResource Resource; [Signal] - public delegate void OnHPChangedEventHandler(int amount); + public delegate void OnHPChangedEventHandler(int amount,Node origin); public override void _Ready() { _hp = _maxHP; } - public void Heal(int amount) + public void Heal(int amount,Node origin) { _hp += amount; - EmitSignal(SignalName.OnHPChanged,amount); + EmitSignal(SignalName.OnHPChanged,amount,origin); if (MaxHp > 0) { @@ -37,11 +37,11 @@ public partial class RuntimePlantData : Node2D, IEntity } } - public void TakeDamage(int amount) + public void TakeDamage(int amount,Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL) { _hp -= amount; - EmitSignal(SignalName.OnHPChanged,-amount); + EmitSignal(SignalName.OnHPChanged,-amount, origin); if (_hp <= 0) { diff --git a/scripts/components/plants/behaviours/AloeBehaviour.cs b/scripts/components/plants/behaviours/AloeBehaviour.cs index f6f9ff5..e36f959 100644 --- a/scripts/components/plants/behaviours/AloeBehaviour.cs +++ b/scripts/components/plants/behaviours/AloeBehaviour.cs @@ -24,7 +24,7 @@ public partial class AloeBehaviour : Node { if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold) { - plantData.Heal(3000 + 25 * plantData.MaxHp); + plantData.Heal(3000 + 25 * plantData.MaxHp,GetParent()); _charge = false; _player.Play("aloe/heal"); _player.Queue("aloe/idle_used"); diff --git a/scripts/components/zombies/AudioDamage.cs b/scripts/components/zombies/AudioDamage.cs index 2152342..5c9bac3 100644 --- a/scripts/components/zombies/AudioDamage.cs +++ b/scripts/components/zombies/AudioDamage.cs @@ -4,7 +4,7 @@ namespace Newlon.Components.Zombies; public partial class AudioDamage : AudioStreamPlayer2D { - public void OnDamaged(int amount) + public void OnDamaged(int amount, Node origin) { Play(); } diff --git a/scripts/components/zombies/EatBox.cs b/scripts/components/zombies/EatBox.cs index 9091843..79b2604 100644 --- a/scripts/components/zombies/EatBox.cs +++ b/scripts/components/zombies/EatBox.cs @@ -15,7 +15,7 @@ public partial class EatBox : Area2D public void Bite() { - plant.TakeDamage(_damage); + plant?.TakeDamage(_damage,GetParent()); } public void OnAreaEntered(Area2D area) diff --git a/scripts/components/zombies/RuntimeZombieData.cs b/scripts/components/zombies/RuntimeZombieData.cs index 5d55d5a..d4da31d 100644 --- a/scripts/components/zombies/RuntimeZombieData.cs +++ b/scripts/components/zombies/RuntimeZombieData.cs @@ -7,7 +7,7 @@ namespace Newlon.Components.Zombies; public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffectHandler { [Signal] - public delegate void OnHPChangedEventHandler(int deltaHP); + public delegate void OnHPChangedEventHandler(int deltaHP, Node origin); [Signal] public delegate void OnLocalTimescaleChangedEventHandler(int currentTimescale); @@ -45,14 +45,15 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe var timer = new Timer() {Autostart = false, OneShot = true}; _effectSlotTimers[i] = timer; AddChild(timer); - timer.Timeout += () => {EndEffectAtSlot(i);}; + int current_index = i; + timer.Timeout += () => {EndEffectAtSlot(current_index);}; } } - public void Heal(int amount) + public void Heal(int amount,Node origin) { _hp += amount; - EmitSignal(SignalName.OnHPChanged,amount); + EmitSignal(SignalName.OnHPChanged,amount,origin); if (MaxHp > 0) { @@ -60,10 +61,10 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe } } - public void TakeDamage(int amount) + public void TakeDamage(int amount, Node origin, Utility.DamageTypes damageType = Utility.DamageTypes.PHYSICAL) { _hp -= amount; - EmitSignal(SignalName.OnHPChanged,-amount); + EmitSignal(SignalName.OnHPChanged,-amount, origin); if (_hp <= 0) { @@ -101,7 +102,7 @@ public partial class RuntimeZombieData : Node2D, IEntity, ILocalTimescale, IEffe public void ProcessEffects() { for(int i = 0; i < Utility.EffectSlotCount; i++) - _activeEffectSlots[i].Process(this); + _activeEffectSlots[i]?.Process(this); } private void EndEffectAtSlot(int slot)