Skip to content

Commit

Permalink
Add plant spawning.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malcolmnixon committed Feb 16, 2025
1 parent f41cba3 commit 6c9cb72
Show file tree
Hide file tree
Showing 22 changed files with 2,237 additions and 71 deletions.
11 changes: 9 additions & 2 deletions ar/hands/hand_pose_action_map.tres
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[gd_resource type="Resource" script_class="HandPoseActionMap" load_steps=9 format=3 uid="uid://c7gtqq7mvo024"]
[gd_resource type="Resource" script_class="HandPoseActionMap" load_steps=11 format=3 uid="uid://c7gtqq7mvo024"]

[ext_resource type="Script" path="res://addons/hand_pose_detector/hand_pose_action.gd" id="1_5g380"]
[ext_resource type="Resource" uid="uid://dhbqusuodrl3r" path="res://addons/hand_pose_detector/poses/fist.tres" id="2_pe5e8"]
[ext_resource type="Resource" uid="uid://ceofxcl7q122" path="res://addons/hand_pose_detector/poses/point.tres" id="3_dk2tv"]
[ext_resource type="Script" path="res://addons/hand_pose_detector/hand_pose_action_map.gd" id="4_2myt4"]
[ext_resource type="Resource" uid="uid://8kyxp8p3nnv0" path="res://ar/hands/lightning.tres" id="4_4ccfd"]
[ext_resource type="Resource" uid="uid://sy66yqr1xila" path="res://addons/hand_pose_detector/poses/thumbs_up.tres" id="5_c8tws"]

[sub_resource type="Resource" id="Resource_uf4kw"]
script = ExtResource("1_5g380")
Expand All @@ -24,6 +25,12 @@ pose = ExtResource("4_4ccfd")
action_type = 0
action_name = "lightning"

[sub_resource type="Resource" id="Resource_8jwd2"]
script = ExtResource("1_5g380")
pose = ExtResource("5_c8tws")
action_type = 0
action_name = "seed"

[resource]
script = ExtResource("4_2myt4")
actions = Array[ExtResource("1_5g380")]([SubResource("Resource_uf4kw"), SubResource("Resource_cc2a6"), SubResource("Resource_5y3a0")])
actions = Array[ExtResource("1_5g380")]([SubResource("Resource_uf4kw"), SubResource("Resource_cc2a6"), SubResource("Resource_5y3a0"), SubResource("Resource_8jwd2")])
5 changes: 3 additions & 2 deletions ar/hands/hand_pose_set.tres
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_resource type="Resource" script_class="HandPoseSet" load_steps=6 format=3 uid="uid://bmmigv35h8cxa"]
[gd_resource type="Resource" script_class="HandPoseSet" load_steps=7 format=3 uid="uid://bmmigv35h8cxa"]

[ext_resource type="Script" path="res://addons/hand_pose_detector/hand_pose.gd" id="1_vg67v"]
[ext_resource type="Resource" uid="uid://dhbqusuodrl3r" path="res://addons/hand_pose_detector/poses/fist.tres" id="2_c4yhd"]
[ext_resource type="Resource" uid="uid://ceofxcl7q122" path="res://addons/hand_pose_detector/poses/point.tres" id="3_a70uy"]
[ext_resource type="Script" path="res://addons/hand_pose_detector/hand_pose_set.gd" id="4_f1s8l"]
[ext_resource type="Resource" uid="uid://8kyxp8p3nnv0" path="res://ar/hands/lightning.tres" id="4_ukem6"]
[ext_resource type="Resource" uid="uid://sy66yqr1xila" path="res://addons/hand_pose_detector/poses/thumbs_up.tres" id="5_6jo51"]

[resource]
script = ExtResource("4_f1s8l")
poses = Array[ExtResource("1_vg67v")]([ExtResource("2_c4yhd"), ExtResource("3_a70uy"), ExtResource("4_ukem6")])
poses = Array[ExtResource("1_vg67v")]([ExtResource("2_c4yhd"), ExtResource("3_a70uy"), ExtResource("4_ukem6"), ExtResource("5_6jo51")])
16 changes: 8 additions & 8 deletions ar/hands/lightning.tres
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
[sub_resource type="Resource" id="Resource_xltr5"]
script = ExtResource("1_6gpoa")
type = 1
min = 4.0
from = 7.0
min = 3.0
from = 6.0
to = 13.0
max = 16.0

[sub_resource type="Resource" id="Resource_hp7ec"]
script = ExtResource("1_6gpoa")
type = 1
min = 4.0
from = 7.0
min = 3.0
from = 6.0
to = 13.0
max = 16.0

