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 0000000..4a82d5b Binary files /dev/null and b/resources/animations/plants/aloe.res differ 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"); + } } }