diff --git a/scenes/entities/Zombies/zombie.tscn b/scenes/entities/Zombies/zombie.tscn index a4db44c..47f2b94 100644 --- a/scenes/entities/Zombies/zombie.tscn +++ b/scenes/entities/Zombies/zombie.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=29 format=3 uid="uid://co11v3w8hbwgf"] +[gd_scene load_steps=30 format=3 uid="uid://co11v3w8hbwgf"] [ext_resource type="Script" uid="uid://dildme6epx8l4" path="res://scripts/components/zombies/RuntimeZombieData.cs" id="1_qq3f1"] [ext_resource type="Texture2D" uid="uid://bwdqbrnn7ygtr" path="res://assets/sprites/atlases/zombies/Зондби.png" id="2_4pdxh"] @@ -12,6 +12,7 @@ [ext_resource type="Script" uid="uid://c3cfnrmnnuqms" path="res://addons/floatmodifiers/FloatModifiers.cs" id="7_b3p4o"] [ext_resource type="AnimationNodeStateMachine" uid="uid://dj0blope85bg7" path="res://resources/animations/zombies/basic_zombie_tree.tres" id="8_ckb7n"] [ext_resource type="Script" uid="uid://c36bj8u7jghc7" path="res://scripts/audio/ChannelPlayer.cs" id="10_ruqsf"] +[ext_resource type="Script" uid="uid://dwlwi42smgxkb" path="res://scripts/components/TimeScalableAnimationTree.cs" id="11_ccrjo"] [ext_resource type="AudioStream" uid="uid://dyid55nhflwyn" path="res://assets/audio/sfx/chomp_generic.tres" id="11_vjrlo"] [ext_resource type="AudioStream" uid="uid://bg76miyscfvhu" path="res://assets/audio/sfx/groan.tres" id="12_ad42i"] [ext_resource type="Script" uid="uid://cnn0ymuhypdff" path="res://scripts/audio/ChannelPlaylist.cs" id="12_he8da"] @@ -62,7 +63,6 @@ _data = { [sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_2q05d"] [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_ccrjo"] -graph_offset = Vector2(-447, 53) nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_2q05d") nodes/TimeScale/position = Vector2(60, 120) nodes/Tree/node = ExtResource("8_ckb7n") @@ -115,11 +115,13 @@ libraries = { &"basic_zombie": ExtResource("6_ckb7n") } -[node name="AnimationTree" type="AnimationTree" parent="."] +[node name="AnimationTree" type="AnimationTree" parent="." node_paths=PackedStringArray("entity")] tree_root = SubResource("AnimationNodeBlendTree_ccrjo") advance_expression_base_node = NodePath("../Eatbox") anim_player = NodePath("../AnimationPlayer") parameters/TimeScale/scale = 1.0 +script = ExtResource("11_ccrjo") +entity = NodePath("..") [node name="Mover" type="Node" parent="."] script = ExtResource("4_u5syx") diff --git a/scenes/entities/plants/aloe.tscn b/scenes/entities/plants/aloe.tscn index 9047d01..4aeb856 100644 --- a/scenes/entities/plants/aloe.tscn +++ b/scenes/entities/plants/aloe.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=20 format=3 uid="uid://bw1w8jp0yeypy"] +[gd_scene load_steps=21 format=3 uid="uid://bw1w8jp0yeypy"] [ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_n25yi"] [ext_resource type="Texture2D" uid="uid://b6tyoa5htapir" path="res://assets/sprites/atlases/plants/aloe.png" id="2_iup5p"] [ext_resource type="AnimationLibrary" uid="uid://bgutjc3ruq27s" path="res://resources/animations/plants/aloe.res" id="3_3sp3b"] [ext_resource type="Script" uid="uid://cljytsmqac0w7" path="res://scripts/components/plants/behaviours/AloeBehaviour.cs" id="4_55asm"] +[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="5_gfy6j"] [sub_resource type="Animation" id="Animation_vknky"] length = 0.001 @@ -118,9 +119,11 @@ parameters/Tree/conditions/heal = false script = ExtResource("4_55asm") _hpTreshold = 0.33 -[node name="Timer" type="Timer" parent="Behaviour" index="0"] +[node name="Timer" type="Timer" parent="Behaviour" index="0" node_paths=PackedStringArray("entity")] wait_time = 20.0 one_shot = true +script = ExtResource("5_gfy6j") +entity = NodePath("../..") [node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" index="0"] shape = SubResource("RectangleShape2D_oe0dc") diff --git a/scenes/entities/plants/peashooter.tscn b/scenes/entities/plants/peashooter.tscn index aee5b0e..853fb21 100644 --- a/scenes/entities/plants/peashooter.tscn +++ b/scenes/entities/plants/peashooter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=3 uid="uid://dy41q1kxray5t"] +[gd_scene load_steps=24 format=3 uid="uid://dy41q1kxray5t"] [ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_pyk3o"] [ext_resource type="Texture2D" uid="uid://cksryh4w5dbbx" path="res://assets/sprites/atlases/plants/peashooter.png" id="2_14qlx"] @@ -6,6 +6,7 @@ [ext_resource type="Script" uid="uid://ceprqkraw3v6m" path="res://scripts/components/plants/Shooter.cs" id="3_a4ew1"] [ext_resource type="PackedScene" uid="uid://b2hrv0aqbui7u" path="res://scenes/projectiles/pea.tscn" id="4_saxds"] [ext_resource type="Script" uid="uid://bdk5iqtw4xbkl" path="res://scripts/components/plants/behaviours/PeashooterBehaviour.cs" id="5_7qiua"] +[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="6_q58jr"] [ext_resource type="Script" uid="uid://dn53jvpjyg63l" path="res://scripts/components/plants/Eyesight.cs" id="7_2bki8"] [ext_resource type="Script" uid="uid://hccb0aee0x0o" path="res://scripts/components/plants/PlantEyesightLimiter.cs" id="8_nl4jc"] [ext_resource type="Script" uid="uid://c36bj8u7jghc7" path="res://scripts/audio/ChannelPlayer.cs" id="9_mbbd7"] @@ -97,9 +98,11 @@ script = ExtResource("3_a4ew1") _projectile = ExtResource("4_saxds") _timer = NodePath("Timer") -[node name="Timer" type="Timer" parent="Shooter" index="0"] +[node name="Timer" type="Timer" parent="Shooter" index="0" node_paths=PackedStringArray("entity")] wait_time = 1.5 one_shot = true +script = ExtResource("6_q58jr") +entity = NodePath("../..") [node name="Behaviour" type="Node" parent="." index="4" node_paths=PackedStringArray("_shootTimer", "_sight")] script = ExtResource("5_7qiua") diff --git a/scenes/entities/plants/potato_mine.tscn b/scenes/entities/plants/potato_mine.tscn index 4a12b17..c3cf489 100644 --- a/scenes/entities/plants/potato_mine.tscn +++ b/scenes/entities/plants/potato_mine.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=26 format=3 uid="uid://b5x35v3w2u8dx"] +[gd_scene load_steps=27 format=3 uid="uid://b5x35v3w2u8dx"] [ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_dj7ul"] [ext_resource type="Texture2D" uid="uid://c77o6ba0mw7a3" path="res://assets/sprites/atlases/plants/potato_mine.png" id="2_sneas"] @@ -8,6 +8,7 @@ [ext_resource type="PackedScene" uid="uid://ckanq33rao1ur" path="res://scenes/particles/potato_explosion.tscn" id="5_px4r0"] [ext_resource type="Script" uid="uid://c36bj8u7jghc7" path="res://scripts/audio/ChannelPlayer.cs" id="7_b1j2f"] [ext_resource type="AudioStream" uid="uid://dltjtpyfr1so0" path="res://assets/audio/sfx/potato_mine.mp3" id="8_3vqdc"] +[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="8_824aq"] [ext_resource type="AudioStream" uid="uid://b27om1bw1x04e" path="res://assets/audio/sfx/dirt_rise.mp3" id="9_3vqdc"] [sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_3vqdc"] @@ -58,7 +59,6 @@ transitions = ["Start", "potato_mine_idle_unprimed", SubResource("AnimationNodeS graph_offset = Vector2(-16.3438, -67.832) [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_824aq"] -graph_offset = Vector2(-427, 79) nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_3vqdc") nodes/TimeScale/position = Vector2(100, 120) nodes/Tree/node = SubResource("AnimationNodeStateMachine_nfn7b") @@ -84,7 +84,7 @@ MaxHP = 20.0 texture = ExtResource("2_sneas") hframes = 7 vframes = 4 -frame = 14 +frame = 7 [node name="AnimationPlayer" parent="." index="1"] libraries = { @@ -123,10 +123,12 @@ audioStream = ExtResource("8_3vqdc") channel = "explosion" metadata/_custom_type_script = "uid://c36bj8u7jghc7" -[node name="PrimeTimer" type="Timer" parent="." index="5"] +[node name="PrimeTimer" type="Timer" parent="." index="5" node_paths=PackedStringArray("entity")] wait_time = 15.0 one_shot = true autostart = true +script = ExtResource("8_824aq") +entity = NodePath("..") [node name="Behaviour" type="Node" parent="." index="6" node_paths=PackedStringArray("_hitbox", "_unprimedShape", "_primedShape")] script = ExtResource("4_twx65") diff --git a/scenes/entities/plants/sunflower.tscn b/scenes/entities/plants/sunflower.tscn index cb0c035..967f77c 100644 --- a/scenes/entities/plants/sunflower.tscn +++ b/scenes/entities/plants/sunflower.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=3 uid="uid://bg7lomiorxo2c"] +[gd_scene load_steps=19 format=3 uid="uid://bg7lomiorxo2c"] [ext_resource type="PackedScene" uid="uid://b1hjjbdwf1rtc" path="res://scenes/templates/plant_template.tscn" id="1_bikjn"] [ext_resource type="Texture2D" uid="uid://b3tuidu8dag8u" path="res://assets/sprites/atlases/plants/sunflower.png" id="2_fwcda"] @@ -6,6 +6,7 @@ [ext_resource type="Script" uid="uid://b71gebny84s81" path="res://scripts/components/plants/PlantSunSpawner.cs" id="3_te0pl"] [ext_resource type="PackedScene" uid="uid://bpekho7leatr5" path="res://scenes/sun.tscn" id="4_b8hls"] [ext_resource type="Script" uid="uid://bth7gah4tn7uj" path="res://scripts/components/plants/behaviours/SunflowerBehaviour.cs" id="5_26je0"] +[ext_resource type="Script" uid="uid://c4jy0cnbnx33h" path="res://scripts/components/TimeScalableTimer.cs" id="7_rlkb7"] [sub_resource type="Animation" id="Animation_bfx6v"] length = 0.001 @@ -92,13 +93,17 @@ _amountPerSun = 25 [node name="Behaviour" type="Node" parent="." index="4"] script = ExtResource("5_26je0") -[node name="Timer" type="Timer" parent="Behaviour" index="0"] +[node name="Timer" type="Timer" parent="Behaviour" index="0" node_paths=PackedStringArray("entity")] wait_time = 24.25 +script = ExtResource("7_rlkb7") +entity = NodePath("../..") -[node name="StartTimer" type="Timer" parent="Behaviour" index="1"] +[node name="StartTimer" type="Timer" parent="Behaviour" index="1" node_paths=PackedStringArray("entity")] wait_time = 12.0 one_shot = true autostart = true +script = ExtResource("7_rlkb7") +entity = NodePath("../..") [node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" index="0"] position = Vector2(0, 4) diff --git a/scenes/templates/plant_template.tscn b/scenes/templates/plant_template.tscn index 685838b..6404adc 100644 --- a/scenes/templates/plant_template.tscn +++ b/scenes/templates/plant_template.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://b1hjjbdwf1rtc"] +[gd_scene load_steps=3 format=3 uid="uid://b1hjjbdwf1rtc"] [ext_resource type="Script" uid="uid://dli2i6albvugt" path="res://scripts/components/plants/RuntimePlantData.cs" id="1_324sd"] +[ext_resource type="Script" uid="uid://dwlwi42smgxkb" path="res://scripts/components/TimeScalableAnimationTree.cs" id="2_e75pf"] [node name="PlantTemplate" type="Node2D"] script = ExtResource("1_324sd") @@ -10,8 +11,10 @@ use_parent_material = true [node name="AnimationPlayer" type="AnimationPlayer" parent="."] -[node name="AnimationTree" type="AnimationTree" parent="."] +[node name="AnimationTree" type="AnimationTree" parent="." node_paths=PackedStringArray("entity")] anim_player = NodePath("../AnimationPlayer") +script = ExtResource("2_e75pf") +entity = NodePath("..") [node name="Hitbox" type="Area2D" parent="."] collision_layer = 2 diff --git a/scripts/components/Entity.cs b/scripts/components/Entity.cs index 5d09167..01e4254 100644 --- a/scripts/components/Entity.cs +++ b/scripts/components/Entity.cs @@ -4,6 +4,7 @@ using Newlon.Systems.Effects; namespace Newlon.Components; +[GlobalClass] public partial class Entity : Node2D { #region Health points @@ -58,13 +59,13 @@ public partial class Entity : Node2D #endregion #region Effects [Export] private Array _effectImmunities = new(); - private readonly Dictionary _activeEffectSlots = new(); - private readonly Dictionary _effectSlotTimers = new(); + private readonly Dictionary _activeEffectSlots = new(); + private readonly Dictionary _effectSlotTimers = new(); [Signal] public delegate void EffectStartedEventHandler(Effect what); [Signal] public delegate void EffectEndedEventHandler(Effect what); [Signal] public delegate void EffectContinuedEventHandler(Effect what); - + public virtual void GiveEffect(Effect what) { @@ -108,7 +109,7 @@ public partial class Entity : Node2D var timer = new Timer() { Autostart = false, OneShot = true }; AddChild(timer); timer.Timeout += () => { EndEffectAtSlot(key); }; - + _effectSlotTimers.Add(key, timer); } @@ -120,7 +121,7 @@ public partial class Entity : Node2D public void ProcessEffects() { - foreach(string key in _activeEffectSlots.Keys) + foreach (string key in _activeEffectSlots.Keys) _activeEffectSlots[key]?.Process(this); } @@ -148,8 +149,8 @@ public partial class Entity : Node2D #endregion #region Godot overrides public override void _Ready() - { - HP = MaxHP; - } + { + HP = MaxHP; + } #endregion } diff --git a/scripts/components/TimeScalableAnimationTree.cs b/scripts/components/TimeScalableAnimationTree.cs new file mode 100644 index 0000000..e7206cd --- /dev/null +++ b/scripts/components/TimeScalableAnimationTree.cs @@ -0,0 +1,17 @@ +using Godot; + +namespace Newlon.Components; + +public partial class TimeScalableAnimationTree : AnimationTree +{ + [Export] private Entity entity; + public override void _Ready() + { + entity.OnLocalTimescaleChanged += OnTimescaleChanged; + } + + private void OnTimescaleChanged(float timescale) + { + Set("parameters/TimeScale/scale", timescale); + } +} diff --git a/scripts/components/TimeScalableAnimationTree.cs.uid b/scripts/components/TimeScalableAnimationTree.cs.uid new file mode 100644 index 0000000..f44c2c0 --- /dev/null +++ b/scripts/components/TimeScalableAnimationTree.cs.uid @@ -0,0 +1 @@ +uid://dwlwi42smgxkb diff --git a/scripts/components/TimeScalableTimer.cs b/scripts/components/TimeScalableTimer.cs new file mode 100644 index 0000000..a6e5c51 --- /dev/null +++ b/scripts/components/TimeScalableTimer.cs @@ -0,0 +1,21 @@ +using Godot; + +namespace Newlon.Components; + +public partial class TimeScalableTimer : Timer +{ + [Export] private Entity entity; + + private float internal_timescale; + public override void _Ready() + { + internal_timescale = entity.LocalTimescale; + entity.OnLocalTimescaleChanged += OnTimescaleChanged; + } + + private void OnTimescaleChanged(float timescale) + { + WaitTime *= internal_timescale / timescale; + internal_timescale = timescale; + } +} diff --git a/scripts/components/TimeScalableTimer.cs.uid b/scripts/components/TimeScalableTimer.cs.uid new file mode 100644 index 0000000..5e713e2 --- /dev/null +++ b/scripts/components/TimeScalableTimer.cs.uid @@ -0,0 +1 @@ +uid://c4jy0cnbnx33h