Add multiplayer damage system and ragdolls
This commit is contained in:
@ -35,6 +35,14 @@ offset_right = 224.0
|
||||
offset_bottom = 220.0
|
||||
text = "Join"
|
||||
|
||||
[node name="TextEdit" type="TextEdit" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 238.0
|
||||
offset_top = 151.0
|
||||
offset_right = 497.0
|
||||
offset_bottom = 220.0
|
||||
text = "192.168.0.28"
|
||||
|
||||
[connection signal="player_connected" from="." to="." method="_on_player_connected"]
|
||||
[connection signal="player_disconnected" from="." to="." method="_on_player_disconnected"]
|
||||
[connection signal="server_disconnected" from="." to="." method="_on_server_disconnected"]
|
||||
|
11
scenes/utils/in_game_hud.gd
Normal file
11
scenes/utils/in_game_hud.gd
Normal file
@ -0,0 +1,11 @@
|
||||
extends Control
|
||||
|
||||
@onready =
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
55
scenes/utils/in_game_hud.tscn
Normal file
55
scenes/utils/in_game_hud.tscn
Normal file
@ -0,0 +1,55 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://c137wl6ls3knx"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/utils/in_game_hud.gd" id="1_sttf0"]
|
||||
[ext_resource type="Texture2D" uid="uid://oopj5mj1vdp0" path="res://assets/crosshairs/crosshair_default.png" id="2_fjr6q"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_ds4qb"]
|
||||
font_size = 70
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_vhjwu"]
|
||||
font_size = 100
|
||||
font_color = Color(0.756874, 0, 0.223924, 1)
|
||||
|
||||
[node name="InGameHud" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_sttf0")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -28.0
|
||||
offset_top = -36.0
|
||||
offset_right = 44.0
|
||||
offset_bottom = 36.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("2_fjr6q")
|
||||
|
||||
[node name="HealthIndicator" type="Label" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 8.0
|
||||
offset_top = -96.0
|
||||
offset_right = 128.0
|
||||
grow_vertical = 0
|
||||
text = "100"
|
||||
label_settings = SubResource("LabelSettings_ds4qb")
|
||||
|
||||
[node name="FPS" type="Label" parent="." groups=["player_placeholder"]]
|
||||
layout_mode = 1
|
||||
offset_left = 8.0
|
||||
offset_right = 65.0
|
||||
offset_bottom = 137.0
|
||||
text = "0"
|
||||
label_settings = SubResource("LabelSettings_vhjwu")
|
@ -10,7 +10,7 @@ signal server_disconnected
|
||||
const PORT = 7000
|
||||
const DEFAULT_SERVER_IP = "127.0.0.1" # IPv4 localhost
|
||||
const MAX_CONNECTIONS = 20
|
||||
|
||||
@onready var address_input: TextEdit = $TextEdit
|
||||
var players = {}
|
||||
var my_random_number = RandomNumberGenerator.new().randf_range(-2.0, 2.0)
|
||||
var player_info = {"name": str(my_random_number)}
|
||||
@ -25,8 +25,7 @@ func _ready() -> void:
|
||||
multiplayer.server_disconnected.connect(_on_server_disconnected)
|
||||
|
||||
func join_game(address = ""):
|
||||
if address.is_empty():
|
||||
address = DEFAULT_SERVER_IP
|
||||
address = address_input.text
|
||||
var peer = ENetMultiplayerPeer.new()
|
||||
var error = peer.create_client(address, PORT)
|
||||
if error:
|
||||
@ -66,7 +65,7 @@ func player_loaded():
|
||||
# When a peer connects, send them my player info.
|
||||
# This allows transfer of all desired data for each player, not only the unique ID.
|
||||
func _on_player_connected(id):
|
||||
player_info = {"name": multiplayer.get_unique_id()}
|
||||
player_info = {"name": multiplayer.get_unique_id(), "health": 100}
|
||||
_register_player.rpc_id(1, multiplayer.get_unique_id(), player_info)
|
||||
|
||||
@rpc("any_peer", "reliable")
|
||||
@ -104,7 +103,7 @@ func _on_server_disconnected():
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
|
||||
func _on_host_pressed() -> void:
|
||||
player_info = {"name": str(1)}
|
||||
player_info = {"name": str(1), "health": 100}
|
||||
_register_player(1, player_info)
|
||||
create_game()
|
||||
|
||||
|
Reference in New Issue
Block a user