From 4084de8feadb697d0526c52afb023476fb5245b8 Mon Sep 17 00:00:00 2001 From: STEINMETZ THOMAS <thomas.steinmetz2@etu.unistra.fr> Date: Sat, 28 Mar 2020 11:43:39 +0100 Subject: [PATCH] #113 adding spawn points --- client/autoloads/gamestate.gd | 16 +-- client/levels/test/game.tscn | 11 -- server/autoloads/gamestate.gd | 41 ++++--- server/levels/test/game.tscn | 209 +++++++++++++++++++++++++++++++++- 4 files changed, 235 insertions(+), 42 deletions(-) diff --git a/client/autoloads/gamestate.gd b/client/autoloads/gamestate.gd index d8f9910..fbd55cb 100644 --- a/client/autoloads/gamestate.gd +++ b/client/autoloads/gamestate.gd @@ -36,27 +36,17 @@ puppet func startGame(): print("players: ", players.values()) get_node("/root/lobby").hide() - + var game:Node = preload("res://levels/test/game.tscn").instance() var player_scene:PackedScene = preload("res://entities/characters/player.tscn") get_tree().get_root().add_child(game) - - # TODO: check (and perhaps) the scene changing functionality - # get_tree().change_scene("res://scenes/levels/game/game.tscn") - #Next evey player will spa every other player including the server's own client! Try to move this to server only - var i = 1 for peer_id in players: var player:Node = player_scene.instance() - + player.set_name(str(peer_id)) get_node(GAMEPATH).add_child(player) - - - var spawnPosition:Vector3 = get_node("/root/game/spawnCollection/spawn"+str(i)).get_translation() - player.translate(spawnPosition) - - i+=1 + var playerArrow:Node = preload("res://entities/characters/playerArrow.tscn").instance() var playerCamera:Node = preload("res://entities/characters/camera.tscn").instance() diff --git a/client/levels/test/game.tscn b/client/levels/test/game.tscn index 6d5fc47..0e4874c 100644 --- a/client/levels/test/game.tscn +++ b/client/levels/test/game.tscn @@ -19,14 +19,3 @@ visible = false [node name="Map" parent="structure" instance=ExtResource( 3 )] transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0 ) - -[node name="spawnCollection" type="Spatial" parent="."] - -[node name="spawn1" type="Position3D" parent="spawnCollection"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 6, 0 ) - -[node name="spawn2" type="Position3D" parent="spawnCollection"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6, 0 ) - -[node name="spawn3" type="Position3D" parent="spawnCollection"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 6, 0 ) diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index 12fa5c5..2e3315d 100644 --- a/server/autoloads/gamestate.gd +++ b/server/autoloads/gamestate.gd @@ -10,6 +10,10 @@ var players = {} const ENVIRONMENT_LAYER = 0 const PLAYER_LAYER = 1 +const MAX_SPAWN_POINT = 70 + +var rng = RandomNumberGenerator.new() + func _ready(): # When a client connects to the server get_tree().connect("network_peer_connected", self, "_playerConnected") @@ -61,27 +65,36 @@ func _playerDisconnected(id): get_node(GAMEPATH+str(id)).queue_free() print("Player ", str(id), " disconnected") - - -func startGame(): - #Â Instancing the map and adding it to the scene tree - var game = preload("res://levels/test/game.tscn").instance() - get_tree().get_root().add_child(game) + +func spawnPlayer(): var playerScene = preload("res://entities/characters/player.tscn") - - var i = 1 + + var listAvailableSpawn = [] + # Create a list of available spawn points + for i in range(MAX_SPAWN_POINT): + listAvailableSpawn.append(i) + + rng.randomize() + + # Attribute a random spawn point for peer_id in players: - # TODO: Replace by a spawnPlayer function !!! var player = playerScene.instance() - player.set_name(str(peer_id)) get_node(GAMEPATH).add_child(player) - - var spawnPosition = get_node("/root/game/spawnCollection/spawn"+str(i)).get_translation() + var i=rng.randi_range(0,len(listAvailableSpawn)-1) + var spawnPosition = get_node(GAMEPATH+"spawnCollection/spawn"+str(listAvailableSpawn[i])).get_translation() player.translate(spawnPosition) - - i+=1 + listAvailableSpawn.remove(i) + + pass + +func startGame(): + #Â Instancing the map and adding it to the scene tree + var game = preload("res://levels/test/game.tscn").instance() + get_tree().get_root().add_child(game) + + spawnPlayer() # Broadcast the beginning of the game rpc("startGame") diff --git a/server/levels/test/game.tscn b/server/levels/test/game.tscn index 0f09937..b2d0dab 100644 --- a/server/levels/test/game.tscn +++ b/server/levels/test/game.tscn @@ -28,16 +28,217 @@ visible = false transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 0 ) [node name="spawnCollection" type="Spatial" parent="."] -transform = Transform( 0.996196, -0.0845788, 0.0209877, 0.084609, 0.996414, -0.000553806, -0.0208656, 0.00232744, 0.99978, 0, 0, 0 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ) [node name="spawn1" type="Position3D" parent="spawnCollection"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 6, 0 ) +transform = Transform( 1, -5.16593e-10, 0, -7.3851e-10, 1, 0, -2.6077e-08, 0, 1, -34.6373, 16.6167, 0 ) [node name="spawn2" type="Position3D" parent="spawnCollection"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 6, 0 ) +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, -37.389, 8.69147, 0 ) [node name="spawn3" type="Position3D" parent="spawnCollection"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 6, 0 ) +transform = Transform( 1, -5.16593e-10, 0, -7.34872e-10, 1, 0, -2.42144e-08, 0, 1, -41.128, 1.39522, 0 ) + +[node name="spawn4" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -42.611, -6.05512, 0 ) + +[node name="spawn5" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, -40.4679, -13.0318, 0 ) + +[node name="spawn6" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, -34.7281, -8.9612, 0 ) + +[node name="spawn7" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, -34.082, -15.9753, 0 ) + +[node name="spawn8" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -24.756, -17.1155, 0 ) + +[node name="spawn9" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, -28.03, -12.428, 0 ) + +[node name="spawn10" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -17.6637, -10.8524, 0 ) + +[node name="spawn11" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, -13.6147, -18.9069, 0 ) + +[node name="spawn12" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -34.0676, -2.66558, 0 ) + +[node name="spawn13" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, -29.773, 4.24735, 0 ) + +[node name="spawn14" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -29.2402, 10.4011, 0 ) + +[node name="spawn15" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, -20.817, -3.9546, 0 ) + +[node name="spawn16" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -18.669, 2.239, 0 ) + +[node name="spawn17" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, -14.12, 10.5359, 0 ) + +[node name="spawn18" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, -20.807, 10.3888, 0 ) + +[node name="spawn19" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -26.191, 20.5556, 0 ) + +[node name="spawn20" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -20.879, 18.947, 0 ) + +[node name="spawn21" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, -10.6348, 21.0143, 0 ) + +[node name="spawn22" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, -6.63466, 13.1877, 0 ) + +[node name="spawn23" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, -8.16122, 7.21328, 0 ) + +[node name="spawn24" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, -13.004, -6.07719, 0 ) + +[node name="spawn25" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -6.21352, -20.317, 0 ) + +[node name="spawn26" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 1.01595, -20.537, 0 ) + +[node name="spawn27" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 8.71135, -18.5043, 0 ) + +[node name="spawn28" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 11.8429, -12.8844, 0 ) + +[node name="spawn29" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 8.26875, -6.32962, 0 ) + +[node name="spawn30" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.3851e-10, 1, 0, -2.6077e-08, 0, 1, 4.71306, -13.5889, 0 ) + +[node name="spawn31" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -6.94854e-10, 1, 0, -7.45058e-09, 0, 1, 0.0494289, -6.70878, 0 ) + +[node name="spawn32" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, -10.8696, -12.7282, 0 ) + +[node name="spawn33" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, -2.70131, -10.9724, 0 ) + +[node name="spawn34" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -6.94854e-10, 1, 0, -7.45058e-09, 0, 1, 0.315, 3.32153, 0 ) + +[node name="spawn35" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, -7.987, 3.17654, 0 ) + +[node name="spawn36" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 6.987, 2.18943, 0 ) + +[node name="spawn37" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, 2.24382, 10.4767, 0 ) + +[node name="spawn38" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 9.3703, 7.12374, 0 ) + +[node name="spawn39" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, -3.81811, 21.524, 0 ) + +[node name="spawn40" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 4.66321, 23.2258, 0 ) + +[node name="spawn41" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 2.64021, 19.58, 0 ) + +[node name="spawn42" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 5.78274, 17.581, 0 ) + +[node name="spawn43" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 7.98103, 21.0454, 0 ) + +[node name="spawn44" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 14.9836, 13.5954, 0 ) + +[node name="spawn45" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 17.9586, 18.8275, 0 ) + +[node name="spawn46" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, 17.999, 8.11178, 0 ) + +[node name="spawn47" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 22.9518, 10.8147, 0 ) + +[node name="spawn48" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 28.795, 8.19825, 0 ) + +[node name="spawn49" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 26.6347, 18.1125, 0 ) + +[node name="spawn50" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 30.8507, 16.4486, 0 ) + +[node name="spawn51" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, 37.286, 16.99, 0 ) + +[node name="spawn52" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 43.7529, 13.8421, 0 ) + +[node name="spawn53" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 36.9867, 11.4018, 0 ) + +[node name="spawn54" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -6.94854e-10, 1, 0, -7.45058e-09, 0, 1, 45.998, 8.62985, 0 ) + +[node name="spawn55" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 38.238, 5.56808, 0 ) + +[node name="spawn56" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 44.802, 2.79939, 0 ) + +[node name="spawn57" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 16.286, 0.912769, 0 ) + +[node name="spawn58" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 32.684, 1.10845, 0 ) + +[node name="spawn59" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.45786e-10, 1, 0, -2.98023e-08, 0, 1, 17.96, -4.91127, 0 ) + +[node name="spawn60" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 21.216, -2.52389, 0 ) + +[node name="spawn61" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 25.9362, -5.03246, 0 ) + +[node name="spawn62" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 26.176, -0.82878, 0 ) + +[node name="spawn63" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.3851e-10, 1, 0, -2.6077e-08, 0, 1, 33.6412, -5.94321, 0 ) + +[node name="spawn64" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 42.1023, -8.85088, 0 ) + +[node name="spawn65" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 50.9602, -5.05289, 0 ) + +[node name="spawn66" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.13044e-10, 1, 0, -1.49012e-08, 0, 1, 24.3208, -9.86172, 0 ) + +[node name="spawn67" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 17.1953, -15.1805, 0 ) + +[node name="spawn68" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.31234e-10, 1, 0, -2.23517e-08, 0, 1, 35.804, -12.985, 0 ) + +[node name="spawn69" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.0213e-10, 1, 0, -1.11759e-08, 0, 1, 28.165, -16.5477, 0 ) + +[node name="spawn70" type="Position3D" parent="spawnCollection"] +transform = Transform( 1, -5.16593e-10, 0, -7.2032e-10, 1, 0, -1.86265e-08, 0, 1, 22.659, -17.0528, 0 ) [node name="killingFallArea" type="Area" parent="."] -- GitLab