diff --git a/project.godot b/project.godot index 9ff19a2..01e969e 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,10 @@ config/icon="res://icon.svg" Gamestate="*res://scripts/gamestate.gd" +[display] + +window/stretch/mode="canvas_items" + [layer_names] 2d_physics/layer_1="walls" diff --git a/scenes/car.tscn b/scenes/car.tscn index 6b89f76..def33ee 100644 --- a/scenes/car.tscn +++ b/scenes/car.tscn @@ -12,38 +12,44 @@ height = 34.0 [node name="Car" type="Node2D"] script = ExtResource("1_0tin3") -[node name="Car" type="CharacterBody2D" parent="."] +[node name="CharacterBody_Car" type="CharacterBody2D" parent="."] +motion_mode = 1 script = ExtResource("1_i5tet") -[node name="sprite_features" type="Sprite2D" parent="Car"] +[node name="sprite_features" type="Sprite2D" parent="CharacterBody_Car"] z_index = 10 scale = Vector2(0.5, 0.5) texture = ExtResource("3_ts6mm") -[node name="sprite_body" type="Sprite2D" parent="Car"] +[node name="sprite_body" type="Sprite2D" parent="CharacterBody_Car"] z_index = 10 scale = Vector2(0.5, 0.5) texture = ExtResource("4_lps13") -[node name="CollisionShape2D" type="CollisionShape2D" parent="Car"] +[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody_Car"] rotation = -1.57079 shape = SubResource("CapsuleShape2D_bj1hp") -[node name="RayCast_FL" type="RayCast2D" parent="Car"] +[node name="RayCast_FL" type="RayCast2D" parent="CharacterBody_Car"] target_position = Vector2(256, -128) collision_mask = 2 -[node name="RayCast_FR" type="RayCast2D" parent="Car"] +[node name="RayCast_FR" type="RayCast2D" parent="CharacterBody_Car"] target_position = Vector2(256, 128) collision_mask = 2 -[node name="resetTimer" type="Timer" parent="Car"] +[node name="resetTimer" type="Timer" parent="CharacterBody_Car"] wait_time = 2.0 one_shot = true -[node name="RayCast_Car" type="RayCast2D" parent="Car"] +[node name="RayCast_Car" type="RayCast2D" parent="CharacterBody_Car"] position = Vector2(-15, 0) target_position = Vector2(31, 0) collision_mask = 4 -[connection signal="timeout" from="Car/resetTimer" to="Car" method="_on_reset_timer_timeout"] +[node name="collisionEnableTimer" type="Timer" parent="CharacterBody_Car"] +wait_time = 0.1 +one_shot = true + +[connection signal="timeout" from="CharacterBody_Car/resetTimer" to="CharacterBody_Car" method="_on_reset_timer_timeout"] +[connection signal="timeout" from="CharacterBody_Car/collisionEnableTimer" to="CharacterBody_Car" method="_on_collision_enable_timer_timeout"] diff --git a/scenes/game.tscn b/scenes/game.tscn index 341d834..52b4fe9 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -5,15 +5,28 @@ [node name="Game" type="Node2D"] script = ExtResource("1_7syh4") -[node name="Camera2D" type="Camera2D" parent="."] +[node name="hud" type="CanvasLayer" parent="."] -[node name="speedlabel" type="Label" parent="Camera2D"] +[node name="speedlabel" type="Label" parent="hud"] z_index = 8 -offset_left = -484.0 -offset_top = 213.0 -offset_right = -68.0 -offset_bottom = 258.0 +offset_left = 38.0 +offset_top = 541.0 +offset_right = 454.0 +offset_bottom = 586.0 theme_override_font_sizes/font_size = 32 +text = "adsf" vertical_alignment = 1 +[node name="speedlabel2" type="Label" parent="hud"] +z_index = 8 +offset_left = 40.0 +offset_top = 582.0 +offset_right = 456.0 +offset_bottom = 627.0 +theme_override_font_sizes/font_size = 32 +text = "adsf" +vertical_alignment = 1 + +[node name="Camera2D" type="Camera2D" parent="."] + [node name="cars" type="Node" parent="."] diff --git a/scenes/menu.tscn b/scenes/menu.tscn index f1e5323..180d653 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -85,7 +85,16 @@ layout_mode = 2 theme_override_font_sizes/font_size = 32 uppercase = true +[node name="btn_fullscreen" type="CheckButton" parent="MenuDisplay"] +offset_left = 845.0 +offset_top = 540.0 +offset_right = 972.0 +offset_bottom = 571.0 +scale = Vector2(2, 2) +text = "Fullscreen" + [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="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/scripts/car.gd b/scripts/car.gd index 0b6d792..8d562b6 100644 --- a/scripts/car.gd +++ b/scripts/car.gd @@ -2,6 +2,7 @@ extends CharacterBody2D #Tutorial: https://www.youtube.com/watch?v=mJ1ZfGDTMCY t=15s + const COLLISIONMASK_FINISH=3 #set in road_overlay const COLLISIONMASK_CHECKPOINT=4 #set in road_overlay @@ -48,14 +49,22 @@ var steer_direction=0 var autoreset=false +var autosteer_enabled=false + @onready var ray_cast_fl: RayCast2D = $RayCast_FL @onready var ray_cast_fr: RayCast2D = $RayCast_FR @onready var reset_timer: Timer = $resetTimer @onready var ray_cast_car: RayCast2D = $RayCast_Car #for tracking markers +@onready var collision_shape: CollisionShape2D = $CollisionShape2D +@onready var collision_enable_timer: Timer = $collisionEnableTimer + var playerid=0 +func _ready() -> void: + collision_shape.disabled=true #disable collisions on start. also to avoid collision when initially setting position + func _physics_process(delta: float) -> void: acceleration=Vector2.ZERO check_markers() @@ -72,7 +81,7 @@ func _physics_process(delta: float) -> void: # var collision = get_slide_collision(i) # print("Collided with: ", collision.get_collider().name) - if velocity.length() < resetcar_stoppedspeed: #moving slow, possibly crash? + if velocity.length() < resetcar_stoppedspeed and autosteer_enabled: #moving slow, possibly crash? if reset_timer.is_stopped(): reset_timer.start() if velocity.length() > resetcar_movingspeed: @@ -122,12 +131,12 @@ func get_input(): var steering_distance_close=constrain( remap(velocity.length(),steering_speed_fast,steering_speed_slow,steering_distance_close_fast,steering_distance_close_slow),steering_distance_close_fast,steering_distance_close_slow) - - if distance_min void: + collision_shape.disabled=false diff --git a/scripts/car_node.gd b/scripts/car_node.gd index 394e33f..04df5e3 100644 --- a/scripts/car_node.gd +++ b/scripts/car_node.gd @@ -1,18 +1,26 @@ extends Node2D -@onready var car: CharacterBody2D = $Car -@onready var carbody: Sprite2D = $Car/sprite_body +@onready var cbcar: CharacterBody2D = $CharacterBody_Car +@onready var carbody: Sprite2D = $CharacterBody_Car/sprite_body func getSpeed() -> float: - return car.velocity.length() + return cbcar.velocity.length() func getPosition(): - return car.position + return cbcar.position func setPosition(p:Vector2): - car.position=p + cbcar.position=p func setPlayerinformation(playerid, playercolor): - car.playerid=playerid + cbcar.playerid=playerid #TODO set playercolor - carbody.modulate = playercolor#Color(0, 0, 1) + carbody.modulate = playercolor + +func move_and_slide(): + cbcar.move_and_slide() + +func printDebug(): + for i in cbcar.get_slide_collision_count(): + var collision = cbcar.get_slide_collision(i) + print(""+str(cbcar.playerid)+" Collided with: "+ str( collision.get_collider().name)+" pid="+str(collision.get_collider().playerid)+" pos="+str(collision.get_collider().position)) diff --git a/scripts/game.gd b/scripts/game.gd index 559f295..536bc8e 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -5,12 +5,13 @@ extends Node2D @onready var cars: Node = $cars -const caroffset=32+12 #space cars on start line +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.1,0.1) -var zoomspeed=0.3 -var zoomspeed_backup=0.05 +var viewCarMargin=Vector2(0.05,0.05) #proportions of viewsize. 0,0 = adjust when cars are outside view, 1,1=infinite zoom out +var viewCarMargin_zoomstart=viewCarMargin+Vector2(0.2,0.2) +var zoomspeed=0.5 +var zoomspeed_backup=0.1 +var zoom_normal=2 # Called when the node enters the scene tree for the first time. @@ -22,7 +23,12 @@ func _ready() -> void: var newcarinstance=newcarscene.instantiate() cars.add_child(newcarinstance) newcarinstance.setPlayerinformation(i,player.color) - newcarinstance.setPosition(Vector2(0,i*caroffset)) + + newcarinstance.setPosition(Vector2(0,ceil(i/2.0)*(fmod(i,2)-0.5)*2.0*caroffset)) + + + #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 #Load Map @@ -74,17 +80,22 @@ func _process(delta: float) -> void: var viewCarMargin_zoombackup=viewCarMargin_zoomstart+Vector2(0.1,0.1) var viewsize = camera.get_viewport_rect().size/camera.zoom var carSpread=Vector2(maxPos.x-minPos.x,maxPos.y-minPos.y) - var calculatedViewCarMargin=Vector2(viewsize.x-carSpread.x,viewsize.y-carSpread.y) + var calculatedViewCarMargin=Vector2((viewsize.x-carSpread.x)/2,(viewsize.y-carSpread.y)/2) var mapped_zoomspeed_x=constrain(remap(calculatedViewCarMargin.x , viewCarMargin_zoomstart.x*viewsize.x,viewCarMargin.x*viewsize.x,0,zoomspeed),0,zoomspeed) var mapped_zoomspeed_y=constrain(remap(calculatedViewCarMargin.y , viewCarMargin_zoomstart.y*viewsize.y,viewCarMargin.y*viewsize.y,0,zoomspeed),0,zoomspeed) var mapped_zoomspeed=max(mapped_zoomspeed_x,mapped_zoomspeed_y) if calculatedViewCarMargin.x<(viewCarMargin_zoomstart.x*viewsize.x) or calculatedViewCarMargin.y<(viewCarMargin_zoomstart.y*viewsize.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 - if camera.zoom.x<1.0: + if camera.zoom.x void: + if toggled_on: + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) + else: + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) diff --git a/scripts/menudisplay.gd b/scripts/menudisplay.gd index 561d631..3bcbea8 100644 --- a/scripts/menudisplay.gd +++ b/scripts/menudisplay.gd @@ -28,9 +28,3 @@ func update_playerlist(players:Array[Gamestate.Player]): else: label.text="" i+=1 - #for p in players: - #$Playerlist.text+=str(OS.get_keycode_string(p.inputkey))+"\n" - - - - #todo add playercolor here