Progress towards issue #27

This commit is contained in:
Paul Black 2023-03-16 13:37:17 -06:00
parent 1cf3feb147
commit 3361aca4b1
8 changed files with 168 additions and 31 deletions

View file

@ -22,6 +22,7 @@ var ranRemovePlayer = false
var mousesense = Global.mouseSensitivity var mousesense = Global.mouseSensitivity
var controllerAxisValue_x = 0 var controllerAxisValue_x = 0
var controllerAxisValue_y = 0 var controllerAxisValue_y = 0
var runnerDead = false
func _ready(): func _ready():
name = str(teddyAuthority) name = str(teddyAuthority)
@ -79,11 +80,9 @@ func _unhandled_input(event):
func _physics_process(delta): func _physics_process(delta):
if is_multiplayer_authority(): if is_multiplayer_authority():
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# This variable gets set my the death scene, so we know the player needs to be respawned # This variable gets set my the death scene, so we know the player needs to be respawned
if Global.playerPleaseRespawn == true: if Global.playerPleaseRespawn == true:
get_node(teddyCollider).disabled = false
position.x = 0 #Set player X position.x = 0 #Set player X
position.y = 10 #Set player Y position.y = 10 #Set player Y
position.z = 0 #Set player Z position.z = 0 #Set player Z
@ -101,10 +100,13 @@ func _physics_process(delta):
if ranRemovePlayer == false: if ranRemovePlayer == false:
if Global.playerAlive == false: if Global.playerAlive == false:
ranRemovePlayer = true ranRemovePlayer = true
#get_node(teddyCollider).disabled = true get_node(teddyCollider).disabled = true
rpc("remove_dead_teddy") rpc("remove_dead_teddy")
if Global.playerAlive: if Global.playerAlive:
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Handle Jump. # Handle Jump.
if Input.is_action_just_pressed("jump") and is_on_floor(): if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY velocity.y = JUMP_VELOCITY
@ -150,7 +152,7 @@ func _physics_process(delta):
if Global.playerDead: if Global.playerDead:
velocity.x = 0 velocity.x = 0
velocity.z = 0 velocity.z = 0
if Input.is_action_just_pressed("shoot"): if Input.is_action_just_pressed("shoot") and Global.roundInSession:
if menuOpen == false: if menuOpen == false:
if Global.multiplayerCurrent == true: if Global.multiplayerCurrent == true:
rpc("shoot_bullet") rpc("shoot_bullet")

View file

@ -22,6 +22,7 @@ offset_top = 562.0
offset_right = 165.0 offset_right = 165.0
offset_bottom = 589.0 offset_bottom = 589.0
value = 100.0 value = 100.0
allow_greater = true
[node name="Fatigue" type="ProgressBar" parent="."] [node name="Fatigue" type="ProgressBar" parent="."]
modulate = Color(1, 1, 0, 1) modulate = Color(1, 1, 0, 1)
@ -143,7 +144,7 @@ offset_bottom = 107.0
grow_horizontal = 2 grow_horizontal = 2
theme_override_fonts/font = ExtResource("3_x1wqt") theme_override_fonts/font = ExtResource("3_x1wqt")
theme_override_font_sizes/font_size = 60 theme_override_font_sizes/font_size = 60
text = "10:00" text = "00:00"
[node name="startLabel" type="Label" parent="."] [node name="startLabel" type="Label" parent="."]
layout_mode = 0 layout_mode = 0
@ -178,3 +179,29 @@ offset_top = 58.0
offset_right = 252.0 offset_right = 252.0
offset_bottom = 81.0 offset_bottom = 81.0
horizontal_alignment = 1 horizontal_alignment = 1
[node name="RunnerPanel" type="Panel" parent="."]
visible = false
layout_mode = 0
offset_left = 916.0
offset_top = 15.0
offset_right = 1131.0
offset_bottom = 82.0
[node name="Health" type="ProgressBar" parent="RunnerPanel"]
modulate = Color(0.890196, 0.137255, 0.0156863, 1)
offset_left = 5.0
offset_top = 35.0
offset_right = 210.0
offset_bottom = 62.0
max_value = 2000.0
value = 2000.0
allow_greater = true
[node name="runnerLabel" type="Label" parent="RunnerPanel"]
layout_mode = 0
offset_left = 48.0
offset_top = 6.0
offset_right = 161.0
offset_bottom = 32.0
text = "Runner Health"

