From 9283a3263f42c5324f4dc92e6054d871d4dc5196 Mon Sep 17 00:00:00 2001 From: Dustin Date: Thu, 17 Apr 2025 23:05:15 -0700 Subject: [PATCH] A whole lotta bodges for multiplayer. Gonna need to rethink some things. --- lib/classes/actor.gd | 7 +-- src/actors/players/playerE/PlayerE.gd | 74 ++++++++++++++------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/lib/classes/actor.gd b/lib/classes/actor.gd index 41109db..17c8a2d 100644 --- a/lib/classes/actor.gd +++ b/lib/classes/actor.gd @@ -37,9 +37,10 @@ func _ready() -> void: puppet_anim_sprite_name = animated_sprite.animation puppet_anim_sprite_frame = animated_sprite.frame puppet_transform = transform -# if not is_network_master(): -# animated_sprite.set_process(false) -# animated_sprite.set_physics_process(false) + ## Disable Process and Physics on puppets + if not is_network_master(): + animated_sprite.set_process(false) + animated_sprite.set_physics_process(false) #movement_state_machine.init_animated_actor(self) #movement_component.attack_function = funcref(self, "attack") # movement_component.player_number = player_number diff --git a/src/actors/players/playerE/PlayerE.gd b/src/actors/players/playerE/PlayerE.gd index c94d1bf..c214e91 100644 --- a/src/actors/players/playerE/PlayerE.gd +++ b/src/actors/players/playerE/PlayerE.gd @@ -35,13 +35,17 @@ func _ready(): PlayerInfo.player_inventory = player_inventory # PlayerInfo.player_stamina = stamina_component.stamina - player_info_index = PlayerInfo.register_player() - print ("Registered as player: ", player_info_index) - player_data = PlayerInfo.get_player_data(player_info_index) - PlayerInfo.get_player_data(player_info_index).player_health = health_component.health - print ("My health is: ", player_data.player_health) - player_data.player_inventory = player_inventory - player_data.player_stamina = stamina_component.stamina + # I think we only want to do this for network master players now + if is_network_master(): + player_info_index = PlayerInfo.register_player() + print ("Registered as player: ", player_info_index) + player_data = PlayerInfo.get_player_data(player_info_index) + PlayerInfo.get_player_data(player_info_index).player_health = health_component.health + print ("My health is: ", player_data.player_health) + player_data.player_inventory = player_inventory + player_data.player_stamina = stamina_component.stamina + else: + $Hurtbox_Component.hurtbox_entered_function = '' # Set initial player position in world. global_position = LevelInfo.player_start_position @@ -50,41 +54,39 @@ func _ready(): player_inventory.select_primary(punch_item) movement_component.state_stamina_cost = state_stamina_cost - - puppet_pos = position - #var stamina_recovery :float = 0.0 # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - #PlayerInfo.player_position = global_position.round() - player_data.player_position = global_position.round() -# stamina_recovery += delta -# if stamina_recovery > 1.0: -# stamina_component.recover(1) -# stamina_recovery = 0.0 -# #print("recover ", stamina_component.stamina) - - #PlayerInfo.player_stamina = stamina_component.stamina - player_data.player_stamina = stamina_component.stamina + if is_network_master(): + #PlayerInfo.player_position = global_position.round() + player_data.player_position = global_position.round() + # stamina_recovery += delta + # if stamina_recovery > 1.0: + # stamina_component.recover(1) + # stamina_recovery = 0.0 + # #print("recover ", stamina_component.stamina) + + #PlayerInfo.player_stamina = stamina_component.stamina + player_data.player_stamina = stamina_component.stamina - ##TODO: well I'm not sure I like this but making a whole state receiver is silly - if state_damage_amount.has(movement_state_machine.current_state.name): - $Hitbox_Component.damage_amount = state_damage_amount[movement_state_machine.current_state.name] - else: - $Hitbox_Component.damage_amount = 10 - - match movement_state_machine.current_state.name: - "idle": - if Input.is_action_just_released("switch_primary_item_" + str(player_number)): - var _selected_item = player_inventory.switch_primary() - if _selected_item: - print("Switched Primary item to: ", _selected_item.name) - elif Input.is_action_just_released("switch_secondary_item_" + str(player_number)): - var _selected_item = player_inventory.switch_secondary() - if _selected_item: - print("Switched Secondary item to: ", _selected_item.name) + ##TODO: well I'm not sure I like this but making a whole state receiver is silly + if state_damage_amount.has(movement_state_machine.current_state.name): + $Hitbox_Component.damage_amount = state_damage_amount[movement_state_machine.current_state.name] + else: + $Hitbox_Component.damage_amount = 10 + + match movement_state_machine.current_state.name: + "idle": + if Input.is_action_just_released("switch_primary_item_" + str(player_number)): + var _selected_item = player_inventory.switch_primary() + if _selected_item: + print("Switched Primary item to: ", _selected_item.name) + elif Input.is_action_just_released("switch_secondary_item_" + str(player_number)): + var _selected_item = player_inventory.switch_secondary() + if _selected_item: + print("Switched Secondary item to: ", _selected_item.name)