diff options
-rw-r--r-- | Nodes/Level_test.tscn | 5 | ||||
-rw-r--r-- | Nodes/Level_test_2.tscn | 71 | ||||
-rw-r--r-- | Nodes/ui.tscn | 20 | ||||
-rw-r--r-- | Scripts/drawing.gd | 11 | ||||
-rw-r--r-- | Scripts/game.gd | 38 | ||||
-rw-r--r-- | Scripts/scene_control.gd | 34 |
6 files changed, 132 insertions, 47 deletions
diff --git a/Nodes/Level_test.tscn b/Nodes/Level_test.tscn index 80330fd..05fbf4b 100644 --- a/Nodes/Level_test.tscn +++ b/Nodes/Level_test.tscn @@ -17,6 +17,8 @@ radius = 18.0278 [node name="Level_test" type="Node2D"] script = ExtResource("1_0esj3") +[node name="UI" parent="." instance=ExtResource("8_8u1ba")] + [node name="Start" type="TextureButton" parent="."] offset_left = 787.0 offset_top = 514.0 @@ -66,7 +68,4 @@ position = Vector2(285, 479) [node name="Checkpoint3" parent="Checkpoints" instance=ExtResource("7_52mhf")] position = Vector2(517, 172) -[node name="UI" parent="." instance=ExtResource("8_8u1ba")] - -[connection signal="pressed" from="Start" to="DrawNode" method="_start_drawing"] [connection signal="mouse_entered" from="FinishLine/Area2D" to="DrawNode" method="_end_drawing"] diff --git a/Nodes/Level_test_2.tscn b/Nodes/Level_test_2.tscn new file mode 100644 index 0000000..3ea0ac4 --- /dev/null +++ b/Nodes/Level_test_2.tscn @@ -0,0 +1,71 @@ +[gd_scene load_steps=11 format=3 uid="uid://b7nxnsf8dirqk"] + +[ext_resource type="Script" path="res://Scripts/scene_control.gd" id="1_amd1r"] +[ext_resource type="PackedScene" uid="uid://c8r6i3bu37ogu" path="res://Nodes/ui.tscn" id="2_veexm"] +[ext_resource type="Texture2D" uid="uid://5xqahgawme4m" path="res://Assets/start.png" id="3_sl2tq"] +[ext_resource type="Texture2D" uid="uid://b8vhe5kt6037n" path="res://Assets/end.png" id="4_1x7qu"] +[ext_resource type="PackedScene" uid="uid://c1mvbh2fwqtkb" path="res://Nodes/car.tscn" id="5_vbxx6"] +[ext_resource type="Script" path="res://Scripts/drawing.gd" id="6_6cnd6"] +[ext_resource type="Texture2D" uid="uid://dg3v488vx0oj6" path="res://Assets/checkpoint.png" id="7_alupw"] +[ext_resource type="PackedScene" uid="uid://wkfai2lvnp7n" path="res://Nodes/checkpoint.tscn" id="8_8dt61"] + +[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_amd1r") + +[node name="UI" parent="." instance=ExtResource("2_veexm")] + +[node name="Start" type="TextureButton" parent="."] +offset_left = 329.0 +offset_top = 574.0 +offset_right = 361.0 +offset_bottom = 606.0 +texture_normal = ExtResource("3_sl2tq") + +[node name="FinishLine" type="Sprite2D" parent="."] +position = Vector2(694, 598) +texture = ExtResource("4_1x7qu") + +[node name="Area2D" type="Area2D" parent="FinishLine"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="FinishLine/Area2D"] +shape = SubResource("CircleShape2D_6g88q") + +[node name="Car" parent="." instance=ExtResource("5_vbxx6")] +max_speed = 500 +acceleration = 0.05 + +[node name="DrawNode" type="Node2D" parent="."] +script = ExtResource("6_6cnd6") + +[node name="TrackLine" type="Line2D" parent="DrawNode"] + +[node name="TrackPath" type="Path2D" parent="DrawNode"] +curve = SubResource("Curve2D_0exre") + +[node name="TrackFollower" type="PathFollow2D" parent="DrawNode/TrackPath"] + +[node name="Sprite2D" type="Sprite2D" parent="DrawNode/TrackPath/TrackFollower"] +scale = Vector2(0.604, 0.604) +texture = ExtResource("7_alupw") + +[node name="31005" type="Timer" parent="DrawNode/TrackPath/TrackFollower"] +wait_time = 0.2 +one_shot = true + +[node name="Checkpoints" type="Node" parent="."] + +[node name="Checkpoint" parent="Checkpoints" instance=ExtResource("8_8dt61")] +position = Vector2(1023, 342) + +[node name="Checkpoint2" parent="Checkpoints" instance=ExtResource("8_8dt61")] +position = Vector2(113, 279) + +[node name="Checkpoint3" parent="Checkpoints" instance=ExtResource("8_8dt61")] +position = Vector2(517, 172) + +[connection signal="mouse_entered" from="FinishLine/Area2D" to="DrawNode" method="_end_drawing"] diff --git a/Nodes/ui.tscn b/Nodes/ui.tscn index aabf0ff..fd035c2 100644 --- a/Nodes/ui.tscn +++ b/Nodes/ui.tscn @@ -18,6 +18,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 script = ExtResource("1_77hb8") [node name="InGameUI" type="Control" parent="Control"] @@ -27,6 +28,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +mouse_filter = 2 [node name="CurrentTime" type="Label" parent="Control/InGameUI"] layout_mode = 0 @@ -92,3 +94,21 @@ offset_bottom = 23.0 scale = Vector2(1, 1.02025) text = "0.00" label_settings = SubResource("LabelSettings_hw7sw") + +[node name="NextLevelButton" type="Button" parent="Control/PostGameUI"] +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.3 +anchor_top = 0.7 +anchor_right = 0.45 +anchor_bottom = 0.8 +text = "Next Level" + +[node name="RestartButton" type="Button" parent="Control/PostGameUI"] +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.55 +anchor_top = 0.7 +anchor_right = 0.7 +anchor_bottom = 0.8 +text = "Retry" diff --git a/Scripts/drawing.gd b/Scripts/drawing.gd index 18e2a6c..61896f9 100644 --- a/Scripts/drawing.gd +++ b/Scripts/drawing.gd @@ -9,11 +9,9 @@ func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) -func _start_drawing(): - line.clear_points() - path.curve.clear_points() +func start_drawing(): + reset() drawing = true - owner.set_driving(false) func _end_drawing(): @@ -25,3 +23,8 @@ func _input(event): if drawing and event is InputEventMouseMotion: line.add_point(event.position) path.curve.add_point(event.position) + + +func reset(): + line.clear_points() + path.curve.clear_points() diff --git a/Scripts/game.gd b/Scripts/game.gd index bacb709..3c4326f 100644 --- a/Scripts/game.gd +++ b/Scripts/game.gd @@ -10,7 +10,8 @@ var post_game = false var scenes = [ # preload("res://Nodes/levels/level1/level1.tscn"), # preload("res://Nodes/levels/level2/level2.tscn") - preload("res://Nodes/Level_test.tscn") + preload("res://Nodes/Level_test.tscn"), + preload("res://Nodes/Level_test_2.tscn") ] # Called when the node enters the scene tree for the first time. @@ -22,7 +23,6 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): if Input.is_action_just_pressed("ui_cancel"): - close_scoreboard() get_tree().paused = true $PausePopup.show() Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) @@ -33,7 +33,6 @@ func _on_QuitButton_pressed(): func _on_ResumeButton_pressed(): - print('aaaa') $PausePopup.hide() get_tree().paused = false Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) @@ -45,31 +44,13 @@ func _on_MainMenuButton_pressed(): func end_level(): - open_scoreboard() # evaluate_player(current_strokes, PAR[current_level_id]) $BGMPLayer.stream_paused = true $JinglePlayer.play() post_game = true -func open_scoreboard(): -# strokes_per_level[current_level_id] = current_strokes -# $Scoreboard.update_values(strokes_per_level, PAR) -# $Scoreboard.show() - pass - - -func close_scoreboard(): -# $Scoreboard.hide() - pass - - -func is_post_game(): - return post_game - - func next_level(): - post_game = false current_level_id += 1 if current_level_id >= NUM_LEVELS: @@ -77,20 +58,9 @@ func next_level(): return load_scene_by_index(current_level_id) - close_scoreboard() - $Evaluation.hide() - $BGMPLayer.stream_paused = false - $JinglePlayer.stop() - - -func evaluate_player(strokes, par): - $Evaluation/EvaluationLabel.text = "%d Seconds" % 42 - $Evaluation.show() - - -func _on_JinglePlayer_finished(): - $BGMPLayer.stream_paused = false + # $BGMPLayer.stream_paused = false + # $JinglePlayer.stop() func load_scene_by_index(index): diff --git a/Scripts/scene_control.gd b/Scripts/scene_control.gd index d01342f..7f0ba5e 100644 --- a/Scripts/scene_control.gd +++ b/Scripts/scene_control.gd @@ -7,23 +7,30 @@ class_name SceneControl @onready var car = $Car @onready var checkpoints = $Checkpoints.get_children() @onready var ui = $UI/Control -@onready var start = $Start - -var finish_line: Area2D +@onready var drawing = $DrawNode var is_driving = false var current_time = 0.0 +var game_control +var start + func _ready(): - finish_line = $FinishLine/Area2D as Area2D - finish_line.body_entered.connect(_on_finish_line_body_entered) + game_control = get_tree().root.get_child(0) + + $FinishLine/Area2D.body_entered.connect(_on_finish_line_body_entered) + $UI/Control/PostGameUI/RestartButton.pressed.connect(reset_level) + $UI/Control/PostGameUI/NextLevelButton.pressed.connect(next_level) + + start = $Start as TextureButton + start.pressed.connect(start_drawing) + reset_level() func _physics_process(delta): if car.driving: current_time += delta - print(current_time) ui.update_timer_label(current_time) @@ -43,12 +50,17 @@ func set_driving(driving: bool): func reset_level(): ui.update_timer_label(-1) + ui.switch_to_in_game_UI() + + $DrawNode.reset() for cp in checkpoints: cp.set_was_visited(false) car.global_position = start.global_position car.global_rotation = start.rotation; + + set_driving(false) func start_driving(): current_time = 0.0 @@ -64,6 +76,16 @@ func evaluate_driving(): func _on_finish_line_body_entered(node: Node2D): if evaluate_driving(): ui.switch_to_post_game_UI() + set_driving(false) + return set_driving(false) reset_level() + +func next_level(): + game_control.next_level() + + +func start_drawing(): + reset_level() + drawing.start_drawing() |