Milestone 6 Beta 2

Reworked multiplayer, like a lot.
This commit is contained in:
patrick_pluto 2024-08-06 23:28:40 +02:00
parent 17ece77b7c
commit 9de67986dd
17 changed files with 309 additions and 89 deletions

View file

@ -343,8 +343,8 @@ codesign/entitlements/photos_library=false
codesign/entitlements/apple_events=false
codesign/entitlements/debugging=false
codesign/entitlements/app_sandbox/enabled=true
codesign/entitlements/app_sandbox/network_server=false
codesign/entitlements/app_sandbox/network_client=false
codesign/entitlements/app_sandbox/network_server=true
codesign/entitlements/app_sandbox/network_client=true
codesign/entitlements/app_sandbox/device_usb=false
codesign/entitlements/app_sandbox/device_bluetooth=false
codesign/entitlements/app_sandbox/files_downloads=0

View file

@ -37,7 +37,6 @@ size = Vector3(14.538, 20, 69.974)
transform = Transform3D(0.031, 0, 0, 0, 0.031, 0, 0, 0, 0.031, 0, 0, 0)
[node name="GridMap" type="GridMap" parent="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
mesh_library = ExtResource("1_rsvxi")
cell_size = Vector3(32, 96, 32)
data = {
@ -346,7 +345,7 @@ omni_range = 20.0
omni_shadow_mode = 0
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.5, -0.296198, 0.813798, 0, 0.939693, 0.34202, -0.866025, 0.17101, -0.469846, 0, 78, 0)
transform = Transform3D(-0.5, -0.55667, 0.663414, 0, 0.766044, 0.642788, -0.866025, 0.321394, -0.383022, 0, 78, 0)
shadow_enabled = true
directional_shadow_mode = 1

File diff suppressed because one or more lines are too long

33
menus/game_menu.tscn Normal file
View file

@ -0,0 +1,33 @@
[gd_scene load_steps=2 format=3 uid="uid://d1tv0npkjbet5"]
[ext_resource type="Script" path="res://scripts/game_menu.gd" id="1_fl507"]
[node name="game_menu" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_fl507")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="Button" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "Leave Game"
[connection signal="pressed" from="VBoxContainer/Button" to="." method="_on_button_pressed"]

View file

@ -74,8 +74,7 @@ grow_vertical = 0
[node name="Label" type="Label" parent="ver_string"]
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "Milestone 6
Beta 1"
text = "M6 B2"
horizontal_alignment = 2
[connection signal="pressed" from="main_content/create" to="." method="_on_create_pressed"]

30
menus/result.tscn Normal file
View file

@ -0,0 +1,30 @@
[gd_scene load_steps=2 format=3 uid="uid://cnn5w3au5766w"]
[ext_resource type="Script" path="res://scripts/result.gd" id="1_gbcar"]
[node name="result" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_gbcar")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 96

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=5 format=3 uid="uid://b440i2oidk5sp"]
[gd_scene load_steps=6 format=3 uid="uid://b440i2oidk5sp"]
[ext_resource type="Script" path="res://scripts/movement.gd" id="1_uru11"]
@ -11,6 +11,9 @@ radius = 0.375
height = 1.75
[sub_resource type="BoxShape3D" id="BoxShape3D_e4age"]
size = Vector3(0.5, 0.25, 0.75)
[sub_resource type="BoxShape3D" id="BoxShape3D_6pbak"]
size = Vector3(0.5, 1, 0.75)
[node name="player" type="CharacterBody3D"]
@ -37,27 +40,12 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
[node name="Camera3D" type="Camera3D" parent="cam_y"]
[node name="detect_hit" type="Area3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.25, -1.25)
[node name="CollisionShape3D" type="CollisionShape3D" parent="detect_hit"]
shape = SubResource("BoxShape3D_e4age")
disabled = true
[node name="hammer_bag" type="CSGBox3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.25, -0.5)
[node name="bag" type="CSGCylinder3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.875)
visible = false
size = Vector3(0.25, 0.25, 1)
[node name="CSGBox3D" type="CSGBox3D" parent="hammer_bag"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.75)
size = Vector3(0.5, 1, 0.75)
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="hammer_bag"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, -0.25, 1.375)
height = 1.0
[node name="CSGSphere3D" type="CSGSphere3D" parent="hammer_bag/CSGCylinder3D"]
[node name="CSGSphere3D" type="CSGSphere3D" parent="bag"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
visible = false
radius = 0.375
@ -100,7 +88,31 @@ size_flags_vertical = 0
theme_override_font_sizes/font_size = 64
text = "HP: 100 "
[connection signal="body_entered" from="detect_hit" to="." method="_on_detect_hit_body_entered"]
[node name="hammer" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, 0)
visible = false
[node name="hammer2" type="CSGBox3D" parent="hammer"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0)
size = Vector3(0.25, 0.25, 1)
[node name="CSGBox3D" type="CSGBox3D" parent="hammer/hammer2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.75)
size = Vector3(0.5, 1, 0.75)
[node name="detect_hit" type="Area3D" parent="hammer/hammer2/CSGBox3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="hammer/hammer2/CSGBox3D/detect_hit"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.375, 0)
shape = SubResource("BoxShape3D_e4age")
disabled = true
[node name="CollisionShape3D" type="CollisionShape3D" parent="hammer"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 1.25, 3.27835e-08)
shape = SubResource("BoxShape3D_6pbak")
[connection signal="timeout" from="time_in_bag" to="." method="_on_time_in_bag_timeout"]
[connection signal="timeout" from="show_fps" to="." method="_on_show_fps_timeout"]
[connection signal="timeout" from="jump_timeout" to="." method="_on_jump_timeout_timeout"]
[connection signal="body_entered" from="hammer/hammer2/CSGBox3D/detect_hit" to="." method="_on_detect_hit_body_entered"]

View file

@ -78,6 +78,11 @@ crouch={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
click={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
[layer_names]

View file

@ -12,6 +12,7 @@ extends Control
var elevated = false
func _ready():
multiplayer.connected_to_server.connect(_on_connected_ok)
if Server.is_server:
$player_customization/ip.hide()
$player_customization/ip.text = "localhost"
@ -33,17 +34,21 @@ func _on_start_pressed():
func _input(event):
if Input.is_action_just_pressed("escape"):
Game.reset()
Server.reset()
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
func _on_join_pressed():
if $player_customization/name.text != "" and $player_customization/ip.text != "":
if $player_customization/name.text != "" and $player_customization/name.text.length() <= 20 and $player_customization/ip.text != "":
if !Server.is_server:
Server.join_game($player_customization/ip.text)
$player_customization/join.hide()
$player_customization/join.disabled = true
$player_customization/name.editable = false
$player_customization/ip.editable = false
await get_tree().create_timer(1).timeout
Server.send_playerinfo.rpc($player_customization/name.text, multiplayer.get_unique_id())
func _on_connected_ok():
$player_customization/join.hide()
$player_customization/join.disabled = true
$player_customization/name.editable = false
$player_customization/ip.editable = false
await get_tree().create_timer(1).timeout
Server.send_playerinfo.rpc($player_customization/name.text, multiplayer.get_unique_id())

View file

@ -16,7 +16,8 @@ var living = true
func _process(delta):
if occupied:
trapped_body.position = global_position
if occupied and trapped_body.hp == 0:
if occupied and trapped_body.hp == 0 and living:
Game.died()
living = false
$dead.show()
@ -28,8 +29,10 @@ func _on_area_3d_body_entered(body):
living = true
body.lost_one()
trapped_body.frozen()
Game.freeze()
elif !body.beast and occupied and living and body != trapped_body:
trapped_body.unfreeze()
Game.unfreeze()
occupied = false
trapped_body.position = $spawn.global_position
trapped_body = null

View file

@ -13,6 +13,12 @@ var settings = {"save_version" = 2, "fps_counter" = 1}
var computers = 0
var players = 0
var map_name = "mansion"
var is_running = false
var frozen = 0
var dead = 0
var escaped = 0
var player_escaped = false
var is_beast = false
func _ready():
if FileAccess.file_exists("user://settings.json"):
@ -26,17 +32,43 @@ func _ready():
if OS.is_debug_build():
settings["fps_counter"] = 1
func freeze():
players -= 1
frozen += 1
func unfreeze():
players += 1
frozen -= 1
func died():
frozen -= 1
dead += 1
func has_escaped():
players -= 1
escaped += 1
func _process(delta):
pass
if is_running and players <= 0:
get_tree().change_scene_to_file("res://menus/result.tscn")
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
is_running = false
func reset():
computers = 0
players = 0
is_running = false
frozen = 0
dead = 0
escaped = 0
player_escaped = false
is_beast = false
func save_setting(setting_name, value):
settings[setting_name] = value
Save.saveJSON("user://settings.json", settings)
func apply_settings():
pass
players = Server.players_numbered.size() - 1
is_running = true

19
scripts/game_menu.gd Normal file
View file

@ -0,0 +1,19 @@
## freeftf
## Copyright (C) 2024 Patrick_Pluto
##
## This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
extends Control
func _on_button_pressed():
Game.reset()
Server.reset()
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
queue_free()

View file

@ -13,8 +13,13 @@ func matchmaking():
get_tree().root.get_node("./main_menu").hide()
func _ready():
Game.reset()
Server.reset()
if !OS.is_debug_build():
$main_content/matchmaking.hide()
$main_content/matchmaking.disabled = true
if DisplayServer.get_name() == "headless":
_on_matchmaking_pressed()
func _on_create_pressed():
get_tree().change_scene_to_file("res://menus/create.tscn")

View file

@ -25,6 +25,7 @@ var beast = false
var mouse_locked = true
var is_frozen = false
var hp = 100
var menu = preload("res://menus/game_menu.tscn")
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@ -66,6 +67,12 @@ func _physics_process(delta):
$cam_y.position.y = 0.5
position.y += 1
if Input.is_action_pressed("click") and $hammer.rotation_degrees.x > -90:
$hammer.rotation_degrees.x -= 5
Server.sync_hammer.rpc(name, $hammer.rotation)
elif $hammer.rotation_degrees.x < 0 and !Input.is_action_pressed("click"):
$hammer.rotation_degrees.x += 5
Server.sync_hammer.rpc(name, $hammer.rotation)
var input_dir = Input.get_vector("left", "right", "forwards", "backwards")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
@ -80,15 +87,18 @@ func _physics_process(delta):
if !npc:
Server.sync_player.rpc(name, position, rotation)
if mouse_locked:
if mouse_locked and !has_node("./game_menu"):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed("escape"):
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
Game.reset()
Server.reset()
if has_node("./game_menu"):
get_node("./game_menu").free()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
var instance = menu.instantiate()
add_child(instance)
if Input.is_action_just_pressed("mouse_lock"):
mouse_locked = !mouse_locked
@ -96,7 +106,7 @@ func _physics_process(delta):
func _input(event):
if !npc:
if event is InputEventMouseMotion and (Input.is_action_pressed("cam_look") or $cam_y/Camera3D.position.z == 0):
if event is InputEventMouseMotion and (Input.is_action_pressed("cam_look") or $cam_y/Camera3D.position.z == 0) and !has_node("./game_menu"):
var camera_rotation = event.relative * 0.01
if $cam_y.rotation.x <= 1.6 && camera_rotation.y <= 0:
$cam_y.rotate(Vector3.RIGHT, -camera_rotation.y)
@ -110,13 +120,16 @@ func _input(event):
func beast_init():
if !npc:
Game.is_beast = true
beast = true
speed += 2
position.y += 10
$detect_hit.monitoring = true
$detect_hit.monitorable = true
$detect_hit/CollisionShape3D.disabled = false
$hammer_bag.visible = true
$hammer/hammer2/CSGBox3D/detect_hit.monitoring = true
$hammer/hammer2/CSGBox3D/detect_hit.monitorable = true
$hammer/hammer2/CSGBox3D/detect_hit/CollisionShape3D.disabled = false
$hammer.show()
$bag.show()
func _on_detect_hit_body_entered(body):
if enabled and body is CharacterBody3D and !got_person:
@ -137,11 +150,11 @@ func captured(beast2):
func got_one(target):
caught_body = target
got_person = true
$hammer_bag/CSGCylinder3D/CSGSphere3D.visible = true
$bag/CSGSphere3D.show()
func lost_one():
got_person = false
$hammer_bag/CSGCylinder3D/CSGSphere3D.visible = false
$bag/CSGSphere3D.hide()
func frozen():
visible = true

21
scripts/result.gd Normal file
View file

@ -0,0 +1,21 @@
## freeftf
## Copyright (C) 2024 Patrick_Pluto
##
## This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
extends Control
func _ready():
if Game.player_escaped or (Game.is_beast and Game.escaped == 0):
$VBoxContainer/Label.text = "You Win"
else:
$VBoxContainer/Label.text = "You Lose"
func _process(delta):
if Input.is_action_just_pressed("escape"):
get_tree().change_scene_to_file("res://menus/main_menu.tscn")

View file

@ -22,6 +22,38 @@ var is_server = false
var first_joined = true
var game_master = "debug"
var map_name = "mansion"
var offline
func _ready():
offline = multiplayer.multiplayer_peer
multiplayer.peer_disconnected.connect(_on_player_disconnected)
multiplayer.server_disconnected.connect(_on_server_disconnected)
func _on_player_disconnected(id):
players.erase(id)
if (players.is_empty() or id == game_master) and multiplayer.is_server():
get_tree().quit()
var x = 0
if !multiplayer.is_server():
for i in players_numbered:
if i == id:
var current_character = get_tree().root.get_node("./"+map_name+"/player"+str(x))
if current_character.hp == 0:
Game.dead -= 1
elif current_character.is_frozen:
Game.frozen -= 1
elif current_character.beast:
Game.player_escaped = true
Game.players = 0
else:
Game.players -= 1
current_character.free()
x += 1
func _on_server_disconnected():
Server.reset()
Game.reset()
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
func reset():
players = {}
@ -29,11 +61,11 @@ func reset():
label = null
map = null
is_server = false
first_joined = false
first_joined = true
game_master = "debug"
character = preload("res://objects/player.tscn")
if multiplayer != null:
multiplayer.multiplayer_peer = null
multiplayer.multiplayer_peer = offline
func join_game(ip):
var peer = ENetMultiplayerPeer.new()
@ -51,9 +83,10 @@ func create_game():
multiplayer.multiplayer_peer = peer
func _process(delta):
if multiplayer != null:
if multiplayer.is_server():
make_host.rpc(game_master)
if multiplayer.is_server():
make_host.rpc(game_master)
@rpc("authority","call_remote","reliable")
func make_host(id):
@ -84,6 +117,7 @@ func send_playerinfo(player_name, id):
label.text = players[w]
done = 1
else:
players[id] = player_name
if first_joined:
first_joined = false
game_master = id
@ -119,6 +153,12 @@ func sync_player(node_name, position, rotation):
current_character.position = position
current_character.rotation = rotation
@rpc("any_peer", "call_remote", "unreliable")
func sync_hammer(node_name, rotation):
if !multiplayer.is_server():
var current_character = get_tree().root.get_node("./"+map_name+"/"+node_name+"/hammer")
current_character.rotation = rotation
@rpc("any_peer", "call_local", "reliable")
func sync_computers(node_name, current):
if !multiplayer.is_server() and (multiplayer.get_remote_sender_id() == game_master or multiplayer.get_remote_sender_id() == 0):
@ -142,3 +182,4 @@ func player_hit(target, beast):
target.captured(beast)
beast.got_one(target)

View file

@ -11,8 +11,11 @@ extends Area3D
func _on_body_entered(body):
if body is CharacterBody3D and !body.beast and Game.computers == 0:
if !body.npc:
Game.player_escaped = true
body.free()
$mapcam.active
Game.has_escaped()
func _process(delta):
if Game.computers == 0: