Quellcode durchsuchen

Slow down liner when drifting

DricomDragon vor 3 Jahren
Ursprung
Commit
d3dc7e1333
3 geänderte Dateien mit 47 neuen und 7 gelöschten Zeilen
  1. 4 2
      godot/Scenes/Player.tscn
  2. 16 2
      godot/Scripts/CharTween.gd
  3. 27 3
      godot/Scripts/Player.gd

+ 4 - 2
godot/Scenes/Player.tscn

@@ -36,8 +36,10 @@ __meta__ = {
 
 [node name="Tween" type="Tween" parent="."]
 script = ExtResource( 2 )
-[connection signal="arena_removed" from="." to="Liner" method="show"]
 [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="Liner" method="hide"]
 [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"]

+ 16 - 2
godot/Scripts/CharTween.gd

@@ -2,12 +2,26 @@ extends Tween
 # Drive moves for player
 
 export var default_duration = 0.1
+export var drift_duration = 0.2
+
+var current_duration = default_duration
+
 
 func connect_into(o):
 	connect("tween_completed", o, "_on_tween_completed")
 
-func move_char(c, target, duration = default_duration):
+
+func move_char(c, target, duration = current_duration):
 	interpolate_property(c, "position", c.get_position(), target, duration, Tween.TRANS_LINEAR, Tween.EASE_OUT_IN)
 
-func rotate_char(c, from, to, duration = default_duration):
+
+func rotate_char(c, from, to, duration = current_duration):
 	interpolate_property(c, "rotation_degrees", from, to, duration, Tween.TRANS_LINEAR, Tween.EASE_OUT)
+
+
+func _on_Player_drift_started():
+	current_duration = drift_duration
+
+
+func _on_Player_drift_ended():
+	current_duration = default_duration

+ 27 - 3
godot/Scripts/Player.gd

@@ -3,6 +3,8 @@ extends Area2D
 
 signal crash
 signal arena_removed
+signal drift_started
+signal drift_ended
 
 enum Direction {
 	UP = 0
@@ -22,6 +24,7 @@ const LEVEL_SPAWN_DURATION = 2
 
 # State
 var running = false
+var drifting = false
 var landed = false
 
 # Movement
@@ -131,7 +134,7 @@ func prepare_turn(left_or_right:int):
 
 
 func can_turn():
-	return dire_delta != 0 and !has_block_on(dire_delta)
+	return !has_block_on(dire_delta)
 
 
 func apply_turn():
@@ -157,14 +160,32 @@ func apply_turn():
 		push_error("dire out of range")
 
 
+func apply_drift():
+	if !drifting:
+		drifting = true
+		emit_signal("drift_started")
+
+
+func end_drift():
+	if drifting:
+		drifting = false
+		emit_signal("drift_ended")
+
+
 func move():
 	if !running:
 		return
 
 	generate_wall()
 
-	if can_turn():
-		apply_turn()
+	if is_transversal():
+		if can_turn():
+			end_drift()
+			apply_turn()
+		else:
+			apply_drift()
+	else:
+		end_drift()
 
 	go_forward()
 
@@ -202,3 +223,6 @@ func run():
 
 func is_running():
 	return running
+
+func is_transversal():
+	return dire_delta != 0