diff options
author | perivesta <> | 2023-07-08 16:13:25 +0200 |
---|---|---|
committer | perivesta <> | 2023-07-08 16:13:25 +0200 |
commit | d98cee8592e15f23ce85e8d54abb29aa341c97da (patch) | |
tree | f9b2301818438fa1903650f8c47c7464aae109db | |
parent | 9573d3ae4170f43f7f65224a16db7ad161a11e28 (diff) | |
download | 2023-d98cee8592e15f23ce85e8d54abb29aa341c97da.tar.gz 2023-d98cee8592e15f23ce85e8d54abb29aa341c97da.tar.bz2 2023-d98cee8592e15f23ce85e8d54abb29aa341c97da.zip |
start drawing when clicking on start. end at finish
-rw-r--r-- | Nodes/Level_test.tscn | 30 | ||||
-rw-r--r-- | Scripts/drawing.gd | 28 |
2 files changed, 37 insertions, 21 deletions
diff --git a/Nodes/Level_test.tscn b/Nodes/Level_test.tscn index 1928496..18a1a1a 100644 --- a/Nodes/Level_test.tscn +++ b/Nodes/Level_test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=3 uid="uid://ct2kxw1rrjryo"] +[gd_scene load_steps=9 format=3 uid="uid://ct2kxw1rrjryo"] [ext_resource type="Script" path="res://Scripts/scene_control.gd" id="1_0esj3"] [ext_resource type="Texture2D" uid="uid://5xqahgawme4m" path="res://Assets/start.png" id="1_wenkl"] @@ -7,29 +7,40 @@ [ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="4_xvobs"] [ext_resource type="Script" path="res://Scripts/drawing.gd" id="5_x7h3g"] +[sub_resource type="CircleShape2D" id="CircleShape2D_6g88q"] +radius = 18.0278 + [sub_resource type="Curve2D" id="Curve2D_0exre"] [node name="Level_test" type="Node2D"] script = ExtResource("1_0esj3") -[node name="Start" type="Sprite2D" parent="."] -position = Vector2(669, 515) -texture = ExtResource("1_wenkl") +[node name="start" type="TextureButton" parent="."] +offset_left = 787.0 +offset_top = 514.0 +offset_right = 819.0 +offset_bottom = 546.0 +texture_normal = ExtResource("1_wenkl") [node name="End" type="Sprite2D" parent="."] -position = Vector2(616, 86) +position = Vector2(793, 96) texture = ExtResource("2_gp6ng") +[node name="Area2D" type="Area2D" parent="End"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="End/Area2D"] +shape = SubResource("CircleShape2D_6g88q") + [node name="cp1" type="Sprite2D" parent="."] -position = Vector2(270, 338) +position = Vector2(283, 479) texture = ExtResource("3_cgigr") [node name="cp2" type="Sprite2D" parent="."] -position = Vector2(621, 323) +position = Vector2(618, 354) texture = ExtResource("3_cgigr") [node name="cp3" type="Sprite2D" parent="."] -position = Vector2(404, 145) +position = Vector2(514, 173) texture = ExtResource("3_cgigr") [node name="Car" parent="." instance=ExtResource("4_xvobs")] @@ -53,3 +64,6 @@ texture = ExtResource("3_cgigr") [node name="31005" type="Timer" parent="DrawNode/TrackPath/TrackFollower"] wait_time = 0.2 one_shot = true + +[connection signal="pressed" from="start" to="DrawNode" method="_start_drawing"] +[connection signal="mouse_entered" from="End/Area2D" to="DrawNode" method="_end_drawing"] diff --git a/Scripts/drawing.gd b/Scripts/drawing.gd index 2e4af95..51e7f21 100644 --- a/Scripts/drawing.gd +++ b/Scripts/drawing.gd @@ -14,19 +14,21 @@ func _process(delta): func _physics_process(delta): pass + +func _start_drawing(): + line.clear_points() + path.curve.clear_points() + drawing = true + owner.set_driving(false) + + +func _end_drawing(): + drawing = false + owner.set_driving(true) + + 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() - owner.set_driving(false) - else: - # start driving - owner.set_driving(true) - - if event is InputEventMouseMotion and drawing: - # extend the line + if drawing and event is InputEventMouseMotion: line.add_point(event.position) path.curve.add_point(event.position) + |