diff --git a/resources/plants/Sunflower.tres b/resources/plants/Sunflower.tres index de13054..204e8ea 100644 --- a/resources/plants/Sunflower.tres +++ b/resources/plants/Sunflower.tres @@ -1,13 +1,13 @@ [gd_resource type="Resource" script_class="PlantResource" load_steps=4 format=3 uid="uid://drm42f48urvc4"] [ext_resource type="Texture2D" uid="uid://iw75j816gbc" path="res://assets/sprites/plants/sunflower.tres" id="1_8rd5i"] -[ext_resource type="PackedScene" uid="uid://be1kgukmiu0hs" path="res://scenes/entities/plants/peashooter.tscn" id="2_7mcb6"] +[ext_resource type="PackedScene" uid="uid://hsllvtm3q34d" path="res://scenes/entities/plants/sunflower.tscn" id="2_e5o45"] [ext_resource type="Script" path="res://scripts/resources/PlantResource.cs" id="3_vt4jc"] [resource] script = ExtResource("3_vt4jc") Cost = 50 -Scene = ExtResource("2_7mcb6") +Scene = ExtResource("2_e5o45") ReloadTime = 5.0 StartReloadTime = 0.0 Preview = ExtResource("1_8rd5i") diff --git a/scenes/entities/plants/sunflower.tscn b/scenes/entities/plants/sunflower.tscn new file mode 100644 index 0000000..096dea3 --- /dev/null +++ b/scenes/entities/plants/sunflower.tscn @@ -0,0 +1,170 @@ +[gd_scene load_steps=17 format=3 uid="uid://hsllvtm3q34d"] + +[ext_resource type="Script" path="res://scripts/components/plants/RuntimePlantData.cs" id="1_2wmcw"] +[ext_resource type="Texture2D" uid="uid://b3tuidu8dag8u" path="res://assets/sprites/atlases/plants/sunflower.png" id="2_fwcda"] +[ext_resource type="Script" 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" path="res://scripts/components/plants/behaviours/SunflowerBehaviour.cs" id="5_26je0"] + +[sub_resource type="Animation" id="Animation_7b6ex"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [12] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("AnimationTree:parameters/conditions/produce") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} + +[sub_resource type="Animation" id="Animation_w8qjp"] +resource_name = "idle" +length = 0.833342 +loop_mode = 2 +step = 0.0833333 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.166667, 0.333333, 0.5, 0.666667, 0.833333), +"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1), +"update": 1, +"values": [4, 6, 8, 10, 12, 14] +} + +[sub_resource type="Animation" id="Animation_18upv"] +resource_name = "produce" +step = 0.0833333 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Sprite:frame") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.0833333, 0.166667, 0.25, 0.333333, 0.416667, 0.5, 0.583333, 0.666666), +"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1, 1), +"update": 1, +"values": [1, 3, 5, 7, 9, 11, 13, 15, 17] +} +tracks/1/type = "method" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("PlantSunSpawner") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0.5), +"transitions": PackedFloat32Array(1), +"values": [{ +"args": [], +"method": &"Spawn" +}] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("AnimationTree:parameters/conditions/produce") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0.5), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_piyjs"] +_data = { +"RESET": SubResource("Animation_7b6ex"), +"idle": SubResource("Animation_w8qjp"), +"produce": SubResource("Animation_18upv") +} + +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_eokqq"] +animation = &"idle" + +[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_1pq1s"] +animation = &"produce" + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_51e4m"] +advance_mode = 2 +advance_condition = &"produce" + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_rn41y"] +switch_mode = 2 +advance_mode = 2 + +[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_agd8v"] +advance_mode = 2 + +[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_1ra8v"] +states/idle/node = SubResource("AnimationNodeAnimation_eokqq") +states/idle/position = Vector2(351, 100) +states/produce/node = SubResource("AnimationNodeAnimation_1pq1s") +states/produce/position = Vector2(659, 100) +transitions = ["idle", "produce", SubResource("AnimationNodeStateMachineTransition_51e4m"), "produce", "idle", SubResource("AnimationNodeStateMachineTransition_rn41y"), "Start", "idle", SubResource("AnimationNodeStateMachineTransition_agd8v")] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_626vr"] +size = Vector2(26, 48) + +[node name="Sunflower" type="Node2D"] +script = ExtResource("1_2wmcw") + +[node name="Sprite" type="Sprite2D" parent="."] +texture = ExtResource("2_fwcda") +hframes = 2 +vframes = 9 +frame = 12 + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +"": SubResource("AnimationLibrary_piyjs") +} + +[node name="AnimationTree" type="AnimationTree" parent="."] +tree_root = SubResource("AnimationNodeStateMachine_1ra8v") +anim_player = NodePath("../AnimationPlayer") +parameters/conditions/produce = false + +[node name="Hitbox" type="Area2D" parent="."] +collision_layer = 2 +collision_mask = 0 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"] +position = Vector2(0, 4) +shape = SubResource("RectangleShape2D_626vr") + +[node name="PlantSunSpawner" type="Node2D" parent="."] +position = Vector2(-2, 0) +script = ExtResource("3_te0pl") +_sunScene = ExtResource("4_b8hls") +_amountPerSun = 25 + +[node name="Behaviour" type="Node" parent="."] +script = ExtResource("5_26je0") + +[node name="Timer" type="Timer" parent="Behaviour"] +wait_time = 5.0 +autostart = true + +[connection signal="timeout" from="Behaviour/Timer" to="Behaviour" method="Timeout"] diff --git a/scripts/components/level/PlantField.cs b/scripts/components/level/PlantField.cs index 65c19aa..a45f607 100644 --- a/scripts/components/level/PlantField.cs +++ b/scripts/components/level/PlantField.cs @@ -72,6 +72,7 @@ public partial class PlantField : Node2D LevelController.Instance.Pools.Plants.AddChild(plant); plant.GlobalPosition = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14); plant.Resource = _resource; + plant.Line = (int)plant.GlobalPosition.Y/Utility.TileHeight; LevelController.Instance.Pools.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity); diff --git a/scripts/components/plants/PlantSunSpawner.cs b/scripts/components/plants/PlantSunSpawner.cs new file mode 100644 index 0000000..64973f3 --- /dev/null +++ b/scripts/components/plants/PlantSunSpawner.cs @@ -0,0 +1,19 @@ +using Godot; +using System; + +public partial class PlantSunSpawner : Node2D +{ + [Export] + private PackedScene _sunScene; + [Export] + private int _amountPerSun; + + public void Spawn() + { + var sun = _sunScene.Instantiate(); + sun.amount = _amountPerSun; + + LevelController.Instance.Pools.Projectiles.AddChild(sun); + sun.GlobalPosition = GlobalPosition; + } +} diff --git a/scripts/components/plants/RuntimePlantData.cs b/scripts/components/plants/RuntimePlantData.cs index 8f3697a..cbdc329 100644 --- a/scripts/components/plants/RuntimePlantData.cs +++ b/scripts/components/plants/RuntimePlantData.cs @@ -10,11 +10,9 @@ 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 int Line {get; set;} public PlantResource Resource; public override void _Ready() @@ -41,7 +39,6 @@ public partial class RuntimePlantData : Node2D, IEntity Kill(); } } - public void Kill() { LevelController.Instance.Pools.EntityField[Resource.Layer].Remove(GlobalPosition); diff --git a/scripts/components/plants/behaviours/SunflowerBehaviour.cs b/scripts/components/plants/behaviours/SunflowerBehaviour.cs new file mode 100644 index 0000000..1e1cfef --- /dev/null +++ b/scripts/components/plants/behaviours/SunflowerBehaviour.cs @@ -0,0 +1,18 @@ +using Godot; +using System; + +public partial class SunflowerBehaviour : Node +{ + private AnimationTree _tree; + + public override void _Ready() + { + _tree = GetNode("../AnimationTree"); + } + + public void Timeout() + { + _tree.Set("parameters/conditions/produce",true); + } + +}