From 22e9c1bcc1324067c592d4f847904abe1f3c729a Mon Sep 17 00:00:00 2001 From: Fisch Date: Wed, 6 Nov 2024 18:36:13 +0100 Subject: [PATCH] fix zooming --- scenes/game.tscn | 1 + scripts/game.gd | 51 +++++++++++++++++++++++------------------ scripts/time_display.gd | 12 ++++++++++ 3 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 scripts/time_display.gd diff --git a/scenes/game.tscn b/scenes/game.tscn index e7f9dae..9fb6f00 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -8,6 +8,7 @@ script = ExtResource("1_7syh4") [node name="hud" type="CanvasLayer" parent="."] [node name="debuglabel" type="Label" parent="hud"] +visible = false z_index = 8 offset_left = 14.0 offset_top = 535.0 diff --git a/scripts/game.gd b/scripts/game.gd index ae721c7..6d48e91 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -9,11 +9,12 @@ extends Node2D const caroffset= 32+4 #space cars on start line -var viewCarMargin=Vector2(0.1,0.1) #proportions of viewsize. 0,0 = adjust when cars are outside view, 1,1=infinite zoom out -var viewCarMargin_zoomstart=viewCarMargin+Vector2(0.05,0.05) -var zoomspeed=1.0 -var zoomspeed_backup=0.2 -var zoom_normal=2 +var viewCarMargin=Vector2(0.7,0.7) #1=zoom out full speed when car is at border. 0.9 zoom out full speed when car is 10% away from border +var viewCarMargin_zoomstart=viewCarMargin-Vector2(0.2,0.2) #start zooming +var viewCarMargin_zoombackup=viewCarMargin_zoomstart-Vector2(0.1,0.1) #start zooming back in +var zoomspeed=0.5 +var zoomspeed_backup=0.1 #relative to screen size +var zoom_normal=2.0 const CAMERA_POSITION_SPEED=0.98 #0.0 - 1.0, higher=faster var running=false @@ -28,21 +29,18 @@ func _ready() -> void: countdown_label.visible=true #Load Map - #var num_checkpoints=0 var checkpoints :Array[String]=[] var mapscene=load("res://scenes/map_01.tscn") var mapsceneinstance=mapscene.instantiate() add_child(mapsceneinstance) for mapc in mapsceneinstance.get_children(): if mapc.name.begins_with("area_cp"): - #num_checkpoints+=1 checkpoints.append(mapc.name) print(str(checkpoints.size())+" Checkpoints found") var i=0 - #for playerkey in Gamestate.getPlayerkeys(): #create all players - for player in Gamestate.getPlayers(): + for player in Gamestate.getPlayers(): #create all players var newcarscene=load("res://scenes/car.tscn") var newcarinstance=newcarscene.instantiate() cars.add_child(newcarinstance) @@ -52,8 +50,6 @@ func _ready() -> void: newcarinstance.setCheckpoints(checkpoints,rounds) newcarinstance.getCharacterBody().car_finished.connect(_on_car_finished) - - #print("Position car "+str(i)+" = "+str(ceil(i/2.0)*(fmod(i,2)-0.5)*2.0*caroffset)) print("carpos is ="+str(newcarinstance.getPosition())+" instancepos="+str(newcarinstance.position)) i+=1 @@ -99,8 +95,8 @@ func _process(delta: float) -> void: meanCarPosition/=displayedCarCount - #camera.position=car.getPosition() - camera.position=lerp(camera.position,meanCarPosition,CAMERA_POSITION_SPEED*delta) + camera.position=meanCarPosition + #camera.position=lerp(camera.position,meanCarPosition,CAMERA_POSITION_SPEED*delta) #rint("zoom = "+str(camera.zoom)) #camera.zoom=Vector2(1.5,1.5) @@ -111,21 +107,32 @@ func _process(delta: float) -> void: if camera.zoomviewCarMargin_zoomstart_pixels.x or calculatedViewCarMargin.y>viewCarMargin_zoomstart_pixels.y: #cars not in view camera.zoom-=Vector2(mapped_zoomspeed*delta,mapped_zoomspeed*delta) - #camera.zoom-=Vector2(0.1,0.1) - elif calculatedViewCarMargin.x>(viewCarMargin_zoombackup.x*viewsize.x) and calculatedViewCarMargin.y>(viewCarMargin_zoombackup.y*viewsize.y): #cars in view again + $hud/debuglabel.set("theme_override_colors/font_color",Color(0,0,0.7)) + elif calculatedViewCarMargin.x