adds basic menu functionnality
This commit is contained in:
16
Player.gd
16
Player.gd
@@ -1,22 +1,24 @@
|
||||
extends PathFollow2D
|
||||
|
||||
signal lap_completed(laps)
|
||||
|
||||
export (float) var speed = 0.125
|
||||
|
||||
var position_on_track := 0.0
|
||||
var target_on_track := 0.0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
func _process(delta):
|
||||
# Check if a lap was completed
|
||||
if int(position_on_track) > Global.laps:
|
||||
Global.laps += 1
|
||||
emit_signal("lap_completed", Global.laps)
|
||||
|
||||
# Move the player until target_on_track
|
||||
if target_on_track - position_on_track > 0.01:
|
||||
elif target_on_track - position_on_track > 0.01:
|
||||
# Speed up car as the target_on_track goes further
|
||||
var speed_mod = int(clamp((target_on_track - position_on_track) / speed, 1.0, 4.0))
|
||||
position_on_track += speed * delta * speed_mod
|
||||
set_unit_offset(position_on_track)
|
||||
set_unit_offset(min(position_on_track, target_on_track))
|
||||
else:
|
||||
position_on_track = target_on_track
|
||||
|
||||
|
||||
Reference in New Issue
Block a user