diff --git a/client/entities/items/beer.gd b/client/entities/items/beer.gd new file mode 100644 index 0000000000000000000000000000000000000000..519d544ba6b0c3a8e7a26bf5ac2ed1092299d66e --- /dev/null +++ b/client/entities/items/beer.gd @@ -0,0 +1,4 @@ +extends Spatial + +remotesync func deleteItemClient(): + self.queue_free() \ No newline at end of file diff --git a/client/entities/items/beer.tscn b/client/entities/items/beer.tscn index 2d9277ab5cd87b735e3d77e3b3770e3af9670ce2..99c95deba0f003e1a3a841b41755159aaa70e9d0 100644 --- a/client/entities/items/beer.tscn +++ b/client/entities/items/beer.tscn @@ -1,4 +1,6 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=13 format=2] + +[ext_resource path="res://entities/items/beer.gd" type="Script" id=1] [sub_resource type="Shader" id=1] code = "shader_type spatial; @@ -285,6 +287,7 @@ surfaces/4 = { } [node name="beer" type="Spatial"] +script = ExtResource( 1 ) [node name="Cylinder" type="MeshInstance" parent="."] transform = Transform( 0.389609, 0, 0, 0, 0.389609, 0, 0, 0, 0.389609, 0, -0.308799, 0 ) diff --git a/client/entities/items/trumpet.gd b/client/entities/items/trumpet.gd new file mode 100644 index 0000000000000000000000000000000000000000..74572a7fb82fc7277b6d48ce3c02ef23e0d9e49d --- /dev/null +++ b/client/entities/items/trumpet.gd @@ -0,0 +1,4 @@ +extends Spatial + +remotesync func deleteItemClient(): + queue_free() \ No newline at end of file diff --git a/client/entities/items/trumpet.tscn b/client/entities/items/trumpet.tscn index f5ac004617f4f9aab4cbdf323b0742d3a3c1a376..81f39626f480a7e30b2a5afe11bbd3e1b5e8031a 100644 --- a/client/entities/items/trumpet.tscn +++ b/client/entities/items/trumpet.tscn @@ -1,4 +1,6 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://entities/items/trumpet.gd" type="Script" id=1] [sub_resource type="Shader" id=1] resource_name = "Shader Nodetree" @@ -118,6 +120,7 @@ surfaces/1 = { } [node name="trumpet" type="Spatial"] +script = ExtResource( 1 ) [node name="Cylinder" type="MeshInstance" parent="."] transform = Transform( 0.172074, 0, 0, 0, 0.172073, 0, 0, 0, 0.172073, 0, 0, 0 ) diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index 2b4c27eec6bee93a2dc6b4bbd970ffe91c9dc412..f4d18aec7bebbc224eba62e07c7d00c2cee07c93 100644 --- a/server/autoloads/gamestate.gd +++ b/server/autoloads/gamestate.gd @@ -11,12 +11,18 @@ const ENVIRONMENT_LAYER = 0 const PLAYER_LAYER = 1 const MAX_SPAWN_POINT = 70 -const MAX_ITEMS = 30 +const MAX_ITEMS = 20 +var nbItemTotal = 0 + +var timer = null +var item_delay = 15 +signal deleteItem var rng = RandomNumberGenerator.new() var typeItems = ["beer","trumpet"] + func _ready(): # When a client connects to the server get_tree().connect("network_peer_connected", self, "_playerConnected") @@ -91,8 +97,13 @@ func spawnPlayer(): listAvailableSpawn.remove(i) +func _initNewItem(): + print("Nouveau spawn") + emit_signal("deleteItem") + spawnInitItem() + + func spawnInitItem(): - var listAvailableItem= [] # Create a list of available spawn points for i in range(MAX_SPAWN_POINT): @@ -102,16 +113,34 @@ func spawnInitItem(): for item_counter in range(MAX_ITEMS): + nbItemTotal+=1 var typeItem = rng.randi_range(0,len(typeItems)-1) var itemScene = load("res://entities/items/"+typeItems[typeItem]+".tscn") var item = itemScene.instance() - item.set_name("item"+str(item_counter)) - get_node(GAMEPATH+"itemCollection").add_child(item) var i=rng.randi_range(0,len(listAvailableItem)-1) + item.set_name("item"+str(nbItemTotal)) + get_node(GAMEPATH+"itemCollection").add_child(item) + self.connect("deleteItem",item,"on_timeout_complete") var position = get_node(GAMEPATH+"spawnCollection/spawn"+str(listAvailableItem[i]+1)).get_translation() item.translate(position) listAvailableItem.remove(i) - rpc("registerItem",item_counter,typeItem,position) + rpc("registerItem",nbItemTotal,typeItem,position) + timer.start() + +#func on_createNewItem(id): +# listAvailableItem.push_back(id.to_int()-1) +# var typeItem = rng.randi_range(0,len(typeItems)-1) +# var itemScene = load("res://entities/items/"+typeItems[typeItem]+".tscn") +# var item = itemScene.instance() +# var i=rng.randi_range(0,len(listAvailableItem)-1) +# item.set_name("item"+str(i+1)) +# get_node(GAMEPATH+"itemCollection").add_child(item) +# var position = get_node(GAMEPATH+"spawnCollection/spawn"+str(listAvailableItem[i]+1)).get_translation() +# item.translate(position) +# listAvailableItem.remove(i) +# rpc("registerItem",i+1,typeItem,position) +# print("new item add") + func startGame(): #Â Instancing the map and adding it to the scene tree @@ -119,6 +148,11 @@ func startGame(): get_tree().get_root().add_child(game) spawnPlayer() + timer = Timer.new() + timer.set_one_shot(false) + timer.set_wait_time(item_delay) + timer.connect("timeout",self,"_initNewItem") + get_node(GAMEPATH).add_child(timer) # Broadcast the beginning of the game rpc("startGame") spawnInitItem() diff --git a/server/entities/items/beer.gd b/server/entities/items/beer.gd index 34d1327bd64b3fc77621ddc292959516c743d598..8bbdc3b9f3e6afe1ad059adc508b6f83e1ccaf96 100644 --- a/server/entities/items/beer.gd +++ b/server/entities/items/beer.gd @@ -1,8 +1,32 @@ extends Area +const GAMEPATH = "/root/game/" + const player: = preload("res://entities/characters/player.gd") +#var timer = null +#var beer_delay = 15 +# +#signal createNewItem + +#func _ready(): +# timer = Timer.new() +# timer.set_one_shot(true) +# timer.autostart = true +# timer.set_wait_time(beer_delay) +# timer.connect("timeout",self,"on_timeout_complete") +# get_node(GAMEPATH).add_child(timer) + + -func _on_beer_body_entered(body): - if body is player: - queue_free() +func on_timeout_complete(): +# timer.free() + rpc("deleteItemClient") +# var x = self.name +# x.erase(0,4) +# x.to_int() +# print("x :",x) +# emit_signal("createNewItem",x) +# timer.stop() +# timer.queue_free() + queue_free() \ No newline at end of file diff --git a/server/entities/items/trumpet.gd b/server/entities/items/trumpet.gd index 34d1327bd64b3fc77621ddc292959516c743d598..2006681a5cac66bea1153391bc25ba1ecf93323d 100644 --- a/server/entities/items/trumpet.gd +++ b/server/entities/items/trumpet.gd @@ -2,7 +2,30 @@ extends Area const player: = preload("res://entities/characters/player.gd") +const GAMEPATH = "/root/game/" -func _on_beer_body_entered(body): - if body is player: - queue_free() +#var timer = null +#var beer_delay = 15 +# +# +#func _ready(): +# timer = Timer.new() +# timer.set_one_shot(true) +# timer.autostart = true +# timer.set_wait_time(beer_delay) +# timer.connect("timeout",self,"on_timeout_complete") +# get_node(GAMEPATH).add_child(timer) + + +func on_timeout_complete(): + rpc("deleteItemClient") + queue_free() + + + + + + +#func _on_beer_body_entered(body): +# if body is player: +# queue_free()