diff --git a/Countdown.gd b/Countdown.gd index 5d05d69..7b7ece1 100644 --- a/Countdown.gd +++ b/Countdown.gd @@ -1,6 +1,6 @@ extends Node2D -signal race_started +signal completed() export (int) var delay = 3 var timer @@ -32,7 +32,7 @@ func _timeout(): elif time_left == 0: # Go ! $Number.set_text("GO") - emit_signal("race_started") + emit_signal("completed") else: $Number.set_text("%d" % time_left) \ No newline at end of file diff --git a/Global.gd b/Global.gd index c9bbc5c..ff3644d 100644 --- a/Global.gd +++ b/Global.gd @@ -1,5 +1,20 @@ extends Node +signal laps_changed(value) + +enum InputMode { MOUSE, KEYBOARD } +enum GameMode { TRAIN, EASY } +enum PlayerSkin { CAR, POLICE, BUS } var race_started = false -var laps = 0 \ No newline at end of file +var laps = 0 setget set_laps + +func set_laps(value): + laps = value + emit_signal("laps_changed", value) + +var settings = { + "input_mode": null, + "game_mode": null, + "player_skin": null, +} diff --git a/Gui.gd b/Gui.gd index d38aa23..679a974 100644 --- a/Gui.gd +++ b/Gui.gd @@ -4,7 +4,7 @@ onready var lap_counter = get_node("Laps/Value") # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + Global.connect("laps_changed", self, "_on_lap_completed") func _on_lap_completed(laps): lap_counter.set_text("%d" % laps) diff --git a/Main.gd b/Main.gd index 483b95a..a971be5 100644 --- a/Main.gd +++ b/Main.gd @@ -1,14 +1,20 @@ extends Node +func _ready(): + get_tree().paused = true + func start_game(): - print("Game starting") $Menu.set_visible(false) - yield($Countdown.start(), "race_started") - Global.race_started = true + if not Global.race_started: + print("Game starting") + Global.race_started = true + $GUI.set_visible(true) + yield($Countdown.start(), "completed") + get_tree().paused = false func pause_game(): $Menu.set_visible(true) - Global.race_started = false + get_tree().paused = true func _input(event): if event.is_action_pressed("ui_cancel"): diff --git a/Main.tscn b/Main.tscn index 94e4b06..0190665 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://Main.gd" type="Script" id=1] [ext_resource path="res://RaceTrack.tscn" type="PackedScene" id=2] [ext_resource path="res://Menu.tscn" type="PackedScene" id=3] [ext_resource path="res://Countdown.tscn" type="PackedScene" id=4] +[ext_resource path="res://Gui.tscn" type="PackedScene" id=5] +[ext_resource path="res://Gui.gd" type="Script" id=6] [node name="Main" type="Node"] script = ExtResource( 1 ) @@ -11,9 +13,14 @@ script = ExtResource( 1 ) [node name="RaceTrack" parent="." instance=ExtResource( 2 )] [node name="Menu" parent="." instance=ExtResource( 3 )] +pause_mode = 2 [node name="Countdown" parent="." instance=ExtResource( 4 )] +pause_mode = 2 visible = false delay = 3 + +[node name="GUI" parent="." instance=ExtResource( 5 )] +visible = false +script = ExtResource( 6 ) [connection signal="game_started" from="Menu" to="." method="start_game"] -[connection signal="track_changed" from="Menu" to="RaceTrack" method="_on_Menu_track_changed"] diff --git a/Menu.gd b/Menu.gd index e7a65dd..973fc86 100644 --- a/Menu.gd +++ b/Menu.gd @@ -1,57 +1,82 @@ extends Control signal game_started() -signal track_changed() signal skin_changed(skin) -enum Actions { PLAY, CHANGE_TRACK, QUIT } -var _focus = null setget _set_focus +enum Actions { + PLAY, + ENTER_OPTIONS, + EXIT_OPTIONS, + NEXT_TRACK, + PREV_TRACK, + # PREV_SKIN, + # NEXT_SKIN, + # PREV_INPUT_MODE, + # NEXT_INPUT_MODE, + # PREV_GAME_MODE, + # NEXT_GAME_MODE, + QUIT, + } +var actions = {} # Registered actions +var _focus = null # The node that has focus + -func _set_focus(value): - _focus = value - print("New focus: ", value) -# Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. + _connect_action("Main/Jouer", Actions.PLAY) + _connect_action("Main/Options", Actions.ENTER_OPTIONS) + _connect_action("Main/Quitter", Actions.QUIT) + + _connect_action("Options/Return", Actions.EXIT_OPTIONS) + _connect_action("Options/TrackSelection/LeftArrow", Actions.PREV_TRACK) + _connect_action("Options/TrackSelection/RightArrow", Actions.NEXT_TRACK) + + TrackSelection.connect("track_changed", self, "_on_track_changed") + _on_track_changed() -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass func _input(event): - if event is InputEventMouseButton: - if _focus != null: - if event.button_index == BUTTON_LEFT and event.pressed: - match _focus: - Actions.PLAY: - emit_signal("game_started") - Actions.CHANGE_TRACK: - emit_signal("track_changed") - Actions.QUIT: - get_tree().quit() + # TODO: Handle navigation + if event is InputEventMouseButton and _focus != null: + if event.button_index == BUTTON_LEFT and event.pressed: + match actions[_focus]: + Actions.PLAY: + emit_signal("game_started") + Actions.ENTER_OPTIONS: + $Main.set_visible(false) + $Options.set_visible(true) + Actions.EXIT_OPTIONS: + $Main.set_visible(true) + $Options.set_visible(false) + Actions.QUIT: + get_tree().quit() + Actions.PREV_TRACK: + TrackSelection.set_previous_track() + Actions.NEXT_TRACK: + TrackSelection.set_next_track() -func _on_Jouer_mouse_exited(): - get_node("Main/Jouer").set("custom_colors/font_color", Color.white) + +func _on_track_changed(): + get_node("Options/TrackSelection/Value").set_text(TrackSelection.get_current_track_name()) + + +func _connect_action(node_path, action): + var node = get_node(node_path) + node.connect("mouse_entered", self, "set_focus", [node]) + node.connect("mouse_exited", self, "leave_focus", [node]) + actions[node] = action + + +func set_focus(node): + _set_active(true, node) + _focus = node + + +func leave_focus(node): + _set_active(false, node) _focus = null -func _on_Jouer_mouse_entered(): - get_node("Main/Jouer").set("custom_colors/font_color", Color.orange) - _set_focus(Actions.PLAY) - -func _on_Options_mouse_exited(): - get_node("Main/Options").set("custom_colors/font_color", Color.white) - _focus = null - -func _on_Options_mouse_entered(): - get_node("Main/Options").set("custom_colors/font_color", Color.orange) - _set_focus(Actions.CHANGE_TRACK) - - -func _on_Quitter_mouse_entered(): - get_node("Main/Quitter").set("custom_colors/font_color", Color.orange) - _set_focus(Actions.QUIT) - -func _on_Quitter_mouse_exited(): - get_node("Main/Quitter").set("custom_colors/font_color", Color.white) - _focus = null \ No newline at end of file +func _set_active(is_active, node): + # Updates the focus effect for node + var color = Color.orange if is_active else Color.white + node.set("custom_colors/font_color", color) \ No newline at end of file diff --git a/Menu.tscn b/Menu.tscn index 494ef80..69375ff 100644 --- a/Menu.tscn +++ b/Menu.tscn @@ -32,6 +32,132 @@ custom_constants/shadow_offset_y = 3 custom_constants/shadow_as_outline = 0 text = "Car Racer" +[node name="Options" type="VBoxContainer" parent="."] +visible = false +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -250.169 +margin_top = -89.9366 +margin_right = 318.831 +margin_bottom = 421.063 + +[node name="TrackSelection" type="HBoxContainer" parent="Options"] +editor/display_folded = true +margin_right = 569.0 +margin_bottom = 66.0 +custom_constants/separation = 20 + +[node name="Label" type="Label" parent="Options/TrackSelection"] +margin_right = 326.0 +margin_bottom = 66.0 +custom_fonts/font = ExtResource( 3 ) +text = "Piste de course :" + +[node name="LeftArrow" type="Label" parent="Options/TrackSelection"] +margin_left = 346.0 +margin_right = 365.0 +margin_bottom = 66.0 +mouse_filter = 0 +custom_fonts/font = ExtResource( 3 ) +text = "<" + +[node name="Value" type="Label" parent="Options/TrackSelection"] +margin_left = 385.0 +margin_right = 495.0 +margin_bottom = 66.0 +custom_fonts/font = ExtResource( 3 ) +text = "Démo" + +[node name="RightArrow" type="Label" parent="Options/TrackSelection"] +margin_left = 515.0 +margin_right = 534.0 +margin_bottom = 66.0 +mouse_filter = 0 +custom_fonts/font = ExtResource( 3 ) +text = ">" + +[node name="GameMode" type="HBoxContainer" parent="Options"] +editor/display_folded = true +margin_top = 70.0 +margin_right = 569.0 +margin_bottom = 136.0 +custom_constants/separation = 20 + +[node name="Label" type="Label" parent="Options/GameMode"] +margin_right = 208.0 +margin_bottom = 66.0 +custom_fonts/font = ExtResource( 3 ) +text = "Difficulté :" + +[node name="LeftArrow" type="Label" parent="Options/GameMode"] +margin_left = 228.0 +margin_right = 247.0 +margin_bottom = 66.0 +mouse_filter = 0 +custom_fonts/font = ExtResource( 3 ) +text = "<" + +[node name="Value" type="Label" parent="Options/GameMode"] +margin_left = 267.0 +margin_right = 530.0 +margin_bottom = 66.0 +custom_fonts/font = ExtResource( 3 ) +text = "Entraînement" + +[node name="RightArrow" type="Label" parent="Options/GameMode"] +margin_left = 550.0 +margin_right = 569.0 +margin_bottom = 66.0 +mouse_filter = 0 +custom_fonts/font = ExtResource( 3 ) +text = ">" + +[node name="InputMode" type="HBoxContainer" parent="Options"] +editor/display_folded = true +margin_top = 140.0 +margin_right = 569.0 +margin_bottom = 206.0 +custom_constants/separation = 20 + +[node name="Label" type="Label" parent="Options/InputMode"] +margin_right = 235.0 +margin_bottom = 66.0 +custom_fonts/font = ExtResource( 3 ) +text = "Contrôleur :" + +[node name="LeftArrow" type="Label" parent="Options/InputMode"] +margin_left = 255.0 +margin_right = 274.0 +margin_bottom = 66.0 +mouse_filter = 0 +custom_fonts/font = ExtResource( 3 ) +text = "<" + +[node name="Value" type="Label" parent="Options/InputMode"] +margin_left = 294.0 +margin_right = 417.0 +margin_bottom = 66.0 +custom_fonts/font = ExtResource( 3 ) +text = "Souris" + +[node name="RightArrow" type="Label" parent="Options/InputMode"] +margin_left = 437.0 +margin_right = 456.0 +margin_bottom = 66.0 +mouse_filter = 0 +custom_fonts/font = ExtResource( 3 ) +text = ">" + +[node name="Return" type="Label" parent="Options"] +margin_top = 210.0 +margin_right = 569.0 +margin_bottom = 276.0 +mouse_filter = 0 +custom_fonts/font = ExtResource( 3 ) +text = "Retour" + [node name="Main" type="VBoxContainer" parent="."] anchor_left = 0.5 anchor_top = 0.5 @@ -82,19 +208,3 @@ custom_constants/shadow_offset_x = 2 custom_constants/shadow_offset_y = 3 text = "Quitter" align = 1 - -[node name="Options" type="VBoxContainer" parent="."] -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -margin_left = -20.0 -margin_top = -20.0 -margin_right = 20.0 -margin_bottom = 20.0 -[connection signal="mouse_entered" from="Main/Jouer" to="." method="_on_Jouer_mouse_entered"] -[connection signal="mouse_exited" from="Main/Jouer" to="." method="_on_Jouer_mouse_exited"] -[connection signal="mouse_entered" from="Main/Options" to="." method="_on_Options_mouse_entered"] -[connection signal="mouse_exited" from="Main/Options" to="." method="_on_Options_mouse_exited"] -[connection signal="mouse_entered" from="Main/Quitter" to="." method="_on_Quitter_mouse_entered"] -[connection signal="mouse_exited" from="Main/Quitter" to="." method="_on_Quitter_mouse_exited"] diff --git a/PlayerCar.tscn b/PlayerCar.tscn index ea2d755..b64329d 100644 --- a/PlayerCar.tscn +++ b/PlayerCar.tscn @@ -17,17 +17,17 @@ [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=15] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=16] [ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=17] -[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=18] -[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=19] -[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=20] -[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=21] -[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=22] -[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=23] -[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=24] -[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=25] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0000.png" type="Texture" id=18] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0001.png" type="Texture" id=19] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0002.png" type="Texture" id=20] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0003.png" type="Texture" id=21] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0004.png" type="Texture" id=22] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0005.png" type="Texture" id=23] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0006.png" type="Texture" id=24] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0007.png" type="Texture" id=25] [ext_resource path="res://CarSprite.gd" type="Script" id=26] -[sub_resource type="SpriteFrames" id=1] +[sub_resource type="SpriteFrames" id=6] animations = [ { "frames": [ ExtResource( 2 ), ExtResource( 3 ), ExtResource( 4 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ) ], "loop": true, @@ -56,6 +56,6 @@ __meta__ = { [node name="CarSprite" type="AnimatedSprite" parent="."] position = Vector2( -3.20422, 3.0376 ) scale = Vector2( 0.8, 0.8 ) -frames = SubResource( 1 ) +frames = SubResource( 6 ) animation = "car" script = ExtResource( 26 ) diff --git a/RaceTrack.gd b/RaceTrack.gd index d9b1489..993fde0 100644 --- a/RaceTrack.gd +++ b/RaceTrack.gd @@ -20,6 +20,7 @@ func get_track_offset(coords): # Called when the node enters the scene tree for the first time. func _ready(): + TrackSelection.connect("track_changed", self, "_reset_state") _reset_state() func _reset_state(): diff --git a/RaceTrack.tscn b/RaceTrack.tscn index 86ebdd5..a46dfff 100644 --- a/RaceTrack.tscn +++ b/RaceTrack.tscn @@ -1,40 +1,37 @@ -[gd_scene load_steps=41 format=2] +[gd_scene load_steps=39 format=2] [ext_resource path="res://RaceTrack.gd" type="Script" id=1] [ext_resource path="res://assets/track_tiles/track.png" type="Texture" id=2] [ext_resource path="res://TileMap.gd" type="Script" id=3] [ext_resource path="res://TrackPath.gd" type="Script" id=4] [ext_resource path="res://OpponentCar.gd" type="Script" id=5] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=6] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=7] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=8] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=9] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=10] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=11] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=12] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=13] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0007.png" type="Texture" id=14] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0004.png" type="Texture" id=15] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0001.png" type="Texture" id=16] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0002.png" type="Texture" id=17] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0003.png" type="Texture" id=18] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=19] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=20] -[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=21] -[ext_resource path="res://track1/policeCar/policeiso_0003.png" type="Texture" id=22] -[ext_resource path="res://track1/policeCar/policeiso_0004.png" type="Texture" id=23] -[ext_resource path="res://track1/policeCar/policeiso_0001.png" type="Texture" id=24] -[ext_resource path="res://track1/policeCar/policeiso_0002.png" type="Texture" id=25] -[ext_resource path="res://track1/policeCar/policeiso_0007.png" type="Texture" id=26] -[ext_resource path="res://track1/policeCar/policeiso_0000.png" type="Texture" id=27] -[ext_resource path="res://track1/policeCar/policeiso_0005.png" type="Texture" id=28] -[ext_resource path="res://track1/policeCar/policeiso_0006.png" type="Texture" id=29] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0007.png" type="Texture" id=6] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0004.png" type="Texture" id=7] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0001.png" type="Texture" id=8] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0002.png" type="Texture" id=9] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0003.png" type="Texture" id=10] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0000.png" type="Texture" id=11] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0005.png" type="Texture" id=12] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/bus/busiso_0006.png" type="Texture" id=13] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0003.png" type="Texture" id=14] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0004.png" type="Texture" id=15] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0001.png" type="Texture" id=16] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0002.png" type="Texture" id=17] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0007.png" type="Texture" id=18] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0000.png" type="Texture" id=19] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0005.png" type="Texture" id=20] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/car02/car02iso_0006.png" type="Texture" id=21] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0003.png" type="Texture" id=22] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0004.png" type="Texture" id=23] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0001.png" type="Texture" id=24] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0002.png" type="Texture" id=25] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0007.png" type="Texture" id=26] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0000.png" type="Texture" id=27] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0005.png" type="Texture" id=28] +[ext_resource path="res://assets/2D_Car_Pack_DevilsWorkShop_V01/policeCar/policeiso_0006.png" type="Texture" id=29] [ext_resource path="res://CarSprite.gd" type="Script" id=30] [ext_resource path="res://Player.gd" type="Script" id=31] -[ext_resource path="res://PlayerCar.tscn" type="PackedScene" id=32] -[ext_resource path="res://wrong_way.tscn" type="PackedScene" id=33] -[ext_resource path="res://Gui.tscn" type="PackedScene" id=34] -[ext_resource path="res://Gui.gd" type="Script" id=35] +[ext_resource path="res://wrong_way.tscn" type="PackedScene" id=32] [sub_resource type="Gradient" id=1] colors = PoolColorArray( 0.284025, 0.4375, 0.0803223, 1, 0.30305, 0.480469, 0.0675659, 1 ) @@ -117,19 +114,19 @@ width = 1920 [sub_resource type="Curve2D" id=4] _data = { -"points": PoolVector2Array( 0, 0, 0, 0, 606.951, 579.696, 0, 0, 0, 0, 755.584, 596.499 ) +"points": PoolVector2Array( 0, 0, 0, 0, 606.951, 579.696 ) } [sub_resource type="SpriteFrames" id=5] animations = [ { "frames": [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ], "loop": true, -"name": "car", +"name": "bus", "speed": 5.0 }, { "frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ], "loop": true, -"name": "bus", +"name": "car", "speed": 5.0 }, { "frames": [ ExtResource( 22 ), ExtResource( 23 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 26 ), ExtResource( 27 ), ExtResource( 28 ), ExtResource( 29 ) ], @@ -138,6 +135,24 @@ animations = [ { "speed": 5.0 } ] +[sub_resource type="SpriteFrames" id=6] +animations = [ { +"frames": [ ExtResource( 6 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 9 ), ExtResource( 10 ), ExtResource( 11 ), ExtResource( 12 ), ExtResource( 13 ) ], +"loop": true, +"name": "bus", +"speed": 5.0 +}, { +"frames": [ ExtResource( 14 ), ExtResource( 15 ), ExtResource( 16 ), ExtResource( 17 ), ExtResource( 18 ), ExtResource( 19 ), ExtResource( 20 ), ExtResource( 21 ) ], +"loop": true, +"name": "car", +"speed": 5.0 +}, { +"frames": [ ExtResource( 27 ), ExtResource( 24 ), ExtResource( 25 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 28 ), ExtResource( 29 ), ExtResource( 26 ) ], +"loop": true, +"name": "police", +"speed": 5.0 +} ] + [node name="RaceTrack" type="Node"] script = ExtResource( 1 ) @@ -160,7 +175,7 @@ script = ExtResource( 4 ) [node name="Opponent" type="PathFollow2D" parent="TrackPath"] position = Vector2( 606.951, 579.696 ) -rotation = 0.112561 +rotation = 0.112563 script = ExtResource( 5 ) [node name="OpponentCar" type="Node2D" parent="TrackPath/Opponent"] @@ -177,19 +192,21 @@ skin = "police" [node name="Player" type="PathFollow2D" parent="TrackPath"] position = Vector2( 606.951, 579.696 ) -rotation = 0.112561 +rotation = 0.112563 script = ExtResource( 31 ) -[node name="PlayerCar" parent="TrackPath/Player" instance=ExtResource( 32 )] +[node name="PlayerCar" type="Node2D" parent="TrackPath/Player"] position = Vector2( 1.89564, -22.3528 ) scale = Vector2( 0.25, 0.25 ) -script = null -[node name="Wrong Way" parent="." instance=ExtResource( 33 )] +[node name="CarSprite" type="AnimatedSprite" parent="TrackPath/Player/PlayerCar"] +position = Vector2( -3.20422, 3.0376 ) +scale = Vector2( 0.8, 0.8 ) +frames = SubResource( 6 ) +animation = "car" +script = ExtResource( 30 ) + +[node name="Wrong Way" parent="." instance=ExtResource( 32 )] visible = false - -[node name="GUI" parent="." instance=ExtResource( 34 )] -script = ExtResource( 35 ) [connection signal="player_moved" from="." to="TrackPath/Player" method="_on_RaceTrack_player_moved"] [connection signal="wrong_way" from="." to="Wrong Way" method="_on_RaceTrack_wrong_way"] -[connection signal="lap_completed" from="TrackPath/Player" to="GUI" method="_on_lap_completed"] diff --git a/TileMap.gd b/TileMap.gd index 72fc50b..e5335c1 100644 --- a/TileMap.gd +++ b/TileMap.gd @@ -4,8 +4,8 @@ enum { LEFT, RIGHT, UP, DOWN } # Enum for tiles from tile_set enum { DOWN_LEFT, DOWN_RIGHT, LEFT_RIGHT, START, UP_DOWN, UP_LEFT, UP_RIGHT } -# Called when the node enters the scene tree for the first time. -func _reset(): +func _ready(): + TrackSelection.connect("track_changed", self, "_reload_track") _reload_track() func _reload_track(): diff --git a/TrackPath.gd b/TrackPath.gd index db1ed9d..5699785 100644 --- a/TrackPath.gd +++ b/TrackPath.gd @@ -6,8 +6,12 @@ var tile_size : int = 128 var half_size : int = tile_size / 2 onready var map = get_node("../TileMap/") +func _ready(): + TrackSelection.connect("track_changed", self, "_reset_state") + _reset_state() + # Called when the node enters the scene tree for the first time. -func _reset(): +func _reset_state(): var track = TrackSelection.get_current_track() _build_track(track) $Opponent.set_offset(0.0) diff --git a/project.godot b/project.godot index 8602756..f4fbff6 100644 --- a/project.godot +++ b/project.godot @@ -25,10 +25,6 @@ config/icon="res://icon.png" Global="*res://Global.gd" TrackSelection="*res://track_selection.gd" -[debug] - -settings/stdout/print_fps=true - [display] window/size/width=1920 diff --git a/track_selection.gd b/track_selection.gd index c5dcadf..beb18f2 100644 --- a/track_selection.gd +++ b/track_selection.gd @@ -1,24 +1,34 @@ extends Node +signal track_changed() + const TRACKS_PATH = "res://assets/tracks/" var _tracks = [] -var _selected : int = 1 +var _selected : int func _ready(): _load_tracks() + _selected = 0 + emit_signal("track_changed") + func set_next_track(): _selected = wrapi(_selected + 1, 0, _tracks.size()) - print("set_next_track : ", _selected) + emit_signal("track_changed") func set_previous_track(): _selected = wrapi(_selected - 1, 0, _tracks.size()) + emit_signal("track_changed") func get_current_track(): - return _tracks[_selected] + return _tracks[_selected]["path"] + + +func get_current_track_name(): + return _tracks[_selected]["name"] func _load_tracks(): @@ -27,8 +37,12 @@ func _load_tracks(): var file = File.new() file.open(path, File.READ) var track = _load_from_txt(file.get_as_text()) + var track_name = path.get_file().rstrip(".%s" % path.get_extension()) if track.size() > 1: - loaded.append(track) + loaded.append({ + "name": track_name, + "path": track, + }) else: print("Error in track file : ", path)