diff --git a/src/game/level.gd b/src/game/level.gd index 3e81c09..fc8bdad 100644 --- a/src/game/level.gd +++ b/src/game/level.gd @@ -97,6 +97,7 @@ func get_total_distance(): func game_over(): running = false + player.dead = true $player/death_sound.play() print_debug("final score: ", get_total_distance()) await get_tree().create_timer(3).timeout diff --git a/src/game/player_controller.gd b/src/game/player_controller.gd index 73cfaa7..d8c38d1 100644 --- a/src/game/player_controller.gd +++ b/src/game/player_controller.gd @@ -25,6 +25,7 @@ extends StaticBody2D # variables var momentum: Vector2 #var direction = 0 # 1 for forward, 0 for standing still, -1 for reverse +var dead = false signal speed_changed(new_speed) @@ -35,46 +36,48 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - var acc_d = acc * delta - var dec_d = dec * delta - var rev_d = rev * delta - var turn_d = turn_speed * delta - var brake_d = brake_strength * delta - var turn_factor = 1 - - if momentum.length() > dec_d: - momentum -= momentum.normalized()*dec_d - else: - momentum = Vector2(0,0) - - if Input.is_action_pressed("accelerate"): - momentum += acc_d * Vector2(1,0).rotated(rotation) - -# if Input.is_action_pressed("reverse"): -# print_debug("reverse vector: ", rev_d * Vector2(-1,0).rotated(rotation)) -# momentum += rev_d * Vector2(-1,0).rotated(rotation) -# print_debug("momentum vector = ", momentum) - - if Input.is_action_pressed("brake"): - turn_factor = drift_factor - if momentum.length() > brake_d: - momentum -= momentum.normalized() * brake_d + if !dead: + var acc_d = acc * delta + var dec_d = dec * delta + var rev_d = rev * delta + var turn_d = turn_speed * delta + var brake_d = brake_strength * delta + var turn_factor = 1 + + if momentum.length() > dec_d: + momentum -= momentum.normalized()*dec_d else: momentum = Vector2(0,0) - - if Input.is_action_pressed("left"): - rotate(turn_d*turn_factor*-1) - if Input.is_action_pressed("right"): - rotate(turn_d*turn_factor) - if !Input.is_action_pressed("brake"): - momentum = Vector2(1,0).rotated(rotation) * momentum.length() - - camera.position = Vector2(get_speed_proportion() * camera_offset, 0) - camera.rotation_degrees = momentum.angle() + 90 - - $engine_sounds.pitch_scale = get_speed_proportion() + .2 - + if Input.is_action_pressed("accelerate"): + momentum += acc_d * Vector2(1,0).rotated(rotation) + + # if Input.is_action_pressed("reverse"): + # print_debug("reverse vector: ", rev_d * Vector2(-1,0).rotated(rotation)) + # momentum += rev_d * Vector2(-1,0).rotated(rotation) + # print_debug("momentum vector = ", momentum) + + if Input.is_action_pressed("brake"): + turn_factor = drift_factor + if momentum.length() > brake_d: + momentum -= momentum.normalized() * brake_d + else: + momentum = Vector2(0,0) + + if Input.is_action_pressed("left"): + rotate(turn_d*turn_factor*-1) + if Input.is_action_pressed("right"): + rotate(turn_d*turn_factor) + + if !Input.is_action_pressed("brake"): + momentum = Vector2(1,0).rotated(rotation) * momentum.length() + + camera.position = Vector2(get_speed_proportion() * camera_offset, 0) + camera.rotation_degrees = momentum.angle() + 90 + + $engine_sounds.pitch_scale = get_speed_proportion() + .2 + else: + rotate(PI*delta) if momentum.length() > max_speed: momentum = momentum.normalized() * max_speed speed_changed.emit(momentum.length())