One step closer to multiplayer

This commit is contained in:
Dustin 2025-04-17 22:23:16 -07:00
parent 8a29cc5be3
commit 0248be637d
2 changed files with 58 additions and 40 deletions

View File

@ -19,6 +19,13 @@ onready var movement_component: Movement_StateReceiver = $Movement_StateReceiver
#onready var movement_state_machine: StateMachineAnimatedActor = $movement_state_machine #onready var movement_state_machine: StateMachineAnimatedActor = $movement_state_machine
onready var movement_state_machine: StateMachine = $Movement_StateMachine onready var movement_state_machine: StateMachine = $Movement_StateMachine
onready var animated_sprite : AnimatedSprite = $AnimatedSprite_StateReceiver
## Multiplayer Variables
puppet var puppet_pos = Vector2()
puppet var puppet_anim_sprite_frame :int
puppet var puppet_anim_sprite_name :String
puppet var puppet_transform: Transform2D
##TODO: ##TODO:
# Can't seem to implement the ready and process node functions # Can't seem to implement the ready and process node functions
@ -27,23 +34,42 @@ onready var movement_state_machine: StateMachine = $Movement_StateMachine
# interfaces for the state machines. # interfaces for the state machines.
func _ready() -> void: func _ready() -> void:
pass 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)
#movement_state_machine.init_animated_actor(self) #movement_state_machine.init_animated_actor(self)
#movement_component.attack_function = funcref(self, "attack") #movement_component.attack_function = funcref(self, "attack")
# movement_component.player_number = player_number # movement_component.player_number = player_number
func _process(delta):
if is_network_master():
rset("puppet_anim_sprite_name", animated_sprite.animation)
rset("puppet_anim_sprite_frame", animated_sprite.frame)
else:
animated_sprite.animation = puppet_anim_sprite_name
animated_sprite.frame = puppet_anim_sprite_frame
func _unhandled_input(event: InputEvent) -> void: func _unhandled_input(event: InputEvent) -> void:
if actor_type == "Player": if is_network_master():
movement_component.process_input(event) if actor_type == "Player":
movement_component.process_input(event)
#movement_state_machine.process_input(event) #movement_state_machine.process_input(event)
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
# Input based or polling input is not done in _unhandled_input # Input based or polling input is not done in _unhandled_input
# gives us the ability to turn off polling this way # gives us the ability to turn off polling this way
if actor_type == "Player": if is_network_master():
movement_component.process_physics_input(delta) if actor_type == "Player":
movement_component.process_physics(delta) movement_component.process_physics_input(delta)
movement_component.process_physics(delta)
rset("puppet_pos", position)
rset("puppet_transform", transform)
else:
position = puppet_pos
transform = puppet_transform
#movement_state_machine.process_physics(delta) #movement_state_machine.process_physics(delta)
# #
#func _process(delta: float) -> void: #func _process(delta: float) -> void:

View File

@ -28,9 +28,6 @@ const state_damage_amount :Dictionary = {
var player_info_index :int var player_info_index :int
var player_data :PlayerData var player_data :PlayerData
## Multiplayer Variables
puppet var puppet_pos = Vector2()
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -61,38 +58,33 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if is_network_master(): #PlayerInfo.player_position = global_position.round()
#PlayerInfo.player_position = global_position.round() player_data.player_position = global_position.round()
player_data.player_position = global_position.round() # stamina_recovery += delta
# stamina_recovery += delta # if stamina_recovery > 1.0:
# if stamina_recovery > 1.0: # stamina_component.recover(1)
# stamina_component.recover(1) # stamina_recovery = 0.0
# stamina_recovery = 0.0 # #print("recover ", stamina_component.stamina)
# #print("recover ", stamina_component.stamina)
#PlayerInfo.player_stamina = stamina_component.stamina #PlayerInfo.player_stamina = stamina_component.stamina
player_data.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 ##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): if state_damage_amount.has(movement_state_machine.current_state.name):
$Hitbox_Component.damage_amount = state_damage_amount[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)
rset("puppet_pos", position)
else: else:
position = puppet_pos $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)