View file

@ -32,33 +32,33 @@ flat = true
[node name="Panel2" type="Panel" parent="."] [node name="Panel2" type="Panel" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 308.0 offset_left = 308.0
offset_top = 229.0 offset_top = 187.0
offset_right = 508.0 offset_right = 508.0
offset_bottom = 429.0 offset_bottom = 387.0
theme_override_styles/panel = SubResource("StyleBoxFlat_xhmtq") theme_override_styles/panel = SubResource("StyleBoxFlat_xhmtq")
[node name="Label" type="Label" parent="."] [node name="Label" type="Label" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 348.0 offset_left = 348.0
offset_top = 309.0 offset_top = 267.0
offset_right = 464.0 offset_right = 464.0
offset_bottom = 335.0 offset_bottom = 293.0
text = "IMAGE OF MAP" text = "IMAGE OF MAP"
[node name="mapLabel" type="Label" parent="."] [node name="mapLabel" type="Label" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 658.0 offset_left = 658.0
offset_top = 218.0 offset_top = 176.0
offset_right = 782.0 offset_right = 782.0
offset_bottom = 244.0 offset_bottom = 202.0
text = "MAP SELECTION" text = "MAP SELECTION"
[node name="playground" type="Button" parent="."] [node name="playground" type="Button" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 646.0 offset_left = 646.0
offset_top = 248.0 offset_top = 206.0
offset_right = 797.0 offset_right = 797.0
offset_bottom = 283.0 offset_bottom = 241.0
text = "Toyland" text = "Toyland"
[node name="portBox" type="LineEdit" parent="."] [node name="portBox" type="LineEdit" parent="."]
@ -79,18 +79,18 @@ text = "START"
[node name="lowerMapLabel" type="Label" parent="."] [node name="lowerMapLabel" type="Label" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 262.0 offset_left = 265.0
offset_top = 454.0 offset_top = 395.0
offset_right = 305.0 offset_right = 308.0
offset_bottom = 480.0 offset_bottom = 421.0
text = "Map: " text = "Map: "
[node name="mapSelected" type="Label" parent="."] [node name="mapSelected" type="Label" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 309.0 offset_left = 309.0
offset_top = 456.0 offset_top = 396.0
offset_right = 349.0 offset_right = 349.0
offset_bottom = 479.0 offset_bottom = 419.0
[node name="playerBox" type="LineEdit" parent="."] [node name="playerBox" type="LineEdit" parent="."]
layout_mode = 0 layout_mode = 0
@ -127,9 +127,9 @@ flat = true
[node name="hostLabel" type="Label" parent="."] [node name="hostLabel" type="Label" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 534.0 offset_left = 534.0
offset_top = 161.0 offset_top = 148.0
offset_right = 620.0 offset_right = 620.0
offset_bottom = 187.0 offset_bottom = 174.0
text = "Host Game" text = "Host Game"
[node name="playerNameBox" type="LineEdit" parent="."] [node name="playerNameBox" type="LineEdit" parent="."]
@ -174,12 +174,11 @@ text = "Long"
[node name="respawnLabel" type="Label" parent="."] [node name="respawnLabel" type="Label" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 681.0 offset_left = 664.0
offset_top = 387.0 offset_top = 413.0
offset_right = 751.0 offset_right = 776.0
offset_bottom = 439.0 offset_bottom = 439.0
text = "Respawn text = "Respawn Time"
Time"
horizontal_alignment = 1 horizontal_alignment = 1
[node name="Toyland" type="Sprite2D" parent="."] [node name="Toyland" type="Sprite2D" parent="."]
@ -188,6 +187,32 @@ position = Vector2(407.556, 329)
scale = Vector2(0.653595, 0.653595) scale = Vector2(0.653595, 0.653595)
texture = ExtResource("3_rgmyq") texture = ExtResource("3_rgmyq")
[node name="Label2" type="Label" parent="."]
layout_mode = 0
offset_left = 351.0
offset_top = 435.0
offset_right = 450.0
offset_bottom = 461.0
text = "Gamemode"
[node name="GamemodeDeathmatch" type="CheckBox" parent="."]
layout_mode = 0
offset_left = 279.0
offset_top = 461.0
offset_right = 403.0
offset_bottom = 492.0
tooltip_text = "5 minute Deathmatch. Player with most kills wins."
button_pressed = true
text = "Deathmatch"
[node name="GamemodeRunner" type="CheckBox" parent="."]
offset_left = 407.0
offset_top = 461.0
offset_right = 492.0
offset_bottom = 492.0
tooltip_text = "One player is selected at random as \"the runner.\" Everyone else it supposed to kill the runner. 5 minutes."
text = "Runner"
[connection signal="pressed" from="close" to="." method="_on_close_pressed"] [connection signal="pressed" from="close" to="." method="_on_close_pressed"]
[connection signal="pressed" from="playground" to="." method="_on_playground_pressed"] [connection signal="pressed" from="playground" to="." method="_on_playground_pressed"]
[connection signal="pressed" from="startButton" to="." method="_on_start_button_pressed"] [connection signal="pressed" from="startButton" to="." method="_on_start_button_pressed"]
@ -196,3 +221,5 @@ texture = ExtResource("3_rgmyq")
[connection signal="button_down" from="shortRespawn" to="." method="_on_short_respawn_button_down"] [connection signal="button_down" from="shortRespawn" to="." method="_on_short_respawn_button_down"]
[connection signal="button_down" from="normalRespawn" to="." method="_on_normal_respawn_button_down"] [connection signal="button_down" from="normalRespawn" to="." method="_on_normal_respawn_button_down"]
[connection signal="button_down" from="longRespawn" to="." method="_on_long_respawn_button_down"] [connection signal="button_down" from="longRespawn" to="." method="_on_long_respawn_button_down"]
[connection signal="button_down" from="GamemodeDeathmatch" to="." method="_on_gamemode_deathmatch_button_down"]
[connection signal="button_down" from="GamemodeRunner" to="." method="_on_gamemode_runner_button_down"]

View file

@ -1,11 +1,12 @@
extends Control extends Control
var roundTimer := 600.0 var roundTimer := 300.0
var minutes var minutes
var seconds var seconds
var scores: Array[int] = [] var scores: Array[int] = []
var scoresInitalized = false var scoresInitalized = false
var runnerSelected = false
func _ready(): func _ready():
minutes = roundTimer / 60 minutes = roundTimer / 60
@ -17,6 +18,8 @@ func _process(delta):
$startLabel.text = Global.HUDStartLabelText $startLabel.text = Global.HUDStartLabelText
$Fatigue.value = Global.fatigue $Fatigue.value = Global.fatigue
$Health.value = Global.playerHealth $Health.value = Global.playerHealth
if Global.iAmRunner:
rpc("sync_runner_hp", $Health.value)
if Global.musicUpdated == true: if Global.musicUpdated == true:
Global.musicUpdated = false Global.musicUpdated = false
$musicPanel/playingLabel.text = Global.musicName $musicPanel/playingLabel.text = Global.musicName
@ -26,9 +29,17 @@ func _process(delta):
$musicPanel.visible = false $musicPanel.visible = false
if Global.roundInSession == true and roundTimer >= 0: if Global.roundInSession == true and roundTimer >= 0:
if scoresInitalized == false: if scoresInitalized == false:
#Global.HUDStartLabelText = ""
scoresInitalized = true scoresInitalized = true
fill_scores_with_zeros(Global.connectedPlayers.size()) fill_scores_with_zeros(Global.connectedPlayers.size())
$startLabel.text = "" if Global.gamemode == "Runner":
if runnerSelected == false:
runnerSelected = true
select_runner(Global.connectedPlayers, Global.connectedPlayersByPeerID)
if Global.runnerDead == true:
print("RUNNER IS DEAD")
rpc("runner_dead", Global.chosenRunner)
runner_dead(Global.chosenRunner)
roundTimer -= delta roundTimer -= delta
minutes = roundTimer / 60 minutes = roundTimer / 60
seconds = fmod(roundTimer, 60) seconds = fmod(roundTimer, 60)
@ -62,3 +73,48 @@ func fill_scores_with_zeros(num_of_players):
scores.resize(num_of_players) scores.resize(num_of_players)
for i in num_of_players: for i in num_of_players:
scores[i] = 0 scores[i] = 0
func select_runner(players, playersID):
var numOfPlayers = players.size()
var getIndexSize = numOfPlayers - 1
var playerChosen = RandomNumberGenerator.new().randi_range(0, getIndexSize)
var runner = players[playerChosen]
Global.chosenRunner = runner
rpc("not_runner", Global.chosenRunner)
rpc("selected_runner", runner)
selected_runner(runner)
var index = players.find(runner)
var runnerID = playersID[index]
if runnerID == 1:
runner_stats()
else:
rpc_id(runnerID, "runner_stats")
print("Runner: ", runner, ", ID: ", runnerID)
@rpc("any_peer", "reliable")
func selected_runner(player):
Global.chosenRunner = player
@rpc("any_peer", "reliable")
func not_runner(player):
$RunnerPanel.visible = true
Global.HUDStartLabelText = str(player + " is the runner!")
@rpc("any_peer", "reliable")
func runner_stats():
await get_tree().create_timer(0.1).timeout
Global.iAmRunner = true
$Health.max_value = 2000
Global.playerHealth = 2000
Global.HUDStartLabelText = "You are the runner!"
$RunnerPanel.visible = false
print(Global.HUDStartLabelText)
@rpc("any_peer", "reliable")
func runner_dead(runner):
Global.roundInSession = false
Global.HUDStartLabelText = "Runner has died! Killers win!"
@rpc("any_peer", "reliable")
func sync_runner_hp(value):
$RunnerPanel/Health.value = value

View file

@ -10,6 +10,9 @@ func _ready():
func _process(delta): func _process(delta):
if Global.gamemode == "Runner":
if Global.iAmRunner:
Global.runnerDead = true
if deathTimer < 100: if deathTimer < 100:
deathTimer = deathTimer + (10 * Global.respawnTimeModifier) * delta deathTimer = deathTimer + (10 * Global.respawnTimeModifier) * delta
if deathTimer > 100: if deathTimer > 100:
@ -17,3 +20,4 @@ func _process(delta):
Global.playerPleaseRespawn = true # Used so the Teddy script will know to reset variables and position of the player Global.playerPleaseRespawn = true # Used so the Teddy script will know to reset variables and position of the player
self.queue_free() self.queue_free()
$deathBar.value = deathTimer $deathBar.value = deathTimer

View file

@ -24,16 +24,21 @@ var HUDStartLabelText = "" # The text displayed at the bottom of the screen of t
var lastPersonToHitMe = 0 # Defined in the Bullet RPC var lastPersonToHitMe = 0 # Defined in the Bullet RPC
var HUDPlayerDied = false # Tells the HUD.gd script that a point should be added or deducted var HUDPlayerDied = false # Tells the HUD.gd script that a point should be added or deducted
var connectedPlayers = [] # Currently connected players by their name (NOT THEIR ID) var connectedPlayers = [] # Currently connected players by their name (NOT THEIR ID)
var connectedPlayersByPeerID = [] # Currently connected players by their ID
var respawnTimeModifier = 1.0 # Affects how quickly the player respawns in death.gd var respawnTimeModifier = 1.0 # Affects how quickly the player respawns in death.gd
var musicName = "" # Name of music for HUD.gd var musicName = "" # Name of music for HUD.gd
var musicAuthor = "" # Name of music author for HUD.gd var musicAuthor = "" # Name of music author for HUD.gd
var musicUpdated = false # Tells HUD.gd to update labels and change visibility var musicUpdated = false # Tells HUD.gd to update labels and change visibility
var menuLightSwitch = false # No description provided var menuLightSwitch = false # No description provided
var gamemode = "Deathmatch" # This is changed in host.gd
var chosenRunner # Changed in HUD.gd
var iAmRunner = false # Defines whether you're the runner or not. Used in HUD.gd
var runnerDead = false
func _process(delta): func _process(delta):
if godMode: if godMode:
pass pass
elif Input.is_action_pressed("sprint"): elif Input.is_action_pressed("sprint") and not iAmRunner and roundInSession:
if fatigue > 0: if fatigue > 0:
fatigue = fatigue - 10 * delta fatigue = fatigue - 10 * delta
elif not Input.is_action_pressed("sprint"): elif not Input.is_action_pressed("sprint"):

View file

@ -86,3 +86,13 @@ func _on_normal_respawn_button_down():
func _on_long_respawn_button_down(): func _on_long_respawn_button_down():
$shortRespawn.button_pressed = false $shortRespawn.button_pressed = false
$normalRespawn.button_pressed = false $normalRespawn.button_pressed = false
func _on_gamemode_deathmatch_button_down():
$GamemodeRunner.button_pressed = false
Global.gamemode = "Deathmatch"
func _on_gamemode_runner_button_down():
$GamemodeDeathmatch.button_pressed = false
Global.gamemode = "Runner"

View file

@ -23,6 +23,7 @@ func create_server(port, maxPlayers):
await get_tree().create_timer(0.5).timeout ## REQUIRED, THE RPC IS MADE BEFORE THE CLIENT IS FULLY CONNECTED await get_tree().create_timer(0.5).timeout ## REQUIRED, THE RPC IS MADE BEFORE THE CLIENT IS FULLY CONNECTED
rpc_id(new_peer_id, "sync_names", Global.connectedPlayers) rpc_id(new_peer_id, "sync_names", Global.connectedPlayers)
rpc_id(new_peer_id, "sync_respawn_speed", Global.respawnTimeModifier) rpc_id(new_peer_id, "sync_respawn_speed", Global.respawnTimeModifier)
rpc_id(new_peer_id, "sync_gamemode", Global.gamemode)
rpc("add_newly_connected_player_character", new_peer_id) rpc("add_newly_connected_player_character", new_peer_id)
rpc_id(new_peer_id, "add_previously_connected_player_characters", connected_peers) rpc_id(new_peer_id, "add_previously_connected_player_characters", connected_peers)
add_player_node(new_peer_id) add_player_node(new_peer_id)
@ -44,6 +45,7 @@ func add_newly_connected_player_character(new_peer_id):
func add_player_node(peer_id): func add_player_node(peer_id):
connected_peers.append(peer_id) connected_peers.append(peer_id)
Global.connectedPlayersByPeerID = connected_peers
var player_character = preload("res://scenes/Teddy.tscn").instantiate() var player_character = preload("res://scenes/Teddy.tscn").instantiate()
player_character.set_multiplayer_authority(peer_id) player_character.set_multiplayer_authority(peer_id)
await get_tree().create_timer(0.5).timeout await get_tree().create_timer(0.5).timeout
@ -75,6 +77,10 @@ func sync_name_all_peers(name):
func sync_respawn_speed(speed): func sync_respawn_speed(speed):
Global.respawnTimeModifier = speed Global.respawnTimeModifier = speed
@rpc("any_peer", "reliable")
func sync_gamemode(gamemode):
Global.gamemode = gamemode
@rpc("any_peer", "reliable") @rpc("any_peer", "reliable")
func check_name(name): # Returns true if it finds a matching name func check_name(name): # Returns true if it finds a matching name
for i in range(Global.connectedPlayers.size()): for i in range(Global.connectedPlayers.size()):