forked from unfa/liblast
Updated code for a new Godot version
parent
9d56d048b2
commit
173bea08b3
|
@ -109,7 +109,7 @@ func pick_random():
|
|||
assert(len(clips) > 0, "SoundPlayer has no clips to choose from")
|
||||
return randi() % len(clips)
|
||||
|
||||
@rpc(sync, any, reliable) func play():
|
||||
@rpc(call_local, any_peer, reliable) func play():
|
||||
|
||||
# temporary
|
||||
$AudioStreamPlayer3D.play()
|
||||
|
|
|
@ -120,7 +120,7 @@ var last_viewed_banner = null
|
|||
func view_banner(show:bool):
|
||||
focus_banner_show = show
|
||||
|
||||
@rpc(nosync, reliable, auth) func focus_banner(show:bool, type:=0 ):
|
||||
@rpc(authority, reliable) func focus_banner(show:bool, type:=0 ):
|
||||
if show:
|
||||
$FocusBanner.show()
|
||||
else:
|
||||
|
@ -131,13 +131,13 @@ func view_banner(show:bool):
|
|||
1: $FocusBanner.mesh.surface_get_material(0).set("albedo_texture", banner_chat)
|
||||
|
||||
|
||||
@rpc(auth, nosync,unreliable) func update_movement(player_transform, head_rotation, lin_velocity, jetpack):
|
||||
@rpc(authority, unreliable) func update_movement(player_transform, head_rotation, lin_velocity, jetpack):
|
||||
global_transform = player_transform
|
||||
head.set_rotation(head_rotation)
|
||||
jetpack_active = jetpack
|
||||
linear_velocity = lin_velocity
|
||||
motion_velocity = lin_velocity
|
||||
|
||||
@rpc(any, sync, reliable) func set_dead(is_dead: bool):
|
||||
@rpc(any_peer, call_local, reliable) func set_dead(is_dead: bool):
|
||||
#print("Recieved RPC call for set_dead ", is_dead)
|
||||
self.dead = is_dead
|
||||
|
||||
|
@ -276,7 +276,7 @@ func _process(delta):
|
|||
# weapon spread
|
||||
weapon.spread = max(lerp(weapon.spread, weapon.spread_min, weapon.spread_lerp), weapon.spread_min)
|
||||
|
||||
@rpc(sync, any, reliable) func moan():
|
||||
@rpc(call_local, any_peer, reliable) func moan():
|
||||
var anims = ["01", "02", "03", "04"]
|
||||
$Pain.play(anims[randi() % 4])
|
||||
|
||||
|
@ -284,7 +284,7 @@ func damage(hp: int):
|
|||
var target = main.player_list.players[self.get_multiplayer_authority()]
|
||||
target.health -= hp
|
||||
|
||||
@rpc(any, sync, reliable) func die(killer_pid: int):
|
||||
@rpc(any_peer, call_local, reliable) func die(killer_pid: int):
|
||||
var gibs = gibs_vfx.instantiate()
|
||||
get_tree().root.add_child(gibs)
|
||||
gibs.global_transform = self.global_transform
|
||||
|
@ -317,7 +317,7 @@ func update_color(color) -> void: #change player's wolrldmodel color
|
|||
|
||||
func _physics_process(delta):
|
||||
if dead: # workaround for Godot player destruction crash
|
||||
linear_velocity = Vector3.ZERO
|
||||
motion_velocity = Vector3.ZERO
|
||||
return
|
||||
|
||||
if not is_multiplayer_authority():
|
||||
|
@ -373,15 +373,15 @@ func _physics_process(delta):
|
|||
|
||||
velocity = velocity.lerp(direction * speed, accel * delta)
|
||||
|
||||
linear_velocity = velocity + gravity_vec
|
||||
motion_velocity = velocity + gravity_vec
|
||||
move_and_slide()
|
||||
|
||||
if not is_on_floor() and not ground_check.is_colliding(): # while in mid-air collisions affect momentum
|
||||
velocity.x = linear_velocity.x
|
||||
velocity.z = linear_velocity.z
|
||||
gravity_vec.y = linear_velocity.y
|
||||
velocity.x = motion_velocity.x
|
||||
velocity.z = motion_velocity.z
|
||||
gravity_vec.y = motion_velocity.y
|
||||
|
||||
rpc(&'update_movement', global_transform, head.get_rotation(), linear_velocity, jetpack_active)
|
||||
rpc(&'update_movement', global_transform, head.get_rotation(), motion_velocity, jetpack_active)
|
||||
|
||||
# (stair) climbing
|
||||
# ↓ disabled - Tween is undergoing redesign in Godot 4
|
||||
|
|
|
@ -52,7 +52,7 @@ func _unhandled_input(_event) -> void:
|
|||
get_tree().get_root().set_input_as_handled()
|
||||
|
||||
# doesn't work over network due to missing RPC implementation in Godot 4
|
||||
@rpc(sync, any, reliable) func chat_message(sender_pid: int, recipient_team, message: String) -> void:
|
||||
@rpc(call_local, any_peer, reliable) func chat_message(sender_pid: int, recipient_team, message: String) -> void:
|
||||
var sender_info = main.player_list.get(sender_pid)
|
||||
chat_history.append_text('\n' + '[b][color=' + sender_info.color.to_html() +']' + str(sender_info.name) + '[/color][/b] : [i]' + message + '[/i]')
|
||||
$Message.play()
|
||||
|
|
|
@ -27,7 +27,7 @@ var spread = spread_min
|
|||
|
||||
#enum Trigger {TRIGGER_PRIMARY, TRIGGER_SECONDARY}
|
||||
|
||||
@rpc(any, sync, reliable) func shoot(spread_offset:=Vector3.ZERO):
|
||||
@rpc(any_peer, call_local, reliable) func shoot(spread_offset:=Vector3.ZERO):
|
||||
|
||||
var space_state = get_world_3d().direct_space_state
|
||||
|
||||
|
@ -54,8 +54,8 @@ var spread = spread_min
|
|||
var casing_instance = casing.instantiate()
|
||||
get_tree().root.add_child(casing_instance)
|
||||
|
||||
casing_instance.global_transform = ejector.global_transform.translated(player.linear_velocity / 60) #approximating delta
|
||||
casing_instance.linear_velocity = ejector.global_transform.basis[1] * randf_range(3.2, 4.5) + (player.linear_velocity / 2)
|
||||
casing_instance.global_transform = ejector.global_transform.translated(player.motion_velocity / 60) #approximating delta
|
||||
casing_instance.linear_velocity = ejector.global_transform.basis[1] * randf_range(3.2, 4.5) + (player.motion_velocity / 2)
|
||||
casing_instance.angular_velocity.y += randf_range(-10, 10)
|
||||
casing_instance.angular_velocity.x += randf_range(-10, 10)
|
||||
|
||||
|
|
17
Game/Main.gd
17
Game/Main.gd
|
@ -13,7 +13,7 @@ var peer = ENetMultiplayerPeer.new()
|
|||
var role = MultiplayerRole.NONE:
|
||||
set(new_role):
|
||||
role = new_role
|
||||
print("Multiplayer Role changed to ", MultiplayerRole.keys()[new_role])
|
||||
# print("Multiplayer Role changed to ", MultiplayerRole.keys()[new_role])
|
||||
|
||||
var player_scene = preload("res://Assets/Characters/Player.tscn")
|
||||
|
||||
|
@ -80,6 +80,8 @@ const destroy_free_player_crash_workaround = true
|
|||
func _process(delta):
|
||||
uptime += delta
|
||||
|
||||
#print($GUI.settings)
|
||||
|
||||
$Label.text = "player_list: \n"
|
||||
for i in player_list.players.keys():
|
||||
if player_list.players[i]:
|
||||
|
@ -137,6 +139,7 @@ class PlayerList:
|
|||
|
||||
var focus:GameFocus:
|
||||
set(new_focus):
|
||||
# print("Focus set to ", new_focus)
|
||||
if local_player != null:
|
||||
assert(local_player != null, "local_player is not null but it is null, WTF?!")
|
||||
match new_focus:
|
||||
|
@ -169,15 +172,17 @@ func _input(_event) -> void:
|
|||
if Input.is_action_just_pressed("ui_cancel"):
|
||||
if focus == GameFocus.GAME:
|
||||
focus = GameFocus.MENU
|
||||
#get_tree().root.set_input_as_handled()
|
||||
elif focus == GameFocus.MENU:
|
||||
focus = GameFocus.GAME
|
||||
#get_tree().root.set_input_as_handled()
|
||||
|
||||
if Input.is_action_just_pressed("show_scoretab"):
|
||||
hud.scoretab(true)
|
||||
elif Input.is_action_just_released("show_scoretab"):
|
||||
hud.scoretab(false)
|
||||
|
||||
@rpc(any, sync, reliable) func game_over(winner):
|
||||
@rpc(any_peer, call_local, reliable) func game_over(winner):
|
||||
if local_player:
|
||||
local_player.rpc(&'set_dead', true)
|
||||
hud.game_over(winner)
|
||||
|
@ -236,7 +241,7 @@ func update_hud():
|
|||
else:
|
||||
hud.get_node("ScoreRank").text += str(rank) + "\nGAP: " + str(-lead)
|
||||
|
||||
@rpc(any, reliable) func player_list_update(info, pid = get_tree().get_rpc_sender_id(), erase:=false):
|
||||
@rpc(any_peer, reliable) func player_list_update(info, pid = get_tree().get_rpc_sender_id(), erase:=false):
|
||||
if erase:
|
||||
player_list.erase(pid)
|
||||
|
||||
|
@ -265,7 +270,7 @@ func push_local_player_info(): #
|
|||
var pid = get_tree().multiplayer.get_unique_id()
|
||||
rpc(&'player_list_update', player_list.get(pid).serialize(), pid)
|
||||
|
||||
@rpc(sync, any, reliable) func destroy_player(pid: int):
|
||||
@rpc(call_local, any_peer, reliable) func destroy_player(pid: int):
|
||||
print("DESTROY_PLAYER called on ", get_tree().multiplayer.get_unique_id(), " by ", get_tree().multiplayer.get_remote_sender_id(), " regarding ", pid)
|
||||
|
||||
#assert($Players.has_node(str(pid)), "Attempting to destroy a player that does not exist")
|
||||
|
@ -485,3 +490,7 @@ func change_player_name(player_name):
|
|||
if get_tree().multiplayer.has_multiplayer_peer():
|
||||
player_list.players[get_tree().multiplayer.get_unique_id()].name = player_name
|
||||
push_local_player_info()
|
||||
|
||||
|
||||
func _on_Disconnect_pressed():
|
||||
get_tree().multiplayer.multiplayer_peer = null
|
||||
|
|
Loading…
Reference in New Issue