Expand All @@ -40,8 +40,8 @@ script = ExtResource("1_6gpoa")
type = 1
min = -20.0
from = -15.0
to = 15.0
max = 20.0
to = 20.0
max = 30.0

[sub_resource type="Resource" id="Resource_mtrhp"]
script = ExtResource("1_6gpoa")
Expand Down Expand Up @@ -72,8 +72,8 @@ script = ExtResource("1_6gpoa")
type = 1
min = -20.0
from = -15.0
to = 15.0
max = 20.0
to = 20.0
max = 30.0

[sub_resource type="Resource" id="Resource_gi5nw"]
script = ExtResource("1_6gpoa")
Expand Down
38 changes: 38 additions & 0 deletions ar/objects/destructible.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
extends StaticBody3D


var _grown : bool = false


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# Set the plant scale to zero and disable collision
%Object.scale = Vector3.ZERO
%Collision.disabled = true

# Tween scaling the plant to full size
var tween = get_tree().create_tween()
tween.tween_property(%Object, "scale", Vector3.ONE, 1.0)
tween.tween_callback(_on_grown)


# Called when fully grown
func _on_grown() -> void:
# Enable collision
%Collision.disabled = false
_grown = true


func damage() -> void:
# Cannot damage if not grown
if not _grown:
return

# Disable collision
%Collision.disabled = true
_grown = false

# Shrink and destroy
var tween = get_tree().create_tween()
tween.tween_property(%Object, "scale", Vector3.ZERO, 1.0)
tween.tween_callback(queue_free)
20 changes: 20 additions & 0 deletions ar/objects/moss_flower.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[gd_scene load_steps=4 format=3 uid="uid://cuqkxcsnjduau"]

[ext_resource type="Script" path="res://ar/objects/destructible.gd" id="1_bredg"]
[ext_resource type="PackedScene" uid="uid://bqkrg317dd7bb" path="res://assets/meshes/moss_flower.tscn" id="2_35brj"]

[sub_resource type="SphereShape3D" id="SphereShape3D_vgnh5"]
radius = 0.181445

[node name="MossFlower" type="StaticBody3D" groups=["destructible"]]
collision_layer = 2
collision_mask = 0
script = ExtResource("1_bredg")

