diff --git a/scripts/game.gd b/scripts/game.gd index 25fa18b..bf62af7 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -20,12 +20,12 @@ var viewCarMargin_zoombackup=viewCarMargin_zoomstart-Vector2(0.1,0.1) #start zoo var zoomspeed=0.5 var zoomspeed_backup=0.1 #relative to screen size var zoom_normal=1.5 -const CAMERA_POSITION_SPEED=0.5 #0.0 - 1.0, higher=faster +const CAMERA_POSITION_SPEED=0.02 #0.0 - 1.0, higher=faster var running=false -var time_close_keypressed=1#seconds to wait after key pressed at endscreen +var time_close_keypressed=1 #seconds to wait after key pressed at endscreen var game_ended=false @@ -39,7 +39,7 @@ func _ready() -> void: #Load Map var checkpoints :Array[String]=[] - var mapscene=load(Gamestate.getSelectedMap()) + var mapscene=load(Gamestate.getSelectedMapSceneName()) var mapsceneinstance=mapscene.instantiate() add_child(mapsceneinstance) for mapc in mapsceneinstance.get_children(): @@ -71,7 +71,6 @@ func _process(delta: float) -> void: countdown_label.text=str(round(countdown.time_left)) var cars=cars.get_children() - var meanCarPosition=Vector2.ZERO var displayedCarCount=0 var maxCarSpeed=0 var minPos=Vector2.ZERO #min/max x and y position of all cars @@ -85,7 +84,6 @@ func _process(delta: float) -> void: for c in cars: if !c.hasFinished() or !oneDriving: var carpos = c.getPosition() - meanCarPosition+=carpos maxCarSpeed=max(maxCarSpeed,c.getSpeed()) if displayedCarCount==0: @@ -101,10 +99,9 @@ func _process(delta: float) -> void: displayedCarCount+=1 - meanCarPosition/=displayedCarCount - #camera.position=lerp(camera.position,meanCarPosition,CAMERA_POSITION_SPEED) - camera.position=meanCarPosition + camera.position=lerp(camera.position,(minPos+maxPos)/2.0,CAMERA_POSITION_SPEED) + var viewsize = camera.get_viewport_rect().size diff --git a/scripts/gamestate.gd b/scripts/gamestate.gd index b4429cb..aeb1bff 100644 --- a/scripts/gamestate.gd +++ b/scripts/gamestate.gd @@ -13,7 +13,7 @@ var map_scene_name="" var map_scene_name_prefix="res://scenes/map_" var map_scene_name_postfix=".tscn" -var rounds=1 +var rounds=3 func getRounds(): return rounds @@ -22,11 +22,14 @@ func setRounds(r): print("Rounds set to "+str(r)) rounds=r -func getSelectedMap(): +func getSelectedMap(): #return only short map name "00" return map_scene_name +func getSelectedMapSceneName(): #returns full scene path "res://scenes/map_00.tscn" + return map_scene_name_prefix+map_scene_name+map_scene_name_postfix + func setSelectedMap(mapname): - map_scene_name=map_scene_name_prefix+mapname+map_scene_name_postfix + map_scene_name=mapname func checkColoriFree(i): var free=true diff --git a/scripts/map_selection.gd b/scripts/map_selection.gd index a45e622..82ecdaa 100644 --- a/scripts/map_selection.gd +++ b/scripts/map_selection.gd @@ -12,6 +12,12 @@ func _ready() -> void: if len(Gamestate.getSelectedMap())<=0: #no map selected (ie on startup) get_children()[0].emit_signal("pressed") #preselect first map in list + else: + for c in get_children(): + if c.name==button_prefix+Gamestate.getSelectedMap(): + c.emit_signal("pressed") + break + func _on_btn_map(btn): diff --git a/scripts/menu.gd b/scripts/menu.gd index 7926eb2..1083ff0 100644 --- a/scripts/menu.gd +++ b/scripts/menu.gd @@ -7,6 +7,7 @@ extends Node func _ready(): removeAssignedKeys() Gamestate.removeAllPlayers() + $Timer.stop() func assignKeys(): var i=0 @@ -68,7 +69,9 @@ func _on_btn_fullscreen_toggled(toggled_on: bool) -> void: func _on_rounds_selection_item_selected(index: int) -> void: - $Timer.start() + if not $Timer.is_stopped(): #only restart + $Timer.start() func _on_map_container_map_changed() -> void: - $Timer.start() + if not $Timer.is_stopped(): #only restart + $Timer.start() diff --git a/scripts/rounds_selection.gd b/scripts/rounds_selection.gd index cfe95f4..015dac5 100644 --- a/scripts/rounds_selection.gd +++ b/scripts/rounds_selection.gd @@ -3,8 +3,9 @@ extends OptionButton # Called when the node enters the scene tree for the first time. func _ready() -> void: - select(3-1) #preselect rounds - Gamestate.setRounds(3) + var selectedRounds=Gamestate.getRounds() + select(selectedRounds-1) #preselect rounds + Gamestate.setRounds(selectedRounds)