Added death "animation"

This commit is contained in:
KingGurke 2023-10-01 21:22:37 +02:00
parent 40cec00116
commit 131f2472b7
2 changed files with 41 additions and 37 deletions

View file

@ -97,6 +97,7 @@ func get_total_distance():
func game_over(): func game_over():
running = false running = false
player.dead = true
$player/death_sound.play() $player/death_sound.play()
print_debug("final score: ", get_total_distance()) print_debug("final score: ", get_total_distance())
await get_tree().create_timer(3).timeout await get_tree().create_timer(3).timeout

View file

@ -25,6 +25,7 @@ extends StaticBody2D
# variables # variables
var momentum: Vector2 var momentum: Vector2
#var direction = 0 # 1 for forward, 0 for standing still, -1 for reverse #var direction = 0 # 1 for forward, 0 for standing still, -1 for reverse
var dead = false
signal speed_changed(new_speed) signal speed_changed(new_speed)
@ -35,6 +36,7 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if !dead:
var acc_d = acc * delta var acc_d = acc * delta
var dec_d = dec * delta var dec_d = dec * delta
var rev_d = rev * delta var rev_d = rev * delta
@ -50,10 +52,10 @@ func _process(delta):
if Input.is_action_pressed("accelerate"): if Input.is_action_pressed("accelerate"):
momentum += acc_d * Vector2(1,0).rotated(rotation) momentum += acc_d * Vector2(1,0).rotated(rotation)
# if Input.is_action_pressed("reverse"): # if Input.is_action_pressed("reverse"):
# print_debug("reverse vector: ", rev_d * Vector2(-1,0).rotated(rotation)) # print_debug("reverse vector: ", rev_d * Vector2(-1,0).rotated(rotation))
# momentum += rev_d * Vector2(-1,0).rotated(rotation) # momentum += rev_d * Vector2(-1,0).rotated(rotation)
# print_debug("momentum vector = ", momentum) # print_debug("momentum vector = ", momentum)
if Input.is_action_pressed("brake"): if Input.is_action_pressed("brake"):
turn_factor = drift_factor turn_factor = drift_factor
@ -74,7 +76,8 @@ func _process(delta):
camera.rotation_degrees = momentum.angle() + 90 camera.rotation_degrees = momentum.angle() + 90
$engine_sounds.pitch_scale = get_speed_proportion() + .2 $engine_sounds.pitch_scale = get_speed_proportion() + .2
else:
rotate(PI*delta)
if momentum.length() > max_speed: if momentum.length() > max_speed:
momentum = momentum.normalized() * max_speed momentum = momentum.normalized() * max_speed
speed_changed.emit(momentum.length()) speed_changed.emit(momentum.length())