diff --git a/src/entities/Enemy.gd b/src/entities/Enemy.gd index 5e1f5c3..1ae739a 100644 --- a/src/entities/Enemy.gd +++ b/src/entities/Enemy.gd @@ -2,4 +2,7 @@ extends KinematicBody2D func _on_Damageable_dead(): + for child in get_children(): + if child.name == "BranchSpawn": + child.BranchSpawn() queue_free() diff --git a/src/entities/Enemy.tscn b/src/entities/Enemy.tscn index f1e2d11..8774b68 100644 --- a/src/entities/Enemy.tscn +++ b/src/entities/Enemy.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://src/mechanics/Black.png" type="Texture" id=1] [ext_resource path="res://src/entities/behaviours/ErraticMovement.tscn" type="PackedScene" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://src/entities/behaviours/Damageable.tscn" type="PackedScene" id=4] [ext_resource path="res://src/entities/behaviours/Alliance.tscn" type="PackedScene" id=5] [ext_resource path="res://src/entities/Enemy.gd" type="Script" id=6] +[ext_resource path="res://src/entities/behaviours/BranchSpawn.gd" type="Script" id=7] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 16, 16 ) @@ -28,4 +29,7 @@ texture = ExtResource( 1 ) [node name="Alliance" parent="." instance=ExtResource( 5 )] alliance = -1 + +[node name="BranchSpawn" type="Node" parent="."] +script = ExtResource( 7 ) [connection signal="dead" from="Damageable" to="." method="_on_Damageable_dead"] diff --git a/src/entities/behaviours/BranchSpawn.gd b/src/entities/behaviours/BranchSpawn.gd new file mode 100644 index 0000000..0bf0486 --- /dev/null +++ b/src/entities/behaviours/BranchSpawn.gd @@ -0,0 +1,13 @@ +extends Node + + +export var branch: PackedScene = preload("res://src/entities/Pickup.tscn") +export var branch_container_node_path: String = "../.." +onready var branch_container_node: Node = get_node(branch_container_node_path) +onready var source: Node2D = get_parent() + + +func BranchSpawn(): + var new_branch = branch.instance() + new_branch.set_position(source.global_position) + branch_container_node.add_child(new_branch)