made the first changes towards multiplayer working
This commit is contained in:
@ -59,8 +59,15 @@ func shoot():
|
||||
var target_hitbox = target.shape_owner_get_owner($RayCast3D.get_collider_shape())
|
||||
if target_hitbox is Hitbox:
|
||||
target_hitbox.damage(stats.damage)
|
||||
networked_hit.rpc(get_tree().root.get_path_to(target_hitbox))
|
||||
|
||||
|
||||
@rpc
|
||||
func networked_shoot():
|
||||
$AnimationPlayer.play("shoot")
|
||||
|
||||
|
||||
|
||||
@rpc("reliable")
|
||||
func networked_hit(target_node_path : String):
|
||||
var target_node = get_tree().root.get_node(target_node_path)
|
||||
target_node.damage(stats.damage)
|
||||
|
@ -9,7 +9,7 @@ func _ready() -> void:
|
||||
cooldown = 1.0 / stats.fire_rate
|
||||
|
||||
|
||||
func set_raycast_origin(node):
|
||||
func set_raycast_origin(_node):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ func _ready() -> void:
|
||||
cooldown = 1.0 / stats.fire_rate
|
||||
|
||||
|
||||
func set_raycast_origin(node):
|
||||
func set_raycast_origin(_node):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ func _ready() -> void:
|
||||
cooldown = 1.0 / stats.fire_rate
|
||||
|
||||
|
||||
func set_raycast_origin(node):
|
||||
func set_raycast_origin(_node):
|
||||
pass
|
||||
|
||||
|
||||
|
40
PCs/hero.gd
40
PCs/hero.gd
@ -7,6 +7,7 @@ signal died
|
||||
|
||||
@export var hero_class: HeroClass
|
||||
@export var camera : Camera3D
|
||||
@export var gun_camera : Camera3D
|
||||
@export var left_hand : Node3D
|
||||
@export var right_hand : Node3D
|
||||
@export var right_hand_animator : AnimationPlayer
|
||||
@ -21,23 +22,22 @@ signal died
|
||||
@export var weapon_scene : PackedScene
|
||||
@export var hud : HUD
|
||||
@export var movement : PlayerMovement
|
||||
@export var sprint_zoom_speed := 0.2
|
||||
|
||||
var equipped_card : Card
|
||||
var paused := false
|
||||
var editing_mode := true
|
||||
var profile: PlayerProfile
|
||||
var ready_state := false :
|
||||
var ready_state := false :
|
||||
set(value):
|
||||
ready_state = value
|
||||
networked_set_ready_state.rpc(ready_state)
|
||||
ready_state_changed.emit(ready_state)
|
||||
ready_state_changed.emit(value)
|
||||
var currency := 0 :
|
||||
set(value):
|
||||
currency = value
|
||||
hud.set_currency_count(value)
|
||||
get:
|
||||
return currency
|
||||
@export var sprint_zoom_speed := 0.2
|
||||
|
||||
|
||||
func set_zoom_factor(value):
|
||||
@ -48,11 +48,12 @@ func _ready() -> void:
|
||||
if is_multiplayer_authority():
|
||||
right_hand_animator.play("weapon_sway")
|
||||
right_hand_animator.speed_scale = 0
|
||||
hud.set_visible(true)
|
||||
camera.make_current()
|
||||
sprite.queue_free()
|
||||
else:
|
||||
camera.set_visible(false)
|
||||
gun_camera.set_visible(false)
|
||||
hud.set_visible(false)
|
||||
if weapon != null:
|
||||
weapon.set_raycast_origin(camera)
|
||||
inventory.contents.append_array(hero_class.deck)
|
||||
@ -61,7 +62,7 @@ func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if !is_multiplayer_authority() or paused:
|
||||
return
|
||||
if movement.input_vector == Vector2.ZERO:
|
||||
@ -147,7 +148,9 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
return
|
||||
if editing_mode and event.is_action_pressed("Ready"):
|
||||
edit_tool.interact_key_held = false
|
||||
ready_state = true
|
||||
if !ready_state:
|
||||
ready_state = true
|
||||
networked_set_ready_state.rpc(ready_state)
|
||||
if event.is_action_pressed("Pause"):
|
||||
var menu = pause_menu_scene.instantiate() as PauseMenu
|
||||
pause()
|
||||
@ -203,8 +206,11 @@ func equip_weapon():
|
||||
unequip_weapon()
|
||||
return
|
||||
if inventory.contents.size() > 0:
|
||||
networked_equip_weapon.rpc()
|
||||
equipped_card = inventory.remove()
|
||||
weapon = equipped_card.weapon.instantiate()
|
||||
weapon.name = "weapon"
|
||||
weapon.set_multiplayer_authority(multiplayer.get_unique_id())
|
||||
right_hand.add_child(weapon)
|
||||
gauntlet_sprite.set_visible(false)
|
||||
weapon.set_raycast_origin(camera)
|
||||
@ -213,6 +219,7 @@ func equip_weapon():
|
||||
|
||||
|
||||
func unequip_weapon():
|
||||
networked_unequip_weapon.rpc()
|
||||
gauntlet_sprite.set_visible(true)
|
||||
weapon.queue_free()
|
||||
inventory.add(equipped_card)
|
||||
@ -224,4 +231,21 @@ func unequip_weapon():
|
||||
@rpc("reliable")
|
||||
func networked_set_ready_state(state: bool):
|
||||
ready_state = state
|
||||
ready_state_changed.emit(state)
|
||||
|
||||
|
||||
@rpc("reliable")
|
||||
func networked_equip_weapon():
|
||||
equipped_card = inventory.remove()
|
||||
weapon = equipped_card.weapon.instantiate()
|
||||
weapon.set_multiplayer_authority(multiplayer.get_remote_sender_id())
|
||||
weapon.name = "weapon"
|
||||
right_hand.add_child(weapon)
|
||||
weapon.set_raycast_origin(camera)
|
||||
weapon.set_hero(self)
|
||||
|
||||
|
||||
@rpc("reliable")
|
||||
func networked_unequip_weapon():
|
||||
weapon.queue_free()
|
||||
inventory.add(equipped_card)
|
||||
equipped_card = null
|
||||
|
219
PCs/hero.tscn
219
PCs/hero.tscn
@ -55,12 +55,13 @@ viewport_path = NodePath("SubViewport")
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_574jy"]
|
||||
viewport_path = NodePath("MiniMapViewport")
|
||||
|
||||
[node name="Character" type="CharacterBody3D" node_paths=PackedStringArray("camera", "left_hand", "right_hand", "right_hand_animator", "edit_tool", "gauntlet_sprite", "sprite", "interaction_raycast", "inventory", "card", "hud", "movement")]
|
||||
[node name="Character" type="CharacterBody3D" node_paths=PackedStringArray("camera", "gun_camera", "left_hand", "right_hand", "right_hand_animator", "edit_tool", "gauntlet_sprite", "sprite", "interaction_raycast", "inventory", "card", "hud", "movement")]
|
||||
collision_layer = 2
|
||||
collision_mask = 37
|
||||
script = ExtResource("1_pihpe")
|
||||
hero_class = ExtResource("2_dbyo0")
|
||||
camera = NodePath("Head")
|
||||
gun_camera = NodePath("SubViewport/Head2")
|
||||
left_hand = NodePath("SubViewport/Head2/LeftHand")
|
||||
right_hand = NodePath("SubViewport/Head2/RightHand")
|
||||
right_hand_animator = NodePath("SubViewport/Head2/RightHand/AnimationPlayer")
|
||||
@ -169,6 +170,114 @@ hover_text = NodePath("Label2")
|
||||
enemy_sprites = [NodePath("TextureRect4/TextureRect"), NodePath("TextureRect4/TextureRect2"), NodePath("TextureRect4/TextureRect3"), NodePath("TextureRect4/TextureRect4"), NodePath("TextureRect4/TextureRect5")]
|
||||
enemy_counts = [NodePath("TextureRect4/TextureRect/Label"), NodePath("TextureRect4/TextureRect2/Label2"), NodePath("TextureRect4/TextureRect3/Label3"), NodePath("TextureRect4/TextureRect4/Label4"), NodePath("TextureRect4/TextureRect5/Label5")]
|
||||
|
||||
[node name="WaveCount" type="Label" parent="HUD"]
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
offset_left = -30.0
|
||||
offset_top = 83.0
|
||||
offset_right = 30.0
|
||||
offset_bottom = 26.0
|
||||
grow_horizontal = 2
|
||||
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||
text = "1"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="EnemyCount" type="Label" parent="HUD"]
|
||||
visible = false
|
||||
offset_left = 10.0
|
||||
offset_top = 80.0
|
||||
offset_right = 123.0
|
||||
offset_bottom = 106.0
|
||||
text = "Enemies left: 0"
|
||||
|
||||
[node name="Crosshair" type="TextureRect" parent="HUD"]
|
||||
texture_filter = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -20.0
|
||||
offset_right = 20.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
texture = ExtResource("8_fq3f6")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="HUD"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
texture = SubResource("ViewportTexture_mk87g")
|
||||
|
||||
[node name="TextureRect2" type="TextureRect" parent="HUD"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -256.0
|
||||
offset_top = 40.0
|
||||
offset_right = -40.0
|
||||
offset_bottom = 256.0
|
||||
grow_horizontal = 0
|
||||
mouse_filter = 2
|
||||
texture = SubResource("ViewportTexture_574jy")
|
||||
|
||||
[node name="Label" type="Label" parent="HUD"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -40.0
|
||||
offset_bottom = 26.0
|
||||
grow_horizontal = 0
|
||||
text = "FPS: "
|
||||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="LivesBar" parent="HUD" instance=ExtResource("15_cqpib")]
|
||||
anchors_preset = 0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_left = 10.0
|
||||
offset_top = 10.0
|
||||
offset_right = 214.0
|
||||
offset_bottom = 32.0
|
||||
grow_horizontal = 1
|
||||
grow_vertical = 1
|
||||
scale = Vector2(3, 3)
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="LivesCount" type="Label" parent="HUD"]
|
||||
offset_left = -5.0
|
||||
offset_top = 15.0
|
||||
offset_right = 100.0
|
||||
offset_bottom = 72.0
|
||||
theme_override_colors/font_color = Color(0.65098, 0.227451, 0.243137, 1)
|
||||
theme_override_font_sizes/font_size = 37
|
||||
text = "120
|
||||
"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TextureRect3" type="TextureRect" parent="HUD"]
|
||||
texture_filter = 1
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -262.0
|
||||
offset_top = 37.0
|
||||
offset_right = -37.0
|
||||
offset_bottom = 336.0
|
||||
grow_horizontal = 0
|
||||
mouse_filter = 2
|
||||
texture = ExtResource("16_x1xjr")
|
||||
|
||||
[node name="TextureRect4" type="TextureRect" parent="HUD"]
|
||||
texture_filter = 1
|
||||
anchors_preset = 5
|
||||
@ -291,114 +400,6 @@ text = "999"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="WaveCount" type="Label" parent="HUD"]
|
||||
anchors_preset = 5
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
offset_left = -30.0
|
||||
offset_top = 83.0
|
||||
offset_right = 30.0
|
||||
offset_bottom = 26.0
|
||||
grow_horizontal = 2
|
||||
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||
text = "1"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="EnemyCount" type="Label" parent="HUD"]
|
||||
visible = false
|
||||
offset_left = 10.0
|
||||
offset_top = 80.0
|
||||
offset_right = 123.0
|
||||
offset_bottom = 106.0
|
||||
text = "Enemies left: 0"
|
||||
|
||||
[node name="Crosshair" type="TextureRect" parent="HUD"]
|
||||
texture_filter = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -20.0
|
||||
offset_top = -20.0
|
||||
offset_right = 20.0
|
||||
offset_bottom = 20.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
texture = ExtResource("8_fq3f6")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="HUD"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
texture = SubResource("ViewportTexture_mk87g")
|
||||
|
||||
[node name="TextureRect2" type="TextureRect" parent="HUD"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -256.0
|
||||
offset_top = 40.0
|
||||
offset_right = -40.0
|
||||
offset_bottom = 256.0
|
||||
grow_horizontal = 0
|
||||
mouse_filter = 2
|
||||
texture = SubResource("ViewportTexture_574jy")
|
||||
|
||||
[node name="Label" type="Label" parent="HUD"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -40.0
|
||||
offset_bottom = 26.0
|
||||
grow_horizontal = 0
|
||||
text = "FPS: "
|
||||
horizontal_alignment = 2
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="LivesBar" parent="HUD" instance=ExtResource("15_cqpib")]
|
||||
anchors_preset = 0
|
||||
anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
offset_left = 10.0
|
||||
offset_top = 10.0
|
||||
offset_right = 214.0
|
||||
offset_bottom = 32.0
|
||||
grow_horizontal = 1
|
||||
grow_vertical = 1
|
||||
scale = Vector2(3, 3)
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="LivesCount" type="Label" parent="HUD"]
|
||||
offset_left = -5.0
|
||||
offset_top = 15.0
|
||||
offset_right = 100.0
|
||||
offset_bottom = 72.0
|
||||
theme_override_colors/font_color = Color(0.65098, 0.227451, 0.243137, 1)
|
||||
theme_override_font_sizes/font_size = 37
|
||||
text = "120
|
||||
"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="TextureRect3" type="TextureRect" parent="HUD"]
|
||||
texture_filter = 1
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -262.0
|
||||
offset_top = 37.0
|
||||
offset_right = -37.0
|
||||
offset_bottom = 336.0
|
||||
grow_horizontal = 0
|
||||
mouse_filter = 2
|
||||
texture = ExtResource("16_x1xjr")
|
||||
|
||||
[node name="Currency" type="Label" parent="HUD"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
|
@ -14,13 +14,15 @@ var sprint_zoom_factor := 0.08
|
||||
var sprinting := false
|
||||
var head_angle := 0.0
|
||||
var look_sens : float :
|
||||
set(value):
|
||||
set(_value):
|
||||
return
|
||||
get:
|
||||
return Data.preferences.mouse_sens / 40000.0
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if !is_multiplayer_authority():
|
||||
return
|
||||
var accel = acceleration
|
||||
if sprinting:
|
||||
accel = acceleration + sprint_boost
|
||||
@ -35,7 +37,9 @@ func _physics_process(delta: float) -> void:
|
||||
sync_rotation.rpc(player.rotation)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
if !is_multiplayer_authority():
|
||||
return
|
||||
can_sprint = true
|
||||
input_vector = Input.get_vector("Move Left", "Move Right", "Move Forward", "Move Backward")
|
||||
if input_vector.y >= 0:
|
||||
@ -52,6 +56,8 @@ func _process(delta: float) -> void:
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if !is_multiplayer_authority():
|
||||
return
|
||||
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
player.rotation.y -= event.relative.x * (look_sens / zoom_factor) * (-1 if Data.preferences.invert_lookX else 1)
|
||||
head_angle -= event.relative.y * (look_sens / zoom_factor) * (-1 if Data.preferences.invert_lookY else 1)
|
||||
|
Reference in New Issue
Block a user