From 8fdc2a3ed9407c451a59f33a039a0db17965d4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=91=D0=B4=D0=BE=D1=80=20=D0=92=D0=B5=D1=81=D0=B5?= =?UTF-8?q?=D0=BB=D0=BE=D0=B2?= Date: Thu, 3 Oct 2024 00:25:57 +0500 Subject: [PATCH] aloe --- assets/sprites/plants/aloe.tres | 7 +++ resources/animations/plants/aloe.res | Bin 0 -> 674 bytes resources/plants/Aloe.tres | 14 +++++ scenes/entities/plants/aloe.tscn | 58 ++++++++++++++++++ scripts/components/plants/RuntimePlantData.cs | 2 +- .../plants/behaviours/AloeBehaviour.cs | 42 +++++++++++++ .../plants/behaviours/WallnutBehaviour.cs | 5 ++ 7 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 assets/sprites/plants/aloe.tres create mode 100644 resources/animations/plants/aloe.res create mode 100644 resources/plants/Aloe.tres create mode 100644 scenes/entities/plants/aloe.tscn create mode 100644 scripts/components/plants/behaviours/AloeBehaviour.cs diff --git a/assets/sprites/plants/aloe.tres b/assets/sprites/plants/aloe.tres new file mode 100644 index 0000000..688673b --- /dev/null +++ b/assets/sprites/plants/aloe.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://d4btl7vqi4v0q"] + +[ext_resource type="Texture2D" uid="uid://dvldjlg0nr355" path="res://assets/sprites/atlases/atlas1.png" id="1_rq51o"] + +[resource] +atlas = ExtResource("1_rq51o") +region = Rect2(302, 6, 52, 50) diff --git a/resources/animations/plants/aloe.res b/resources/animations/plants/aloe.res new file mode 100644 index 0000000000000000000000000000000000000000..4a82d5bea54cdb51d73c568cf21b7b5fd7f91fdb GIT binary patch literal 674 zcmV;T0$u%5Q$s@n000005C8x#2mkv>Wl$2YZY($5&!@F79DL0LI6Vm zNdUJhM`ZXvik5R^icYdla488VrW%u!`+w$qZAWOJfa~jt@qc3Af`f@9!2-pz-rjf* zqI`9)7Z?1;{Ez&H{y+Qy6`O1`IcKqTtEtY{6r~w^<~D@@pUpL1Zq=P|V@#!(NoT`R6INX0jCV|6YyxzhiTb0x27N=XUY#?drQ^1r|-U$0L5w?shv1O5kN za62R%P1`yGGB#BHV>snbz!I*bH7=ZvuA|ObAc*X{J2V%Ba}DK+3Xq0pnvLagfba%P=f9L8LqpOuP5S)Ofq;vsaZy7|)rXa9DHr(uZ>qL71g^$8ic{N3~-Gezhq6aHzU4Enfp&tX>E6-tI5G1;gT=R6xBC*4IELW&057`>i~D zpC^Kl;PA%w1w-gwX)T(LRkQ~~YJ_2CJ>h7demsi%8}Xl(Qz-i`d!=!l_MM?bNCYb4 zY1~R=+6g!}s-ywJjeg7XJ1BFYx&?3mufCKNQ%QB1lsDsnyq8sNEyfH*8!-*RSBwf# IPEu1tL(51io&W#< literal 0 HcmV?d00001 diff --git a/resources/plants/Aloe.tres b/resources/plants/Aloe.tres new file mode 100644 index 0000000..ef38f1b --- /dev/null +++ b/resources/plants/Aloe.tres @@ -0,0 +1,14 @@ +[gd_resource type="Resource" script_class="PlantResource" load_steps=4 format=3 uid="uid://bf7vjtufjc8kt"] + +[ext_resource type="Texture2D" uid="uid://d4btl7vqi4v0q" path="res://assets/sprites/plants/aloe.tres" id="1_t4137"] +[ext_resource type="Script" path="res://scripts/resources/PlantResource.cs" id="1_vw2kg"] +[ext_resource type="PackedScene" uid="uid://bw1w8jp0yeypy" path="res://scenes/entities/plants/aloe.tscn" id="2_6a4ia"] + +[resource] +script = ExtResource("1_vw2kg") +Cost = 75 +Scene = ExtResource("2_6a4ia") +ReloadTime = 15.0 +StartReloadTime = 0.0 +Preview = ExtResource("1_t4137") +Layer = 1 diff --git a/scenes/entities/plants/aloe.tscn b/scenes/entities/plants/aloe.tscn new file mode 100644 index 0000000..37fc086 --- /dev/null +++ b/scenes/entities/plants/aloe.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=8 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" path="res://scripts/components/plants/behaviours/AloeBehaviour.cs" id="4_55asm"] + +[sub_resource type="Animation" id="Animation_vknky"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite2D:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [0] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_wlien"] +_data = { +"RESET": SubResource("Animation_vknky") +} + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_oe0dc"] +size = Vector2(22, 32) + +[node name="Aloe" instance=ExtResource("1_n25yi")] +_maxHP = 100 + +[node name="Sprite2D" parent="." index="0"] +position = Vector2(9, -14) +texture = ExtResource("2_iup5p") +hframes = 8 +vframes = 4 + +[node name="AnimationPlayer" parent="." index="1"] +libraries = { +"": SubResource("AnimationLibrary_wlien"), +"aloe": ExtResource("3_3sp3b") +} +autoplay = "aloe/idle" + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox" index="0"] +shape = SubResource("RectangleShape2D_oe0dc") + +[node name="Behaviour" type="Node" parent="." index="3" node_paths=PackedStringArray("_player")] +script = ExtResource("4_55asm") +_player = NodePath("../AnimationPlayer") + +[node name="Timer" type="Timer" parent="Behaviour" index="0"] +wait_time = 15.0 +one_shot = true + +[connection signal="timeout" from="Behaviour/Timer" to="Behaviour" method="OnTimeout"] diff --git a/scripts/components/plants/RuntimePlantData.cs b/scripts/components/plants/RuntimePlantData.cs index 468438a..134fc8b 100644 --- a/scripts/components/plants/RuntimePlantData.cs +++ b/scripts/components/plants/RuntimePlantData.cs @@ -11,7 +11,7 @@ public partial class RuntimePlantData : Node2D, IEntity { [Export] private int _maxHP; - private int _hp; + [Export]private int _hp; public int Hp => _hp; public int MaxHp => _maxHP; public int Line {get; set;} diff --git a/scripts/components/plants/behaviours/AloeBehaviour.cs b/scripts/components/plants/behaviours/AloeBehaviour.cs new file mode 100644 index 0000000..f6f9ff5 --- /dev/null +++ b/scripts/components/plants/behaviours/AloeBehaviour.cs @@ -0,0 +1,42 @@ +using Godot; +using Newlon.Components.Level; + +namespace Newlon.Components.Plants.Behaviours; + +public partial class AloeBehaviour : Node +{ + [Export] private AnimationPlayer _player; + [Export] private float _hpTreshold = 0.25f; + private Timer _timer; + private bool _charge = true; + + public override void _Ready() + { + _timer = GetNode("Timer"); + } + + + + public override void _Process(double delta) + { + var checkPos = GetParent().GlobalPosition + Vector2.Right * Utility.TileWidth; + if(_charge && PoolContainer.Instance.EntityField[1].ContainsKey(checkPos) && PoolContainer.Instance.EntityField[1][checkPos] is RuntimePlantData plantData) + { + if((float)plantData.Hp / (float)plantData.MaxHp < _hpTreshold) + { + plantData.Heal(3000 + 25 * plantData.MaxHp); + _charge = false; + _player.Play("aloe/heal"); + _player.Queue("aloe/idle_used"); + _timer.Start(); + } + } + } + + public void OnTimeout() + { + _charge = true; + _player.Play("aloe/recharge"); + _player.Queue("aloe/idle"); + } +} diff --git a/scripts/components/plants/behaviours/WallnutBehaviour.cs b/scripts/components/plants/behaviours/WallnutBehaviour.cs index 88573e5..b623fab 100644 --- a/scripts/components/plants/behaviours/WallnutBehaviour.cs +++ b/scripts/components/plants/behaviours/WallnutBehaviour.cs @@ -14,6 +14,7 @@ public partial class WallnutBehaviour : Node public void OnHPChanged(int amount) { + if(_data.Hp <= _data.MaxHp*2.0/3.0 && _data.Hp > _data.MaxHp/3.0) { _player.Play("idle_mid"); @@ -22,5 +23,9 @@ public partial class WallnutBehaviour : Node { _player.Play("idle_low"); } + else + { + _player.Play("idle_full"); + } } }