aboutsummaryrefslogblamecommitdiffstats
path: root/Scripts/drawing.gd
blob: d47e1617d7879fd64e408c001d8c7153f60ada36 (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                   
                         
                
                



                         
                         

                                                      








                                                                    

                                                                                      
                                       








                                                 


                                                      
                                                    
extends Node

var drawing = false
var driving_progress = -1
var line: Line2D
var path: Path2D


func _ready():
	line = $TrackLine
	path = $TrackPath
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

func _process(delta):
	pass

func _physics_process(delta):
	if driving_progress >= 0:
		driving_progress += delta*200
		$TrackPath/TrackFollower.progress = driving_progress
		#print(driving_progress)

func _input(event):
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		drawing = event.pressed
		if drawing:
			# start a new drawing
			line.clear_points()
			path.curve.clear_points()
			driving_progress = -1
		else:
			# start driving
			driving_progress = 0
	
	if event is InputEventMouseMotion and drawing:
		# extend the line
		line.add_point(event.position)
		path.curve.add_point(event.position)