Просмотр исходного кода

Add deadline to make game over work

DricomDragon 3 лет назад
Родитель
Сommit
7a13c82a33
3 измененных файлов с 35 добавлено и 2 удалено
  1. 10 1
      godot/scenes/main.tscn
  2. 15 0
      godot/scripts/DeadLine.gd
  3. 10 1
      godot/scripts/UI.gd

+ 10 - 1
godot/scenes/main.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=17 format=2]
+[gd_scene load_steps=18 format=2]
 
 [ext_resource path="res://image/launcher.png" type="Texture" id=1]
 [ext_resource path="res://image/brik.png" type="Texture" id=2]
@@ -10,6 +10,7 @@
 [ext_resource path="res://scripts/BallCounterLabel.gd" type="Script" id=8]
 [ext_resource path="res://scripts/ScoreCounterLabel.gd" type="Script" id=9]
 [ext_resource path="res://scripts/LifeContainer.gd" type="Script" id=10]
+[ext_resource path="res://scripts/DeadLine.gd" type="Script" id=11]
 
 [sub_resource type="PhysicsMaterial" id=1]
 friction = 0.0
@@ -109,6 +110,12 @@ texture = ExtResource( 1 )
 wait_time = 0.1
 one_shot = true
 
+[node name="DeadLine" type="RayCast2D" parent="Launcher"]
+position = Vector2( 380, 390 )
+cast_to = Vector2( -360, 0 )
+collision_mask = 4
+script = ExtResource( 11 )
+
 [node name="UI" type="Control" parent="."]
 margin_right = 40.0
 margin_bottom = 40.0
@@ -203,6 +210,8 @@ __meta__ = {
 [connection signal="get_firing" from="Launcher" to="Launcher" method="_on_Launcher_get_firing"]
 [connection signal="is_full" from="Launcher" to="Launcher/Grid" method="_on_Launcher_is_full"]
 [connection signal="has_moved" from="Launcher/Grid" to="Launcher" method="_on_Grid_has_moved"]
+[connection signal="has_moved" from="Launcher/Grid" to="Launcher/DeadLine" method="_on_Grid_has_moved"]
 [connection signal="kace_broken" from="Launcher/Grid" to="Launcher" method="_on_Grid_kace_broken"]
 [connection signal="kace_damaged" from="Launcher/Grid" to="UI/ScorePanel/ScoreCounterLabel" method="_on_Grid_kace_damaged"]
 [connection signal="timeout" from="Launcher/ShootDelay" to="Launcher" method="_on_ShootDelay_timeout"]
+[connection signal="game_lost" from="Launcher/DeadLine" to="UI" method="_on_DeadLine_game_lost"]

+ 15 - 0
godot/scripts/DeadLine.gd

@@ -0,0 +1,15 @@
+extends RayCast2D
+
+
+signal game_lost
+
+
+func check_death():
+	force_raycast_update()
+	if is_colliding():
+		emit_signal("game_lost")
+
+
+func _on_Grid_has_moved():
+	check_death()
+	

+ 10 - 1
godot/scripts/UI.gd

@@ -2,5 +2,14 @@ extends Control
 
 onready var game_over_panel = $GameOverPanel
 
-func _on_Catcher_game_over():
+
+func show_end_of_game():
 	game_over_panel.show()
+
+
+func _on_Catcher_game_over():
+	show_end_of_game()
+
+
+func _on_DeadLine_game_lost():
+	show_end_of_game()