Преглед изворни кода

Implement transition when building new row

DricomDragon пре 3 година
родитељ
комит
eabdb3bb99
3 измењених фајлова са 27 додато и 6 уклоњено
  1. 6 0
      godot/scenes/main.tscn
  2. 19 5
      godot/scripts/Grid.gd
  3. 2 1
      godot/scripts/Launcher.gd

+ 6 - 0
godot/scenes/main.tscn

@@ -100,6 +100,11 @@ script = ExtResource( 6 )
 [node name="LifeContainer" type="Node2D" parent="Launcher/Grid"]
 script = ExtResource( 10 )
 
+[node name="MoveDown" type="Tween" parent="Launcher/Grid"]
+__meta__ = {
+"_editor_description_": "Move grid to show the new row"
+}
+
 [node name="TargetLine" type="RayCast2D" parent="Launcher"]
 position = Vector2( 200, 400 )
 collision_mask = 6
@@ -220,6 +225,7 @@ __meta__ = {
 [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="tween_all_completed" from="Launcher/Grid/MoveDown" to="Launcher/Grid" method="_on_MoveDown_tween_all_completed"]
 [connection signal="timeout" from="Launcher/ShootDelay" to="Launcher" method="_on_ShootDelay_timeout"]
 [connection signal="game_lost" from="Launcher/DeadLine" to="Launcher" method="_on_DeadLine_game_lost"]
 [connection signal="game_lost" from="Launcher/DeadLine" to="UI" method="_on_DeadLine_game_lost"]

+ 19 - 5
godot/scripts/Grid.gd

@@ -14,7 +14,11 @@ enum State {
 }
 
 
+export (float) var moving_time = 1.0
+
+
 onready var life_container = $LifeContainer
+onready var tween = $MoveDown
 
 
 var current_state = State.DONE
@@ -25,8 +29,7 @@ var current_row = 1
 func generate_and_move():
 	generate_row()
 	current_state = State.MOVING
-	move()
-	current_state = State.DONE
+	start_moving()
 
 
 func generate_row():
@@ -57,9 +60,17 @@ func break_cell(tile_pos):
 	emit_signal("kace_broken")
 
 
-func move():
+func start_moving():
 	current_row += 1
-	position.y += cell_size.y
+	tween.interpolate_property(self, "position", position,
+		position + Vector2(0, cell_size.y), moving_time,
+		Tween.TRANS_QUART, Tween.EASE_IN_OUT)
+	tween.start()
+
+
+func finish_moving():
+	current_state = State.DONE
+	emit_signal("has_moved")
 
 
 func _ready():
@@ -75,4 +86,7 @@ func _on_Ball_kace_contact(contact_pos:Vector2):
 
 func _on_Launcher_is_full():
 	generate_and_move()
-	emit_signal("has_moved")
+
+
+func _on_MoveDown_tween_all_completed():
+	finish_moving()

+ 2 - 1
godot/scripts/Launcher.gd

@@ -101,7 +101,7 @@ func die():
 func _on_ShootDelay_timeout():
 	shoot()
 	nbAmmo -= 1
-	if (nbAmmo == 0):
+	if (nbAmmo <= 0):
 		current_state = State.WAITING
 	else:
 		emit_signal("get_firing")
@@ -122,6 +122,7 @@ func _on_Grid_has_moved():
 
 
 func _on_Grid_kace_broken():
+	print("new bullet")
 	gain_new_bullet()