Compare commits
7 commits
f1a4ad761c
...
fa6a64fbaa
| Author | SHA1 | Date | |
|---|---|---|---|
| fa6a64fbaa | |||
| 54967e570b | |||
| 35a17c04b6 | |||
| ee44810636 | |||
| d00cee752e | |||
| 79fa813571 | |||
| b11655a8fe |
8 changed files with 242 additions and 117 deletions
68
main.tscn
68
main.tscn
|
|
@ -1,12 +1,13 @@
|
|||
[gd_scene load_steps=16 format=3 uid="uid://eiaw4xbs3suk"]
|
||||
[gd_scene load_steps=17 format=3 uid="uid://eiaw4xbs3suk"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cnbm3aqyg0p2o" path="res://server.gd" id="1_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://qb8cbljxgnub" path="res://world/killbrick.tscn" id="1_h2yge"]
|
||||
[ext_resource type="PackedScene" uid="uid://cfceg80unq0pe" path="res://player/player.tscn" id="1_ig7tw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcmrj6qkemrll" path="res://world/radiohead_cube.tscn" id="2_0xm2m"]
|
||||
[ext_resource type="Texture2D" uid="uid://wdjmyv260he1" path="res://world/textures/grass.jpg" id="2_272bh"]
|
||||
[ext_resource type="Texture2D" uid="uid://dnt0vfav03ris" path="res://world/textures/grass.jpg" id="2_272bh"]
|
||||
[ext_resource type="PackedScene" uid="uid://of6tq8gpjxtu" path="res://gears/gear_pickup.tscn" id="3_lquwl"]
|
||||
[ext_resource type="PackedScene" uid="uid://bafl8q0r61xrg" path="res://gears/gear.tscn" id="4_7mycd"]
|
||||
[ext_resource type="Texture2D" uid="uid://2ku62tk8r74x" path="res://world/textures/sky.hdr" id="8_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://c117buhmmkvkt" path="res://gears/ball.tscn" id="6_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3k7b6o56ue5k" path="res://gears/geep.tscn" id="7_kek77"]
|
||||
[ext_resource type="Texture2D" uid="uid://bl4yvm44o6gcf" path="res://world/textures/sky.hdr" id="8_5vw27"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_7dm0k"]
|
||||
size = Vector3(1000, 2, 1000)
|
||||
|
|
@ -40,9 +41,7 @@ glow_hdr_luminance_cap = 0.0
|
|||
[sub_resource type="Compositor" id="Compositor_5vw27"]
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_ig7tw")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0)
|
||||
script = ExtResource("1_5vw27")
|
||||
|
||||
[node name="Baseplate" type="StaticBody3D" parent="."]
|
||||
|
||||
|
|
@ -68,11 +67,16 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 7, 0)
|
|||
[node name="Killbrick" parent="." instance=ExtResource("1_h2yge")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -40, 1.5, -40)
|
||||
|
||||
[node name="GearPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
[node name="BallPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 2, -21)
|
||||
|
||||
[node name="Gear" parent="GearPickup" instance=ExtResource("4_7mycd")]
|
||||
transform = Transform3D(1, 0, 0, 0, -0.012967386, 0.9999159, 0, -0.9999159, -0.012967386, 0, 0.5, 0)
|
||||
[node name="Gear" parent="BallPickup" instance=ExtResource("6_5vw27")]
|
||||
|
||||
[node name="GeepPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 1.75, -30)
|
||||
|
||||
[node name="Gear" parent="GeepPickup" instance=ExtResource("7_kek77")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.75, 0)
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_7mycd")
|
||||
|
|
@ -83,3 +87,45 @@ compositor = SubResource("Compositor_5vw27")
|
|||
transform = Transform3D(0.70710665, 0.5, -0.5, 0, 0.7071067, 0.7071067, 0.7071069, -0.49999988, 0.49999988, -500, 200, 500)
|
||||
light_color = Color(1, 0.87058824, 0.12941177, 1)
|
||||
shadow_enabled = true
|
||||
|
||||
[node name="UI" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Menu" type="Panel" parent="UI"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="UI/Menu"]
|
||||
layout_mode = 0
|
||||
offset_right = 1149.0
|
||||
offset_bottom = 134.0
|
||||
theme_override_constants/margin_left = 15
|
||||
theme_override_constants/margin_top = 15
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="UI/Menu/MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="UI/Menu/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Menu
|
||||
"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="ServerButton2" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Host
|
||||
"
|
||||
|
||||
[node name="ClientButton" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Join
|
||||
"
|
||||
|
||||
[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="."]
|
||||
_spawnable_scenes = PackedStringArray("uid://cfceg80unq0pe")
|
||||
spawn_path = NodePath("..")
|
||||
|
||||
[connection signal="pressed" from="UI/Menu/MarginContainer/VBoxContainer/ServerButton2" to="." method="_on_server_button_pressed"]
|
||||
[connection signal="pressed" from="UI/Menu/MarginContainer/VBoxContainer/ClientButton" to="." method="_on_client_button_pressed"]
|
||||
|
|
|
|||
21
menu.tscn
Normal file
21
menu.tscn
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[gd_scene format=3 uid="uid://dbv3ty2ulxir4"]
|
||||
|
||||
[node name="Menu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
|
||||
[node name="client_button" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 200.0
|
||||
offset_bottom = 100.0
|
||||
text = "Client
|
||||
"
|
||||
|
||||
[node name="server_button" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_top = 165.0
|
||||
offset_right = 200.0
|
||||
offset_bottom = 265.0
|
||||
text = "Server
|
||||
|
||||
"
|
||||
87
player/camera.gd
Normal file
87
player/camera.gd
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
class_name CameraGimbal extends Node3D
|
||||
|
||||
@export var rotation_speed = (PI / 180) * 120
|
||||
@export var default_zoom = 8
|
||||
|
||||
# is mouse captured by game permanently?
|
||||
# (i.e. not just holding right click)
|
||||
var locked = false
|
||||
var mouse_velocity = Vector2.ZERO
|
||||
|
||||
var current_zoom = default_zoom
|
||||
var zoom_min = 4
|
||||
var zoom_max = 80
|
||||
var zoom_speed = 20
|
||||
|
||||
func _lock():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _unlock():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
mouse_velocity = Vector2.ZERO
|
||||
|
||||
func lock():
|
||||
_lock()
|
||||
locked = true
|
||||
|
||||
# optional API function for nodes that want
|
||||
# to unlock the mouse for a period of time
|
||||
func unlock():
|
||||
_unlock()
|
||||
locked = false
|
||||
|
||||
func reset():
|
||||
basis = Basis()
|
||||
$InnerGimbal.basis = Basis()
|
||||
current_zoom = default_zoom
|
||||
|
||||
# y is before x because the outer gimbal is
|
||||
# in charge of rotating the y axis
|
||||
func rotate_camera(delta):
|
||||
var y = 0
|
||||
var x = 0
|
||||
|
||||
if mouse_velocity.x > 5 or mouse_velocity.x < -5:
|
||||
y -= clamp(mouse_velocity.x / 12.5, -10, 10)
|
||||
if mouse_velocity.y > 5 or mouse_velocity.y < -5:
|
||||
x -= clamp(mouse_velocity.y / 12.5, -10, 10)
|
||||
|
||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||
$InnerGimbal.rotate_object_local(
|
||||
Vector3.RIGHT, x * rotation_speed * delta)
|
||||
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -0.8, 0.7)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_velocity = event.relative
|
||||
elif event.is_action_pressed("cam_zoom_out"):
|
||||
current_zoom += 1
|
||||
elif event.is_action_pressed("cam_zoom_in"):
|
||||
current_zoom -= 1
|
||||
|
||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||
|
||||
func _process(delta):
|
||||
# rotate camera
|
||||
if locked:
|
||||
rotate_camera(delta)
|
||||
else:
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||
_lock()
|
||||
rotate_camera(delta)
|
||||
else:
|
||||
_unlock()
|
||||
|
||||
# zoom in/out
|
||||
var pos = Vector3($InnerGimbal/Camera3D.position)
|
||||
pos.y = lerp(pos.y, float(current_zoom), zoom_speed * delta)
|
||||
pos.z = lerp(pos.z, float(current_zoom), zoom_speed * delta)
|
||||
|
||||
$InnerGimbal/Camera3D.position = pos
|
||||
|
||||
# reset camera
|
||||
if Input.is_action_pressed("cam_reset"):
|
||||
reset()
|
||||
|
||||
func _ready():
|
||||
lock()
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
class_name CameraGimbal extends Node3D
|
||||
|
||||
@export var rotation_speed = (PI / 180) * 120
|
||||
@export var shift_lock = false
|
||||
|
||||
var locked_mouse_positon = Vector2(0,0)
|
||||
var mouse_locked = false
|
||||
var mouse_x_velocity = 0
|
||||
var mouse_y_velocity = 0
|
||||
|
||||
var zoom_min = 4
|
||||
var zoom_max = 80
|
||||
var zoom_speed = 20
|
||||
var current_zoom = 8
|
||||
|
||||
func reset():
|
||||
basis = Basis()
|
||||
$InnerGimbal.basis = Basis()
|
||||
|
||||
func rotate_camera_y(y, delta):
|
||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||
func rotate_camera_x(x, delta):
|
||||
$InnerGimbal.rotate_object_local(
|
||||
Vector3.RIGHT, x * rotation_speed * delta)
|
||||
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x,-0.8,0.7)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_x_velocity = event.relative.x
|
||||
mouse_y_velocity = event.relative.y
|
||||
elif event.is_action_pressed("zoom_out"):
|
||||
current_zoom += 1
|
||||
elif event.is_action_pressed("zoom_in"):
|
||||
current_zoom -= 1
|
||||
|
||||
func _process(delta):
|
||||
# rotate outer gimbal around y axis
|
||||
var y = 0
|
||||
var x = 0
|
||||
|
||||
if Input.is_action_just_pressed("shift_lock"):
|
||||
if shift_lock == true:
|
||||
shift_lock = false
|
||||
else:
|
||||
shift_lock = true
|
||||
elif Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or shift_lock == true:
|
||||
if mouse_locked == false:
|
||||
mouse_locked = true
|
||||
locked_mouse_positon = get_viewport().get_mouse_position()
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
if mouse_x_velocity > 5 or mouse_x_velocity < -5:
|
||||
y -= clamp(mouse_x_velocity / 12.5, -10, 10)
|
||||
if mouse_y_velocity > 5 or mouse_y_velocity < -5:
|
||||
x -= clamp(mouse_y_velocity / 12.5, -10, 10)
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
mouse_locked = false
|
||||
mouse_x_velocity = 0
|
||||
mouse_y_velocity = 0
|
||||
|
||||
rotate_camera_y(y, delta)
|
||||
rotate_camera_x(x, delta)
|
||||
|
||||
# reset gimbals
|
||||
if Input.is_action_pressed("cam_reset"):
|
||||
reset()
|
||||
|
||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||
|
||||
var pos = Vector3($InnerGimbal/Camera3D.position)
|
||||
pos.y = lerp(pos.y, float(current_zoom), zoom_speed*delta)
|
||||
pos.z = lerp(pos.z, float(current_zoom), zoom_speed*delta)
|
||||
|
||||
$InnerGimbal/Camera3D.position = pos
|
||||
|
|
@ -18,6 +18,11 @@ var target_velocity = Vector3.ZERO
|
|||
|
||||
var _health = 100
|
||||
|
||||
# Multiplayer
|
||||
|
||||
func _enter_tree():
|
||||
set_multiplayer_authority(str(name).to_int())
|
||||
|
||||
# Player UI
|
||||
|
||||
func resize_ui():
|
||||
|
|
@ -239,8 +244,18 @@ func _ready():
|
|||
resize_ui()
|
||||
respawn()
|
||||
|
||||
if is_multiplayer_authority():
|
||||
$CameraGimbal/InnerGimbal/Camera3D.current = true
|
||||
else:
|
||||
$CameraGimbal/InnerGimbal/Camera3D.current = false
|
||||
|
||||
func _physics_process(delta):
|
||||
if dead:
|
||||
if dead or not is_multiplayer_authority():
|
||||
return
|
||||
if health() < 1 or position.y <= -1000:
|
||||
die()
|
||||
|
||||
if suspended:
|
||||
return
|
||||
|
||||
if health() < 1 or position.y <= -1000:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=8 format=4 uid="uid://cfceg80unq0pe"]
|
||||
[gd_scene load_steps=9 format=4 uid="uid://cfceg80unq0pe"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bfflnag3p4gen" path="res://player/player.gd" id="1_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera_gimbal.gd" id="2_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://djeyfi7vm2vw0" path="res://player/player.gd" id="1_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera.gd" id="2_onrkg"]
|
||||
[ext_resource type="Texture2D" uid="uid://cfb0gbwm57hm4" path="res://models/player_0.png" id="3_hqtel"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_onrkg"]
|
||||
|
|
@ -47,6 +47,32 @@ _surfaces = [{
|
|||
}]
|
||||
shadow_mesh = SubResource("ArrayMesh_e57bw")
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_g1dw6"]
|
||||
properties/0/path = NodePath(".:position")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
properties/1/path = NodePath(".:rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
properties/2/path = NodePath("CameraGimbal:position")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 1
|
||||
properties/3/path = NodePath("CameraGimbal:rotation")
|
||||
properties/3/spawn = true
|
||||
properties/3/replication_mode = 1
|
||||
properties/4/path = NodePath("CameraGimbal/InnerGimbal:position")
|
||||
properties/4/spawn = true
|
||||
properties/4/replication_mode = 1
|
||||
properties/5/path = NodePath("CameraGimbal/InnerGimbal:rotation")
|
||||
properties/5/spawn = true
|
||||
properties/5/replication_mode = 1
|
||||
properties/6/path = NodePath("CameraGimbal/InnerGimbal/Camera3D:position")
|
||||
properties/6/spawn = true
|
||||
properties/6/replication_mode = 1
|
||||
properties/7/path = NodePath("CameraGimbal/InnerGimbal/Camera3D:rotation")
|
||||
properties/7/spawn = true
|
||||
properties/7/replication_mode = 1
|
||||
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
|
|
@ -102,6 +128,9 @@ text = "Pictures of you"
|
|||
horizontal_alignment = 2
|
||||
vertical_alignment = 2
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_g1dw6")
|
||||
|
||||
[connection signal="child_entered_tree" from="Backpack" to="." method="_on_backpack_child_entered_tree"]
|
||||
[connection signal="child_exiting_tree" from="Backpack" to="." method="_on_backpack_child_exiting_tree"]
|
||||
[connection signal="timeout" from="RespawnTimer" to="." method="respawn"]
|
||||
|
|
|
|||
|
|
@ -42,26 +42,6 @@ jump={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_up={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_down={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_reset={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":79,"physical_keycode":0,"key_label":0,"unicode":111,"location":0,"echo":false,"script":null)
|
||||
|
|
@ -87,17 +67,12 @@ backpack_3={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":51,"physical_keycode":0,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
shift_lock={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
zoom_in={
|
||||
cam_zoom_in={
|
||||
"deadzone": 0.2,
|
||||
"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":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
zoom_out={
|
||||
cam_zoom_out={
|
||||
"deadzone": 0.2,
|
||||
"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":5,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
|
|
|
|||
27
server.gd
Normal file
27
server.gd
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
extends Node3D
|
||||
|
||||
@onready var menu = $UI/Menu
|
||||
|
||||
const PORT = 9999
|
||||
const PLAYER = preload("res://player/player.tscn")
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
|
||||
|
||||
|
||||
func _on_server_button_pressed() -> void:
|
||||
menu.hide()
|
||||
peer.create_server(PORT)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
multiplayer.peer_connected.connect(add_player)
|
||||
|
||||
add_player(multiplayer.get_unique_id())
|
||||
|
||||
func _on_client_button_pressed() -> void:
|
||||
menu.hide()
|
||||
peer.create_client("localhost",PORT)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
func add_player(peer_id):
|
||||
var player = PLAYER.instantiate()
|
||||
player.name = str(peer_id)
|
||||
add_child(player)
|
||||
Loading…
Add table
Add a link
Reference in a new issue