Browse Source

Connect mover signal to player from the editor

And rename generic name tween to more specific name mover.
DricomDragon 3 years ago
parent
commit
994465959b
3 changed files with 15 additions and 20 deletions
  1. 4 3
      godot/Scenes/Player.tscn
  2. 0 4
      godot/Scripts/CharTween.gd
  3. 11 13
      godot/Scripts/Player.gd

+ 4 - 3
godot/Scenes/Player.tscn

@@ -34,12 +34,13 @@ __meta__ = {
 "_edit_lock_": true
 }
 
-[node name="Tween" type="Tween" parent="."]
+[node name="Mover" type="Tween" parent="."]
 script = ExtResource( 2 )
 [connection signal="arena_removed" from="." to="Crash" method="hide"]
 [connection signal="arena_removed" from="." to="Liner" method="show"]
 [connection signal="body_entered" from="." to="." method="_on_crash"]
 [connection signal="crash" from="." to="Crash" method="show"]
 [connection signal="crash" from="." to="Liner" method="hide"]
-[connection signal="drift_ended" from="." to="Tween" method="_on_Player_drift_ended"]
-[connection signal="drift_started" from="." to="Tween" method="_on_Player_drift_started"]
+[connection signal="drift_ended" from="." to="Mover" method="_on_Player_drift_ended"]
+[connection signal="drift_started" from="." to="Mover" method="_on_Player_drift_started"]
+[connection signal="tween_completed" from="Mover" to="." method="_on_move_completed"]

+ 0 - 4
godot/Scripts/CharTween.gd

@@ -11,10 +11,6 @@ var current_duration = default_duration
 var current_bonus = 0.0
 
 
-func connect_into(o):
-	connect("tween_completed", o, "_on_tween_completed")
-
-
 func move_char(character, target):
 	move_char_during(character, target, get_computed_duration())
 

+ 11 - 13
godot/Scripts/Player.gd

@@ -45,15 +45,13 @@ var turn_right_action:String
 
 var grid:TileMap
 
-onready var tween = $Tween
+onready var mover = $Mover
 
 
 func _ready():
 	assert(turn_left_action)
 	assert(turn_right_action)
 
-	tween.connect_into(self)
-
 
 func _unhandled_input(event):
 	if event.is_pressed():
@@ -80,7 +78,7 @@ func _on_arena_removed():
 	emit_signal("arena_removed")
 
 
-func _on_tween_completed(_o, key):
+func _on_move_completed(_o, key):
 	if (key == ":position"):
 		move()
 
@@ -103,9 +101,9 @@ func spawn(newGrid, newPosition, newOrientation):
 	apply_turn()
 
 	# Animate spawning
-	tween.rotate_char_during(self, rotation_degrees, newOrientation, LEVEL_SPAWN_DURATION)
-	tween.move_char_during(self, newPosition, LEVEL_SPAWN_DURATION)
-	tween.start()
+	mover.rotate_char_during(self, rotation_degrees, newOrientation, LEVEL_SPAWN_DURATION)
+	mover.move_char_during(self, newPosition, LEVEL_SPAWN_DURATION)
+	mover.start()
 
 
 func generate_wall():
@@ -129,8 +127,8 @@ func prepare_turn(left_or_right:int):
 
 	var aim_angle = current_angle + 90 * left_or_right
 
-	tween.rotate_char(self, current_angle, aim_angle)
-	tween.start()
+	mover.rotate_char(self, current_angle, aim_angle)
+	mover.start()
 
 
 func can_turn():
@@ -179,11 +177,11 @@ func apply_wall_boost():
 	if has_block_on(Side.RIGHT):
 		n += 1
 
-	tween.set_boost(n)
+	mover.set_boost(n)
 
 
 func end_wall_boost():
-	tween.set_boost(0)
+	mover.set_boost(0)
 
 
 func move():
@@ -211,8 +209,8 @@ func go_forward():
 	posiy += diry
 
 	target_pos = Vector2(posix * cell_size + cell_half_size, posiy * cell_size + cell_half_size)
-	tween.move_char(self, target_pos)
-	tween.start()
+	mover.move_char(self, target_pos)
+	mover.start()
 
 
 func has_block_on(left_or_right:int):