Multiplayer fully works

This commit is contained in:
Paul Black 2023-02-22 21:31:22 -07:00
parent a7ce62450a
commit 25a876f71a
43 changed files with 3533 additions and 81 deletions

View file

@ -10,16 +10,20 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@export var Bullet = preload("res://objects/Bullet/Bullet.tscn") @export var Bullet = preload("res://objects/Bullet/Bullet.tscn")
@onready var neck := $CollisionShape3D/Neck @onready var neck := $CollisionShape3D/Neck
@onready var camera := $CollisionShape3D/Neck/Camera3D @onready var camera := $CollisionShape3D/Neck/Camera3D
@onready var selfTeddy = self.get_path() var selfTeddy
@onready var teddyParent = get_node(selfTeddy).get_parent() var teddyParent
var globalscene var globalscene
func _ready(): func _ready():
name = str(get_multiplayer_authority())
Global.playingGame = true Global.playingGame = true
Global.selfTeddy = selfTeddy Global.selfTeddy = selfTeddy
selfTeddy = self.get_path()
teddyParent = get_node(selfTeddy).get_parent()
func _unhandled_input(event): func _unhandled_input(event):
Global.selfTeddy = selfTeddy
if event is InputEventMouseButton: if event is InputEventMouseButton:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
elif event.is_action_pressed("ui_cancel"): elif event.is_action_pressed("ui_cancel"):
@ -45,64 +49,82 @@ func _unhandled_input(event):
globalscene.queue_free() globalscene.queue_free()
func _physics_process(delta): func _physics_process(delta):
# Add the gravity. if is_multiplayer_authority():
if not is_on_floor(): # Add the gravity.
velocity.y -= gravity * delta if not is_on_floor():
# This variable gets set my the death scene, so we know the player needs to be respawned velocity.y -= gravity * delta
if Global.playerPleaseRespawn == true: # This variable gets set my the death scene, so we know the player needs to be respawned
position.x = 0 #Set player X if Global.playerPleaseRespawn == true:
position.y = 1 #Set player Y position.x = 0 #Set player X
position.z = 0 #Set player Z position.y = 1 #Set player Y
Global.reset_variables() position.z = 0 #Set player Z
Global.reset_variables()
## If player falls off the map, kill them!
if velocity.y < Global.playerYDeath: ## If player falls off the map, kill them!
Global.playerHealth = 0 if velocity.y < Global.playerYDeath:
if Global.playerHealth <= 0: Global.playerHealth = 0
Global.player_dead() if Global.playerHealth <= 0:
Global.player_dead()
if Global.playerAlive:
# Handle Jump. if Global.playerAlive:
if Input.is_action_just_pressed("ui_accept") and is_on_floor(): # Handle Jump.
velocity.y = JUMP_VELOCITY if Input.is_action_just_pressed("ui_accept") and is_on_floor():
var input_dir = Input.get_vector("player_left", "player_right", "player_forward", "player_backward") velocity.y = JUMP_VELOCITY
var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() var input_dir = Input.get_vector("player_left", "player_right", "player_forward", "player_backward")
if Input.is_action_pressed("sprint"): var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if Global.fatigue > 5: if Input.is_action_pressed("sprint"):
SPEED = 10.0 if Global.fatigue > 5:
if Global.fatigue < 5: SPEED = 10.0
SPEED = 2.0 if Global.fatigue < 5:
if Input.is_action_pressed("sprint"): SPEED = 2.0
pass if Input.is_action_pressed("sprint"):
elif Global.fatigue > 5: pass
SPEED = 5.0 elif Global.fatigue > 5:
if Input.is_action_just_released("sprint"): SPEED = 5.0
SPEED = 5.0 if Input.is_action_just_released("sprint"):
if direction: SPEED = 5.0
velocity.x = direction.x * SPEED if direction:
velocity.z = direction.z * SPEED velocity.x = direction.x * SPEED
else: velocity.z = direction.z * SPEED
velocity.x = move_toward(velocity.x, 0, SPEED) else:
velocity.z = move_toward(velocity.z, 0, SPEED) velocity.x = move_toward(velocity.x, 0, SPEED)
if Global.playerDead: velocity.z = move_toward(velocity.z, 0, SPEED)
velocity.x = 0 if Global.playerDead:
velocity.z = 0 velocity.x = 0
if Input.is_action_just_pressed("shoot"): velocity.z = 0
if Global.menuOpen == false: if Input.is_action_just_pressed("shoot"):
print("shoot") if Global.menuOpen == false:
var b = Bullet.instantiate() if Global.multiplayerCurrent == true:
teddyParent.add_child(b) rpc("shoot_bullet", 1)
b.transform = $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_transform shoot_bullet(0)
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity else:
if Input.is_action_just_pressed("console"): shoot_bullet(1)
var scene_trs = load("res://scenes/console.tscn") if Input.is_action_just_pressed("console"):
var scene = scene_trs.instantiate() var scene_trs = load("res://scenes/console.tscn")
if not Global.consoleOpen: var scene = scene_trs.instantiate()
Global.consoleOpen = true if not Global.consoleOpen:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) Global.consoleOpen = true
add_child(scene) Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
elif Global.consoleOpen: add_child(scene)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) elif Global.consoleOpen:
Global.consoleOpen = false # We remove the scene in console.gd Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
move_and_slide() Global.consoleOpen = false # We remove the scene in console.gd
rpc("remote_set_position", global_position, $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_position, $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_rotation)
move_and_slide()
@rpc("any_peer", "unreliable")
func remote_set_position(authority_position, bulletgenerator_position, bulletgenerator_rotation):
global_position = authority_position
$CollisionShape3D/Neck/Camera3D/BulletGenerator.global_position = bulletgenerator_position
$CollisionShape3D/Neck/Camera3D/BulletGenerator.global_rotation = bulletgenerator_rotation
@rpc("any_peer", "reliable")
func shoot_bullet(sound):
var b = Bullet.instantiate()
teddyParent.add_child(b)
b.transform = $CollisionShape3D/Neck/Camera3D/BulletGenerator.global_transform
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
if sound == 1:
$sound.stream = load("res://sounds/pistol_shoot.wav")
$sound.play()

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bhnl0h66m0jst"
path="res://.godot/imported/Wood050_2K_Color.jpg.001.jpg-9f5b9ace6c04569729f5d745a25bcc3f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://objects/toyland/Wood050_2K_Color.jpg.001.jpg"
dest_files=["res://.godot/imported/Wood050_2K_Color.jpg.001.jpg-9f5b9ace6c04569729f5d745a25bcc3f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dnobq0anmbln8"
path.s3tc="res://.godot/imported/Wood050_2K_Color.jpg-e6185de0fa12ff4588e435b3845fb87e.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://objects/toyland/Wood050_2K_Color.jpg"
dest_files=["res://.godot/imported/Wood050_2K_Color.jpg-e6185de0fa12ff4588e435b3845fb87e.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://rdm6mfwbwg6s"
path="res://.godot/imported/newplaster.jpg.001.jpg-4d68a0e7c6211fbeba658a0e6fc2cd5f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://objects/toyland/newplaster.jpg.001.jpg"
dest_files=["res://.godot/imported/newplaster.jpg.001.jpg-4d68a0e7c6211fbeba658a0e6fc2cd5f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cmhq2gjngssxg"
path.s3tc="res://.godot/imported/newplaster.jpg-c0159d01e1a6adffe0c3bf5b8dcfc7a7.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://objects/toyland/newplaster.jpg"
dest_files=["res://.godot/imported/newplaster.jpg-c0159d01e1a6adffe0c3bf5b8dcfc7a7.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 407 KiB

View file

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c4brgjvonnjkr"
path.s3tc="res://.godot/imported/toyland-acc3ec7302587eef6111479be4ff2e5f_Wood050_2K_Color.png-09e60c6431251b5cdad5e7603ca8ef91.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={}
[deps]
source_file="res://objects/toyland/toyland-acc3ec7302587eef6111479be4ff2e5f_Wood050_2K_Color.png"
dest_files=["res://.godot/imported/toyland-acc3ec7302587eef6111479be4ff2e5f_Wood050_2K_Color.png-09e60c6431251b5cdad5e7603ca8ef91.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 KiB

View file

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ql40b60xucke"
path.s3tc="res://.godot/imported/toyland-acc3ec7302587eef6111479be4ff2e5f_newplaster.png-56bf5185a878e2d32e5a25ec8c8517fb.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={}
[deps]
source_file="res://objects/toyland/toyland-acc3ec7302587eef6111479be4ff2e5f_newplaster.png"
dest_files=["res://.godot/imported/toyland-acc3ec7302587eef6111479be4ff2e5f_newplaster.png-56bf5185a878e2d32e5a25ec8c8517fb.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 KiB

View file

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cj28kq4i36gcg"
path.s3tc="res://.godot/imported/toyland-acc3ec7302587eef6111479be4ff2e5f_windows_xp_bliss-wide.png-c0ea880c9d43e5d1d8d800dd069f83dd.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={}
[deps]
source_file="res://objects/toyland/toyland-acc3ec7302587eef6111479be4ff2e5f_windows_xp_bliss-wide.png"
dest_files=["res://.godot/imported/toyland-acc3ec7302587eef6111479be4ff2e5f_windows_xp_bliss-wide.png-c0ea880c9d43e5d1d8d800dd069f83dd.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,32 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://c3gou5ubatac0"
path="res://.godot/imported/toylandnocolliders.dae-8a4ebb92a340a4c00fd2c8b7efc1aae4.scn"
[deps]
source_file="res://objects/toyland/toylandnocolliders.dae"
dest_files=["res://.godot/imported/toylandnocolliders.dae-8a4ebb92a340a4c00fd2c8b7efc1aae4.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/embedded_image_handling=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://diruf5vyv41pv"
path="res://.godot/imported/windows_xp_bliss-wide.jpg.001.jpg-1ed28ba1c5c304ae15d500fa2d1079b2.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://objects/toyland/windows_xp_bliss-wide.jpg.001.jpg"
dest_files=["res://.godot/imported/windows_xp_bliss-wide.jpg.001.jpg-1ed28ba1c5c304ae15d500fa2d1079b2.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://co6sxyhce6s7"
path.s3tc="res://.godot/imported/windows_xp_bliss-wide.jpg-b027b98d80d6be8ceaca628f4dcf54ce.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://objects/toyland/windows_xp_bliss-wide.jpg"
dest_files=["res://.godot/imported/windows_xp_bliss-wide.jpg-b027b98d80d6be8ceaca628f4dcf54ce.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b6f2baaxv23qx"
path.s3tc="res://.godot/imported/woodfloor4k.jpg.001.jpg-e2bdf4950350ecebed41e5db675a15f9.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://objects/toyland/woodfloor4k.jpg.001.jpg"
dest_files=["res://.godot/imported/woodfloor4k.jpg.001.jpg-e2bdf4950350ecebed41e5db675a15f9.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c0vfrlgxpq8u3"
path="res://.godot/imported/woodfloor4k.jpg.002.jpg-e9a77dc5f9ec4b59da6d965ef9e2746d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://objects/toyland/woodfloor4k.jpg.002.jpg"
dest_files=["res://.godot/imported/woodfloor4k.jpg.002.jpg-e9a77dc5f9ec4b59da6d965ef9e2746d.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -24,7 +24,6 @@ Networking="*res://scripts/networking.gd"
[display] [display]
window/size/mode=3
window/stretch/mode="canvas_items" window/stretch/mode="canvas_items"
[input] [input]
@ -67,6 +66,7 @@ shoot={
console={ console={
"deadzone": 0.5, "deadzone": 0.5,
"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":96,"key_label":0,"unicode":96,"echo":false,"script":null) "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":96,"key_label":0,"unicode":96,"echo":false,"script":null)
, 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":167,"key_label":0,"unicode":96,"echo":false,"script":null)
] ]
} }
console_send={ console_send={

View file

@ -22,3 +22,5 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.104801, -0.858231)
[node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"] [node name="MeshInstance3D" type="MeshInstance3D" parent="CollisionShape3D"]
mesh = SubResource("CapsuleMesh_ucocb") mesh = SubResource("CapsuleMesh_ucocb")
skeleton = NodePath("") skeleton = NodePath("")
[node name="sound" type="AudioStreamPlayer3D" parent="."]

View file

@ -24,3 +24,5 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.859224, 0)
[node name="BulletGenerator" type="Marker3D" parent="CollisionShape3D/Neck/Camera3D"] [node name="BulletGenerator" type="Marker3D" parent="CollisionShape3D/Neck/Camera3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.104801, -0.858231) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.104801, -0.858231)
[node name="sound" type="AudioStreamPlayer3D" parent="."]

View file

@ -69,7 +69,7 @@ offset_left = 646.0
offset_top = 248.0 offset_top = 248.0
offset_right = 797.0 offset_right = 797.0
offset_bottom = 283.0 offset_bottom = 283.0
text = "Playground" text = "Toyland"
[node name="portBox" type="LineEdit" parent="."] [node name="portBox" type="LineEdit" parent="."]
layout_mode = 0 layout_mode = 0

View file

@ -8,12 +8,12 @@ sky_top_color = Color(0.870588, 0.894118, 0.92549, 1)
sky_horizon_color = Color(0.767647, 0.765779, 0.764623, 1) sky_horizon_color = Color(0.767647, 0.765779, 0.764623, 1)
ground_horizon_color = Color(0.767647, 0.765779, 0.764623, 1) ground_horizon_color = Color(0.767647, 0.765779, 0.764623, 1)
[sub_resource type="Sky" id="Sky_08e8u"] [sub_resource type="Sky" id="Sky_lh0lw"]
sky_material = SubResource("ProceduralSkyMaterial_ell6n") sky_material = SubResource("ProceduralSkyMaterial_ell6n")
[sub_resource type="Environment" id="Environment_fnphj"] [sub_resource type="Environment" id="Environment_fnphj"]
background_mode = 2 background_mode = 2
sky = SubResource("Sky_08e8u") sky = SubResource("Sky_lh0lw")
tonemap_mode = 2 tonemap_mode = 2
glow_enabled = true glow_enabled = true

13
scenes/toyland-map.tscn Normal file

File diff suppressed because one or more lines are too long

17
scenes/toyland.tscn Normal file
View file

@ -0,0 +1,17 @@
[gd_scene load_steps=4 format=3 uid="uid://bsdst5m5kpw0j"]
[ext_resource type="Script" path="res://scripts/maps/toyland.gd" id="1_vq5un"]
[ext_resource type="PackedScene" uid="uid://ytbacsuahxie" path="res://scenes/HUD.tscn" id="1_w2y7j"]
[ext_resource type="PackedScene" uid="uid://borjtj4hucqw7" path="res://scenes/toyland-map.tscn" id="3_uudje"]
[node name="toyland" type="Node3D"]
script = ExtResource("1_vq5un")
[node name="HUD" parent="." instance=ExtResource("1_w2y7j")]
show_behind_parent = true
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.0034906, -0.94887, 0.315647, 0, 0.315649, 0.948876, -0.999994, 0.00331215, -0.00110181, 0, 0, 0)
shadow_enabled = true
[node name="toylandnocolliders" parent="." instance=ExtResource("3_uudje")]

View file

@ -28,6 +28,8 @@ func _physics_process(delta):
owner.add_child(b) owner.add_child(b)
b.transform = $CollisionShape3D/Neck/BulletGenerator.global_transform b.transform = $CollisionShape3D/Neck/BulletGenerator.global_transform
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
$sound.stream = load("res://sounds/pistol_shoot.wav")
$sound.play()
elif bulletshot == true: elif bulletshot == true:
bulletshot = false bulletshot = false
bulletrandom = randf_range(1.0, 50.0) bulletrandom = randf_range(1.0, 50.0)

View file

@ -17,7 +17,8 @@ var consoleCommand # Defined by console.gd
var consoleOutput # Defined by console.gd var consoleOutput # Defined by console.gd
var godMode = false # Defined by console.gd var godMode = false # Defined by console.gd
var selfTeddy # Defined as soon as the player script is initalized var selfTeddy # Defined as soon as the player script is initalized
var multiplayerCurrent = false var multiplayerCurrent = false # Whether the player is using multiplayer
var currentMapNode # Defined in map scripts
func _process(delta): func _process(delta):
if godMode: if godMode:
@ -49,7 +50,3 @@ func reset_variables():
playerAlive = true playerAlive = true
playerPleaseRespawn = false playerPleaseRespawn = false
func add_player_character(mapNode):
var player_character = preload("res://scenes/Teddy.tscn").instantiate()
mapNode.add_child(player_character)
player_character.position.y = 1

View file

@ -15,8 +15,8 @@ func _on_close_pressed():
func _on_playground_pressed(): func _on_playground_pressed():
$mapSelected.text = "Playground" $mapSelected.text = "Toyland"
SCENE = "res://scenes/playground.tscn" SCENE = "res://scenes/toyland.tscn"
func _on_start_button_pressed(): func _on_start_button_pressed():
@ -37,6 +37,7 @@ func _on_start_button_pressed():
print("Player chose player limit: ", intMAX) print("Player chose player limit: ", intMAX)
Networking.create_server(intPORT, intMAX) Networking.create_server(intPORT, intMAX)
Networking.load_map(SCENE) Networking.load_map(SCENE)
Networking.add_player_node(1)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
else: else:
$mapSelected.text = "NO MAX PLAYERS SELECTED" $mapSelected.text = "NO MAX PLAYERS SELECTED"

View file

@ -3,10 +3,9 @@ extends Node
@onready var mapNode = get_node("/root/Playground") @onready var mapNode = get_node("/root/Playground")
func _ready(): func _ready():
Global.currentMapNode = mapNode
Global.playerHealth = 100 Global.playerHealth = 100
Global.fatigue = 100 Global.fatigue = 100
if Global.multiplayerCurrent == true:
Global.add_player_character(mapNode)
func _process(delta): func _process(delta):

13
scripts/maps/toyland.gd Normal file
View file

@ -0,0 +1,13 @@
extends Node
@onready var mapNode = get_node("/root/toyland")
func _ready():
Global.currentMapNode = mapNode
Global.playerHealth = 100
Global.fatigue = 100
Global.playerYDeath = -100
func _process(delta):
pass

View file

@ -1,7 +1,7 @@
extends Node extends Node
var peer = ENetMultiplayerPeer.new() var peer = ENetMultiplayerPeer.new()
var SCENE = "res://scenes/playground.tscn" var SCENE = "res://scenes/toyland.tscn"
func _ready(): func _ready():
$playerNameBox.text = Global.playerName $playerNameBox.text = Global.playerName

View file

@ -1,7 +1,7 @@
extends Node extends Node
var peer = ENetMultiplayerPeer.new() var peer = ENetMultiplayerPeer.new()
var SCENE = "res://scenes/playground.tscn" var SCENE = "res://scenes/toyland.tscn"
var connected_peers = [] var connected_peers = []
func create_server(port, maxPlayers): func create_server(port, maxPlayers):
@ -20,8 +20,9 @@ func create_server(port, maxPlayers):
func(new_peer_id): func(new_peer_id):
print("NEW CONNECTION FROM ", new_peer_id) print("NEW CONNECTION FROM ", new_peer_id)
await get_tree().create_timer(0.5).timeout ## REQUIRED, THE RPC IS MADE BEFORE THE CLIENT IS FULLY CONNECTED await get_tree().create_timer(0.5).timeout ## REQUIRED, THE RPC IS MADE BEFORE THE CLIENT IS FULLY CONNECTED
connected_peers.append(new_peer_id) rpc("add_newly_connected_player_character", new_peer_id)
rpc_id(new_peer_id, "add_newly_connected_player_character") rpc_id(new_peer_id, "add_previously_connected_player_characters", connected_peers)
add_player_node(new_peer_id)
) )
func load_map(map): func load_map(map):
@ -29,7 +30,24 @@ func load_map(map):
get_tree().change_scene_to_file(map) get_tree().change_scene_to_file(map)
@rpc("any_peer", "call_remote") @rpc("any_peer", "call_remote")
func add_newly_connected_player_character(): func add_newly_connected_player_character(new_peer_id):
print("Connected to server!") print("Connected to server!")
load_map(SCENE) load_map(SCENE)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
add_player_node(new_peer_id)
func add_player_node(peer_id):
connected_peers.append(peer_id)
var player_character = preload("res://scenes/Teddy.tscn").instantiate()
player_character.set_multiplayer_authority(peer_id)
await get_tree().create_timer(0.5).timeout
Global.currentMapNode.add_child(player_character)
player_character.position.y = 10
@rpc
func add_previously_connected_player_characters(peer_ids):
await get_tree().create_timer(0.5).timeout
for peer_id in peer_ids:
add_player_node(peer_id)

BIN
sounds/pistol_reload.wav Normal file

Binary file not shown.

View file

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://cn82krq4rp7wf"
path="res://.godot/imported/pistol_reload.wav-2f9958349b7fe2240d05494dce99f911.sample"
[deps]
source_file="res://sounds/pistol_reload.wav"
dest_files=["res://.godot/imported/pistol_reload.wav-2f9958349b7fe2240d05494dce99f911.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0

BIN
sounds/pistol_shoot.wav Normal file

Binary file not shown.

View file

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://bt2g2j7d74cyv"
path="res://.godot/imported/pistol_shoot.wav-0a904657f8ee886da7af21840d2b5128.sample"
[deps]
source_file="res://sounds/pistol_shoot.wav"
dest_files=["res://.godot/imported/pistol_shoot.wav-0a904657f8ee886da7af21840d2b5128.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0