diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 6d0db01..c27f073 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://b1uhymisifcho"] +[gd_scene load_steps=8 format=3 uid="uid://b1uhymisifcho"] [ext_resource type="Script" path="res://scripts/menu.gd" id="1_fushn"] [ext_resource type="Script" path="res://scripts/menudisplay.gd" id="2_jc4pv"] @@ -6,6 +6,7 @@ [ext_resource type="Texture2D" uid="uid://my0glsan1h2e" path="res://scenes/map_preview/map_00.png" id="3_p822h"] [ext_resource type="Texture2D" uid="uid://bk32usoetq3b" path="res://scenes/map_preview/map_01.png" id="4_ac8w4"] [ext_resource type="Texture2D" uid="uid://ole07xte1dxp" path="res://scenes/map_preview/map_02.png" id="5_pnyq7"] +[ext_resource type="Script" path="res://scripts/rounds_selection.gd" id="7_cr4tq"] [node name="Menu" type="Node"] script = ExtResource("1_fushn") @@ -120,8 +121,34 @@ layout_mode = 2 toggle_mode = true icon = ExtResource("5_pnyq7") +[node name="rounds_selection" type="OptionButton" parent="MenuDisplay"] +offset_left = 690.0 +offset_top = 556.0 +offset_right = 732.0 +offset_bottom = 587.0 +item_count = 5 +popup/item_0/text = "1" +popup/item_1/text = "2" +popup/item_1/id = 1 +popup/item_2/text = "3" +popup/item_2/id = 2 +popup/item_3/text = "4" +popup/item_3/id = 3 +popup/item_4/text = "5" +popup/item_4/id = 4 +script = ExtResource("7_cr4tq") + +[node name="Label" type="Label" parent="MenuDisplay/rounds_selection"] +layout_mode = 0 +offset_left = -70.0 +offset_top = 3.0 +offset_right = -7.0 +offset_bottom = 26.0 +text = "Rounds:" + [node name="Timer" type="Timer" parent="."] wait_time = 5.0 [connection signal="toggled" from="MenuDisplay/btn_fullscreen" to="." method="_on_btn_fullscreen_toggled"] +[connection signal="item_selected" from="MenuDisplay/rounds_selection" to="MenuDisplay/rounds_selection" method="_on_item_selected"] [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/scripts/game.gd b/scripts/game.gd index 8b846c7..af98391 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -24,7 +24,6 @@ const CAMERA_POSITION_SPEED=0.05 #0.0 - 1.0, higher=faster var running=false -var rounds=1 var time_close_keypressed=1#seconds to wait after key pressed at endscreen @@ -34,6 +33,7 @@ var game_ended=false # Called when the node enters the scene tree for the first time. func _ready() -> void: Gamestate.resetTimeElapsed() + countdown.start() countdown_label.visible=true @@ -56,7 +56,7 @@ func _ready() -> void: newcarinstance.setPlayerinformation(i,player.color) newcarinstance.setPosition(Vector2(0,ceil(i/2.0)*(fmod(i,2)-0.5)*2.0*caroffset)) - newcarinstance.setCheckpoints(checkpoints,rounds) + newcarinstance.setCheckpoints(checkpoints,Gamestate.getRounds()) newcarinstance.getCharacterBody().car_finished.connect(_on_car_finished) print("carpos is ="+str(newcarinstance.getPosition())+" instancepos="+str(newcarinstance.position)) diff --git a/scripts/gamestate.gd b/scripts/gamestate.gd index 3a71c4d..240ef77 100644 --- a/scripts/gamestate.gd +++ b/scripts/gamestate.gd @@ -13,7 +13,14 @@ var map_scene_name="" var map_scene_name_prefix="res://scenes/map_" var map_scene_name_postfix=".tscn" +var rounds=1 +func getRounds(): + return rounds + +func setRounds(r): + rounds=r + func getSelectedMap(): return map_scene_name diff --git a/scripts/menu.gd b/scripts/menu.gd index fb22eaf..2405854 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -38,12 +38,13 @@ func _unhandled_key_input(event: InputEvent) -> void: -func _on_timer_timeout() -> void: +func _on_timer_timeout() -> void: #Start Game print("Game starting") get_tree().change_scene_to_file("res://scenes/game.tscn") $Timer.stop() assignKeys() + func _process(delta: float) -> void: if $Timer.is_stopped() or $Timer.time_left>3.5: $MenuDisplay.updateCountdown(-1) #do not display countdown diff --git a/scripts/rounds_selection.gd b/scripts/rounds_selection.gd new file mode 100644 index 0000000..6236de1 --- /dev/null +++ b/scripts/rounds_selection.gd @@ -0,0 +1,19 @@ +extends OptionButton + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + select(3-1) #preselect rounds + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + + + + +func _on_item_selected(index: int) -> void: + Gamestate.setRounds(index+1) + print("Set rounds to "+str(index+1))