final lesson 9

This commit is contained in:
Emmet
2024-12-10 21:31:07 -06:00
parent e7bfcf5fa2
commit d91fe9ac56
6 changed files with 65 additions and 6 deletions

View File

@ -19,7 +19,6 @@ func _ready():
star.scale = Vector2(random_scale,random_scale)
star.speed_scale = rng.randf_range(0.5,2)
$Stars.add_child(star)
func _on_meteor_timer_timeout() -> void:
var meteor = meteor_scene.instantiate()
@ -28,6 +27,7 @@ func _on_meteor_timer_timeout() -> void:
meteor.connect('collision',_on_meteor_collision)
func _on_meteor_collision():
$Player.play_collision_sound()
health -= 1
get_tree().call_group('ui','set_health',health)
if health == 0:
@ -37,4 +37,3 @@ func _on_player_laser(pos) -> void:
var laser = laser_scene.instantiate()
$Lasers.add_child(laser)
laser.position = pos

View File

@ -2,6 +2,7 @@ extends Area2D
var velocity
var angular_velocity
var can_collide : bool = true
signal collision
@ -30,10 +31,15 @@ func _process(delta):
rotation += angular_velocity * delta
func _on_body_entered(body:Node2D) -> void:
collision.emit()
if can_collide:
collision.emit()
func _on_area_entered(area: Area2D) -> void:
Global.score += 150
area.queue_free()
$ExplosionSound.play()
$Sprite.hide()
can_collide = false
await get_tree().create_timer(0.5).timeout
queue_free()

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://chbsiw6lpm0d2"]
[gd_scene load_steps=4 format=3 uid="uid://chbsiw6lpm0d2"]
[ext_resource type="Script" path="res://meteor.gd" id="1_hsdcx"]
[ext_resource type="Texture2D" uid="uid://baifmn2j7f820" path="res://assets/PNG/Meteors/meteorBrown_big1.png" id="1_m5pls"]
[ext_resource type="AudioStream" uid="uid://kyo8r8q8qf4l" path="res://assets/Bonus/sfx_twoTone.ogg" id="3_lhjw1"]
[node name="Meteor" type="Area2D"]
collision_layer = 0
@ -14,5 +15,8 @@ texture = ExtResource("1_m5pls")
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(-33, -40, 23, -40, 48, -1, 34, 31, 10, 29, -23, 40, -50, 10)
[node name="ExplosionSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("3_lhjw1")
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -21,7 +21,10 @@ func _process(_delta: float) -> void:
laser.emit($LaserSpawnPos.global_position)
canShoot = false
$LaserCooldown.start()
$LaserSound.play()
func _on_laser_cooldown_timeout() -> void:
canShoot = true
func play_collision_sound() -> void:
$DamageSound.play()

View File

@ -1,12 +1,48 @@
[gd_scene load_steps=3 format=3 uid="uid://cxw7wbwterb7u"]
[gd_scene load_steps=9 format=3 uid="uid://cxw7wbwterb7u"]
[ext_resource type="Texture2D" uid="uid://43wp37ngt5xt" path="res://assets/PNG/playerShip1_blue.png" id="1_atygw"]
[ext_resource type="Script" path="res://player.gd" id="1_lh8st"]
[ext_resource type="Texture2D" uid="uid://dfuim8wosxlf6" path="res://assets/PNG/Effects/star2.png" id="2_m3c71"]
[ext_resource type="AudioStream" uid="uid://ms1qpf4fxjl4" path="res://assets/Bonus/sfx_laser2.ogg" id="3_t1lif"]
[ext_resource type="AudioStream" uid="uid://br5sln755lh6q" path="res://assets/Bonus/sfx_shieldDown.ogg" id="4_pi1bq"]
[sub_resource type="Gradient" id="Gradient_6u34j"]
[sub_resource type="GradientTexture1D" id="GradientTexture1D_uxnd3"]
gradient = SubResource("Gradient_6u34j")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_psy2s"]
particle_flag_disable_z = true
emission_shape_scale = Vector3(17, 30, 1)
emission_shape = 1
emission_sphere_radius = 1.4
gravity = Vector3(0, 40, 0)
linear_accel_min = 3.0
linear_accel_max = 6.0
radial_accel_min = 2.81
radial_accel_max = 2.81
tangential_accel_min = -2.23517e-06
tangential_accel_max = -2.23517e-06
damping_min = 1.0
damping_max = 1.0
scale_min = 0.4
scale_max = 2.0
color = Color(1, 0, 0.0156863, 1)
color_ramp = SubResource("GradientTexture1D_uxnd3")
hue_variation_min = -2.23517e-08
hue_variation_max = 0.15
[node name="Player" type="CharacterBody2D"]
collision_layer = 2
script = ExtResource("1_lh8st")
[node name="GPUParticles2D" type="GPUParticles2D" parent="."]
position = Vector2(0, 34.515)
sub_emitter = NodePath(".")
process_material = SubResource("ParticleProcessMaterial_psy2s")
texture = ExtResource("2_m3c71")
lifetime = 0.3
[node name="PlayerImage" type="Sprite2D" parent="."]
texture = ExtResource("1_atygw")
@ -19,4 +55,10 @@ position = Vector2(0, -42)
[node name="LaserCooldown" type="Timer" parent="."]
wait_time = 0.5
[node name="LaserSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("3_t1lif")
[node name="DamageSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource("4_pi1bq")
[connection signal="timeout" from="LaserCooldown" to="." method="_on_laser_cooldown_timeout"]

View File

@ -59,3 +59,8 @@ laser={
"events": [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":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
[resource]
text_editor/behavior/indent/type=1
text_editor/behavior/indent/size=2