[node name="Collision" type="CollisionShape3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.110201, 0)
shape = SubResource("SphereShape3D_vgnh5")

[node name="Object" parent="." instance=ExtResource("2_35brj")]
unique_name_in_owner = true
19 changes: 19 additions & 0 deletions ar/objects/yard_grass.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[gd_scene load_steps=4 format=3 uid="uid://c8drr7w7g0jdf"]

[ext_resource type="PackedScene" uid="uid://y0o3ldi4wol1" path="res://assets/meshes/yard_grass.tscn" id="1_v60ox"]
[ext_resource type="Script" path="res://ar/objects/destructible.gd" id="1_vvql1"]

[sub_resource type="SphereShape3D" id="SphereShape3D_w5r4d"]
radius = 0.279486

[node name="YardGrass" type="StaticBody3D" groups=["destructible"]]
collision_layer = 2
collision_mask = 0
script = ExtResource("1_vvql1")

[node name="Collision" type="CollisionShape3D" parent="."]
unique_name_in_owner = true
shape = SubResource("SphereShape3D_w5r4d")

[node name="Object" parent="." instance=ExtResource("1_v60ox")]
unique_name_in_owner = true
24 changes: 20 additions & 4 deletions ar/spells/fireball.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ extends AnimatableBody3D

const VELOCITY := 4.0

const DAMAGE_RANGE := 0.8


var _hit : bool = false
var _expire : float = 3.0
Expand All @@ -20,13 +22,27 @@ func _process(delta: float) -> void:

# Handle collision or flight-expiration
if collision or _expire <= 0.0:
# Stop emitting and let expire
%TrailParticles.emitting = false
%ExplosionParticles.emitting = true
%ExplosionSound.play()
# Trigger explosion
_explode()
_hit = true
_expire = 2.0

# Free if expired
if _hit and _expire <= 0.0:
queue_free()


func _explode() -> void:
# Perform explision
%TrailParticles.emitting = false
%ExplosionParticles.emitting = true
%ExplosionSound.play()

var kill_list := get_tree().get_nodes_in_group("destructible")
for k in kill_list:
if global_position.distance_to(k.global_position) < DAMAGE_RANGE:
k.damage()




11 changes: 2 additions & 9 deletions ar/spells/fireball.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://bcjr1trix0aie"]
[gd_scene load_steps=18 format=3 uid="uid://bcjr1trix0aie"]

[ext_resource type="Script" path="res://ar/spells/fireball.gd" id="1_k2x8b"]
[ext_resource type="Texture2D" uid="uid://c2depw22ryg7c" path="res://addons/kenney_particle_pack/flame_04.png" id="2_lg1im"]
Expand All @@ -8,10 +8,6 @@
[sub_resource type="SphereShape3D" id="SphereShape3D_rbyv2"]
radius = 0.05

[sub_resource type="SphereMesh" id="SphereMesh_v0c6o"]
radius = 0.05
height = 0.1

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8ekkm"]
transparency = 1
blend_mode = 1
Expand Down Expand Up @@ -85,16 +81,13 @@ size = Vector2(0.3, 0.3)

[node name="Fireball" type="AnimatableBody3D"]
collision_layer = 0
collision_mask = 3
sync_to_physics = false
script = ExtResource("1_k2x8b")

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_rbyv2")

[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
visible = false
mesh = SubResource("SphereMesh_v0c6o")

[node name="TrailParticles" type="GPUParticles3D" parent="."]
unique_name_in_owner = true
material_override = SubResource("StandardMaterial3D_8ekkm")
Expand Down
47 changes: 42 additions & 5 deletions ar/spells/lightning.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
extends Node3D
extends AnimatableBody3D


func _ready() -> void:
%GPUParticles3D.emitting = true
const VELOCITY := 6.0

const DAMAGE_RANGE := 0.8

func _on_timer_timeout() -> void:
queue_free()

var _hit : bool = false
var _expire : float = 3.0


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# Update expiration timer
_expire -= delta

# Process if not hit
if not _hit:
# Move the fireball and update expiration time
var collision := move_and_collide(-global_basis.z * VELOCITY * delta)

# Handle collision or flight-expiration
if collision or _expire <= 0.0:
# Trigger explosion
_explode()
_hit = true
_expire = 2.0

# Free if expired
if _hit and _expire <= 0.0:
queue_free()


func _explode() -> void:
# Perform explision
%TrailParticles.emitting = false

var kill_list := get_tree().get_nodes_in_group("destructible")
for k in kill_list:
if global_position.distance_to(k.global_position) < DAMAGE_RANGE:
k.damage()




77 changes: 36 additions & 41 deletions ar/spells/lightning.tscn
Original file line number Diff line number Diff line change
@@ -1,62 +1,57 @@
[gd_scene load_steps=9 format=3 uid="uid://blv7ye5k0f3ox"]
[gd_scene load_steps=10 format=3 uid="uid://b1yt3m0qesmx8"]

[ext_resource type="Script" path="res://ar/spells/lightning.gd" id="1_6klr6"]
[ext_resource type="Texture2D" uid="uid://cc750lgosa8v2" path="res://addons/kenney_particle_pack/spark_03.png" id="1_lbhv0"]
[ext_resource type="Texture2D" uid="uid://cykuuu3rfqm7d" path="res://addons/kenney_particle_pack/spark_01.png" id="2_nxcjo"]
[ext_resource type="AudioStream" uid="uid://bx6nrnl7vl0xc" path="res://assets/sounds/sparks.wav" id="3_os4q2"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_luvq8"]
[sub_resource type="SphereShape3D" id="SphereShape3D_xuhcn"]
radius = 0.05

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_q40ya"]
transparency = 1
blend_mode = 1
cull_mode = 2
vertex_color_use_as_albedo = true
albedo_texture = ExtResource("1_lbhv0")
albedo_texture = ExtResource("2_nxcjo")
disable_receive_shadows = true
billboard_mode = 3
billboard_keep_scale = true
particles_anim_h_frames = 1
particles_anim_v_frames = 1
particles_anim_loop = false

[sub_resource type="Curve" id="Curve_fcwys"]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.0395738, 0), 0.0, 0.0, 0, 0, Vector2(0.0898021, 1), 0.0, 0.0, 0, 0, Vector2(0.146119, 0), 0.0, 0.0, 0, 0, Vector2(0.216134, 0), 0.0, 0.0, 0, 0, Vector2(0.254186, 0.717391), 0.0, 0.0, 0, 0, Vector2(0.29376, 0), 0.0, 0.0, 0, 0, Vector2(0.400304, 0), 0.0, 0.0, 0, 0, Vector2(0.439878, 0.542102), 0.0, 0.0, 0, 0, Vector2(0.487062, 0), 0.0, 0.0, 0, 0, Vector2(0.563166, 0), 0.0, 0.0, 0, 0, Vector2(0.61035, 0.341772), 0.0, 0.0, 0, 0, Vector2(0.668189, 0), 0.0, 0.0, 0, 0, Vector2(0.729072, 0), 0.0, 0.0, 0, 0, Vector2(0.761035, 0.255916), 0.0, 0.0, 0, 0, Vector2(0.802131, 0), 0.0, 0.0, 0, 0, Vector2(0.858447, 0), 0.0, 0.0, 0, 0, Vector2(0.887984, 0.12282), 0.0, 0.0, 0, 0, Vector2(0.916286, 0), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 20

[sub_resource type="CurveTexture" id="CurveTexture_5vcqc"]
curve = SubResource("Curve_fcwys")

[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_uuexw"]
angle_min = -180.0
angle_max = 180.0
direction = Vector3(0, 0, -1)
spread = 20.0
flatness = 1.0
initial_velocity_min = 3.0
initial_velocity_max = 6.0
[sub_resource type="Curve" id="Curve_r6cpr"]
_data = [Vector2(0.0103093, 0), 0.0, 0.0, 0, 0, Vector2(0.0234483, 1), 0.0, 0.0, 0, 0, Vector2(0.0496552, 0), 0.0, 0.0, 0, 0, Vector2(0.13931, 0), 0.0, 0.0, 0, 0, Vector2(0.154483, 0.881), 0.0, 0.0, 0, 0, Vector2(0.175258, 0), 0.0, 0.0, 0, 0, Vector2(0.266207, 0), 0.0, 0.0, 0, 0, Vector2(0.281379, 0.710539), 0.0, 0.0, 0, 0, Vector2(0.298969, 0), 0.0, 0.0, 0, 0, Vector2(0.390345, 0), 0.0, 0.0, 0, 0, Vector2(0.404138, 0.559377), 0.0, 0.0, 0, 0, Vector2(0.42268, 0), 0.0, 0.0, 0, 0, Vector2(0.508965, 0), 0.0, 0.0, 0, 0, Vector2(0.531034, 0.231321), 0.0, 0.0, 0, 0, Vector2(0.54433, 0), 0.0, 0.0, 0, 0, Vector2(0.642759, 0), 0.0, 0.0, 0, 0, Vector2(0.652414, 0.147699), 0.0, 0.0, 0, 0, Vector2(0.670345, 0), 0.0, 0.0, 0, 0, Vector2(0.776552, 0), 0.0, 0.0, 0, 0, Vector2(0.786207, 0.105888), 0.0, 0.0, 0, 0, Vector2(0.795862, 0), 0.0, 0.0, 0, 0, Vector2(0.921379, 0), 0.0, 0.0, 0, 0, Vector2(0.929655, 0.0640773), 0.0, 0.0, 0, 0, Vector2(0.942069, 0), 0.0, 0.0, 0, 0]
point_count = 24

[sub_resource type="CurveTexture" id="CurveTexture_3g6n4"]
curve = SubResource("Curve_r6cpr")

[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_sagkm"]
emission_shape = 1
emission_sphere_radius = 0.05
angle_min = 1.07288e-05
angle_max = 360.0
spread = 180.0
initial_velocity_max = 0.2
gravity = Vector3(0, 0, 0)
color = Color(3, 5, 5, 1)
alpha_curve = SubResource("CurveTexture_5vcqc")
color = Color(2, 2, 4, 1)
alpha_curve = SubResource("CurveTexture_3g6n4")

[sub_resource type="QuadMesh" id="QuadMesh_h5g5p"]
[sub_resource type="QuadMesh" id="QuadMesh_oog7i"]
size = Vector2(0.3, 0.3)

[node name="Lightning" type="Node3D"]
[node name="Lightning2" type="AnimatableBody3D"]
script = ExtResource("1_6klr6")

[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_xuhcn")

[node name="TrailParticles" type="GPUParticles3D" parent="."]
unique_name_in_owner = true
material_override = SubResource("StandardMaterial3D_luvq8")
emitting = false
amount = 50
one_shot = true
explosiveness = 0.45
process_material = SubResource("ParticleProcessMaterial_uuexw")
draw_pass_1 = SubResource("QuadMesh_h5g5p")

[node name="Timer" type="Timer" parent="."]
wait_time = 2.0
one_shot = true

[node name="Sparks" type="AudioStreamPlayer3D" parent="."]
material_override = SubResource("StandardMaterial3D_q40ya")
amount = 100
process_material = SubResource("ParticleProcessMaterial_sagkm")
draw_pass_1 = SubResource("QuadMesh_oog7i")

[node name="Sound" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("3_os4q2")
autoplay = true

[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
Loading

0 comments on commit 6c9cb72

Please sign in to comment.