From 9a09776900eb07a7ba86fc2dfb9487072c31cc08 Mon Sep 17 00:00:00 2001 From: Tanner van Teeffelen Date: Wed, 31 Dec 2025 19:01:42 -0500 Subject: [PATCH] Started particle system. --- Materials/Particles/down_particles.tres | 10 +++++++++ Materials/Particles/up_particles.tres | 10 +++++++++ Scenes/player.tscn | 14 ++++++++++++- Scripts/player.gd | 27 ++++++++++++++++--------- project.godot | 4 ++++ 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 Materials/Particles/down_particles.tres create mode 100644 Materials/Particles/up_particles.tres diff --git a/Materials/Particles/down_particles.tres b/Materials/Particles/down_particles.tres new file mode 100644 index 0000000..3dc88cb --- /dev/null +++ b/Materials/Particles/down_particles.tres @@ -0,0 +1,10 @@ +[gd_resource type="ParticleProcessMaterial" format=3 uid="uid://ck13qte606w1j"] + +[resource] +particle_flag_disable_z = true +emission_shape_offset = Vector3(0, -8, 0) +emission_shape = 1 +emission_sphere_radius = 7.35 +gravity = Vector3(0, -98, 0) +scale_max = 5.0 +color = Color(0, 0, 0, 1) diff --git a/Materials/Particles/up_particles.tres b/Materials/Particles/up_particles.tres new file mode 100644 index 0000000..ef7b1a8 --- /dev/null +++ b/Materials/Particles/up_particles.tres @@ -0,0 +1,10 @@ +[gd_resource type="ParticleProcessMaterial" format=3 uid="uid://c81obsijtfpwq"] + +[resource] +particle_flag_disable_z = true +emission_shape_offset = Vector3(0, -8, 0) +emission_shape = 1 +emission_sphere_radius = 7.35 +gravity = Vector3(0, 98, 0) +scale_max = 2.0 +color = Color(0, 0, 0, 1) diff --git a/Scenes/player.tscn b/Scenes/player.tscn index 0baacf8..df1febd 100644 --- a/Scenes/player.tscn +++ b/Scenes/player.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=4 format=3 uid="uid://syx6ov00a585"] +[gd_scene load_steps=5 format=3 uid="uid://syx6ov00a585"] [ext_resource type="Script" uid="uid://ohb2t6o7wr1u" path="res://Scripts/player.gd" id="1_cvnsp"] [ext_resource type="Texture2D" uid="uid://btqnhg54e1p66" path="res://Sprites/png/spritesheet.png" id="2_6t5aa"] +[ext_resource type="Material" uid="uid://ck13qte606w1j" path="res://Materials/Particles/down_particles.tres" id="2_vgqql"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_jjgbg"] size = Vector2(16, 16) @@ -9,6 +10,12 @@ size = Vector2(16, 16) [node name="Player" type="CharacterBody2D"] script = ExtResource("1_cvnsp") +[node name="GPUParticles2D" type="GPUParticles2D" parent="."] +emitting = false +amount = 100 +lifetime = 3.3699999999999997 +process_material = ExtResource("2_vgqql") + [node name="Sprite" type="Sprite2D" parent="."] texture = ExtResource("2_6t5aa") hframes = 2 @@ -16,3 +23,8 @@ vframes = 2 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("RectangleShape2D_jjgbg") + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] +rect = Rect2(-8, -8, 16, 16) + +[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] diff --git a/Scripts/player.gd b/Scripts/player.gd index f587a07..2847800 100644 --- a/Scripts/player.gd +++ b/Scripts/player.gd @@ -2,6 +2,7 @@ extends CharacterBody2D @onready var tile_layer : TileMapLayer = $"../TileMapLayer" @onready var level : Node2D = $".." +@onready var particles : GPUParticles2D = $GPUParticles2D @export_category("Movement") @export var acceleration : float = 50 @@ -16,6 +17,8 @@ func _ready() -> void: func _physics_process(delta: float) -> void: + print(velocity.y) + if dead == false: #Horizontal movement. move_input = Input.get_axis("move_left", "move_right") @@ -29,6 +32,9 @@ func _physics_process(delta: float) -> void: if Input.is_action_just_pressed("flip") and (is_on_floor() or is_on_ceiling()): al_globals.gravity *= -1 + + if velocity.y > 500: + particles.emitting = true move_and_slide() #Allow physics control. spike_detection() #Checks for tiles with the "Spike" custom data enabled. @@ -44,19 +50,19 @@ func spike_detection() -> void: if tile_data: var custom_data = tile_data.get_custom_data("spike") if custom_data == true: - death() - await get_tree().create_timer(1).timeout - respawn() + death(false) - -func death() -> void: +func death(fallen: bool) -> void: dead = true - velocity.x = 0 - velocity.y = 0 - scale.x = lerp(scale.x, 0.0, 0.1) - scale.y = lerp(scale.y, 0.0, 0.1) + if !fallen: + velocity.x = 0 + velocity.y = 0 + scale.x = lerp(scale.x, 0.0, 0.1) + scale.y = lerp(scale.y, 0.0, 0.1) if al_globals.gravity < 0: al_globals.gravity *= -1 + await get_tree().create_timer(1.0).timeout + respawn() func respawn() -> void: dead = false @@ -66,3 +72,6 @@ func respawn() -> void: position.y = level.startPosY +func _on_visible_on_screen_notifier_2d_screen_exited() -> void: + if !dead: + death(true) diff --git a/project.godot b/project.godot index 9b97389..1ef97d2 100644 --- a/project.godot +++ b/project.godot @@ -41,3 +41,7 @@ move_right={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } + +[rendering] + +environment/defaults/default_clear_color=Color(1, 1, 1, 1)