add round selection

This commit is contained in:
interfisch 2024-11-09 13:58:22 +01:00
parent 329d3c7fb2
commit 66f163d75d
5 changed files with 58 additions and 4 deletions

View file

@ -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"]

View file

@ -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))

View file

@ -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

View file

@ -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

View file

@ -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))