final lesson 9
This commit is contained in:
3
level.gd
3
level.gd
@@ -20,7 +20,6 @@ func _ready():
|
|||||||
star.speed_scale = rng.randf_range(0.5,2)
|
star.speed_scale = rng.randf_range(0.5,2)
|
||||||
$Stars.add_child(star)
|
$Stars.add_child(star)
|
||||||
|
|
||||||
|
|
||||||
func _on_meteor_timer_timeout() -> void:
|
func _on_meteor_timer_timeout() -> void:
|
||||||
var meteor = meteor_scene.instantiate()
|
var meteor = meteor_scene.instantiate()
|
||||||
$Meteors.add_child(meteor)
|
$Meteors.add_child(meteor)
|
||||||
@@ -28,6 +27,7 @@ func _on_meteor_timer_timeout() -> void:
|
|||||||
meteor.connect('collision',_on_meteor_collision)
|
meteor.connect('collision',_on_meteor_collision)
|
||||||
|
|
||||||
func _on_meteor_collision():
|
func _on_meteor_collision():
|
||||||
|
$Player.play_collision_sound()
|
||||||
health -= 1
|
health -= 1
|
||||||
get_tree().call_group('ui','set_health',health)
|
get_tree().call_group('ui','set_health',health)
|
||||||
if health == 0:
|
if health == 0:
|
||||||
@@ -37,4 +37,3 @@ func _on_player_laser(pos) -> void:
|
|||||||
var laser = laser_scene.instantiate()
|
var laser = laser_scene.instantiate()
|
||||||
$Lasers.add_child(laser)
|
$Lasers.add_child(laser)
|
||||||
laser.position = pos
|
laser.position = pos
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ extends Area2D
|
|||||||
|
|
||||||
var velocity
|
var velocity
|
||||||
var angular_velocity
|
var angular_velocity
|
||||||
|
var can_collide : bool = true
|
||||||
|
|
||||||
signal collision
|
signal collision
|
||||||
|
|
||||||
@@ -30,10 +31,15 @@ func _process(delta):
|
|||||||
rotation += angular_velocity * delta
|
rotation += angular_velocity * delta
|
||||||
|
|
||||||
func _on_body_entered(body:Node2D) -> void:
|
func _on_body_entered(body:Node2D) -> void:
|
||||||
|
if can_collide:
|
||||||
collision.emit()
|
collision.emit()
|
||||||
|
|
||||||
|
|
||||||
func _on_area_entered(area: Area2D) -> void:
|
func _on_area_entered(area: Area2D) -> void:
|
||||||
Global.score += 150
|
Global.score += 150
|
||||||
area.queue_free()
|
area.queue_free()
|
||||||
|
$ExplosionSound.play()
|
||||||
|
$Sprite.hide()
|
||||||
|
can_collide = false
|
||||||
|
await get_tree().create_timer(0.5).timeout
|
||||||
queue_free()
|
queue_free()
|
||||||
|
@@ -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="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="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"]
|
[node name="Meteor" type="Area2D"]
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
@@ -14,5 +15,8 @@ texture = ExtResource("1_m5pls")
|
|||||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
|
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
|
||||||
polygon = PackedVector2Array(-33, -40, 23, -40, 48, -1, 34, 31, 10, 29, -23, 40, -50, 10)
|
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="area_entered" from="." to="." method="_on_area_entered"]
|
||||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
@@ -21,7 +21,10 @@ func _process(_delta: float) -> void:
|
|||||||
laser.emit($LaserSpawnPos.global_position)
|
laser.emit($LaserSpawnPos.global_position)
|
||||||
canShoot = false
|
canShoot = false
|
||||||
$LaserCooldown.start()
|
$LaserCooldown.start()
|
||||||
|
$LaserSound.play()
|
||||||
|
|
||||||
func _on_laser_cooldown_timeout() -> void:
|
func _on_laser_cooldown_timeout() -> void:
|
||||||
canShoot = true
|
canShoot = true
|
||||||
|
|
||||||
|
func play_collision_sound() -> void:
|
||||||
|
$DamageSound.play()
|
||||||
|
44
player.tscn
44
player.tscn
@@ -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="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="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"]
|
[node name="Player" type="CharacterBody2D"]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
script = ExtResource("1_lh8st")
|
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="."]
|
[node name="PlayerImage" type="Sprite2D" parent="."]
|
||||||
texture = ExtResource("1_atygw")
|
texture = ExtResource("1_atygw")
|
||||||
|
|
||||||
@@ -19,4 +55,10 @@ position = Vector2(0, -42)
|
|||||||
[node name="LaserCooldown" type="Timer" parent="."]
|
[node name="LaserCooldown" type="Timer" parent="."]
|
||||||
wait_time = 0.5
|
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"]
|
[connection signal="timeout" from="LaserCooldown" to="." method="_on_laser_cooldown_timeout"]
|
||||||
|
@@ -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)
|
"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
|
||||||
|
Reference in New Issue
Block a user