silly sparks thing
This commit is contained in:
parent
638495f4a3
commit
68b3e1132f
11 changed files with 172 additions and 8 deletions
35
objects/effects/bouncing_spark.gd
Normal file
35
objects/effects/bouncing_spark.gd
Normal file
|
@ -0,0 +1,35 @@
|
|||
extends RigidBody2D
|
||||
|
||||
|
||||
@export var scale_min: float
|
||||
@export var scale_max: float
|
||||
@export var velocity_min: float
|
||||
@export var velocity_max: float
|
||||
@export_custom(0, "radians_as_degrees") var spin_min: float
|
||||
@export_custom(0, "radians_as_degrees") var spin_max: float
|
||||
@export var decay_speed_threshold: float
|
||||
@export var decay_time: float
|
||||
|
||||
|
||||
var _tween: Tween = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var rnd_scale = randf_range(scale_min, scale_max)
|
||||
$Sprite2D.scale = Vector2.ONE * rnd_scale
|
||||
|
||||
linear_velocity = Vector2.from_angle(randf() * TAU) * randf_range(velocity_min, velocity_max)
|
||||
angular_velocity = randf_range(spin_min, spin_max)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if linear_velocity.length() <= decay_speed_threshold:
|
||||
if _tween:
|
||||
return
|
||||
_tween = create_tween().set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
|
||||
_tween.tween_property(self, ^"scale", Vector2.ZERO, decay_time)
|
||||
_tween.tween_callback(queue_free)
|
||||
|
||||
|
||||
func _on_solid_detector_body_entered(body: Node2D) -> void:
|
||||
print("BLEP")
|
1
objects/effects/bouncing_spark.gd.uid
Normal file
1
objects/effects/bouncing_spark.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://b6krgij5xfu1w
|
57
objects/effects/bouncing_spark.tscn
Normal file
57
objects/effects/bouncing_spark.tscn
Normal file
|
@ -0,0 +1,57 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://djdpcsmms727b"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b6krgij5xfu1w" path="res://objects/effects/bouncing_spark.gd" id="1_62ynp"]
|
||||
[ext_resource type="Texture2D" uid="uid://rhc3c5j1lfw" path="res://assets/textures/effects/spark.png" id="1_ag5ij"]
|
||||
[ext_resource type="AudioStream" uid="uid://cmvbwm6gk8n6b" path="res://assets/audio/sfx/spark_bounce.ogg" id="3_4uvf2"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_62ynp"]
|
||||
bounce = 0.8
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_4uvf2"]
|
||||
radius = 2.0
|
||||
|
||||
[sub_resource type="AudioStreamRandomizer" id="AudioStreamRandomizer_us66k"]
|
||||
random_pitch = 1.25
|
||||
streams_count = 1
|
||||
stream_0/stream = ExtResource("3_4uvf2")
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_us66k"]
|
||||
radius = 6.0
|
||||
|
||||
[node name="Spark" type="RigidBody2D"]
|
||||
z_index = -10
|
||||
collision_layer = 0
|
||||
collision_mask = 3
|
||||
mass = 0.1
|
||||
physics_material_override = SubResource("PhysicsMaterial_62ynp")
|
||||
gravity_scale = 0.25
|
||||
linear_damp = 0.3
|
||||
script = ExtResource("1_62ynp")
|
||||
scale_min = 0.5
|
||||
scale_max = 1.0
|
||||
velocity_min = 40.0
|
||||
velocity_max = 80.0
|
||||
spin_min = -1.5708
|
||||
spin_max = 1.5708
|
||||
decay_speed_threshold = 15.0
|
||||
decay_time = 0.2
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_ag5ij")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_4uvf2")
|
||||
|
||||
[node name="BounceSound" type="AudioStreamPlayer2D" parent="."]
|
||||
stream = SubResource("AudioStreamRandomizer_us66k")
|
||||
bus = &"Sound Effects"
|
||||
|
||||
[node name="SolidDetector" type="Area2D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 3
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="SolidDetector"]
|
||||
shape = SubResource("CircleShape2D_us66k")
|
||||
|
||||
[connection signal="body_entered" from="SolidDetector" to="." method="_on_solid_detector_body_entered"]
|
||||
[connection signal="body_entered" from="SolidDetector" to="BounceSound" method="play" unbinds=1]
|
Loading…
Add table
Add a link
Reference in a new issue