diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index ac65b487fa57bfa1e596b0bef5d36d45325e8e2f..7f1e727fe104810de8724b9b071a6225a5de3074 100644 --- a/server/autoloads/gamestate.gd +++ b/server/autoloads/gamestate.gd @@ -11,16 +11,16 @@ const ENVIRONMENT_LAYER = 0 const PLAYER_LAYER = 1 const MAX_SPAWN_POINT = 70 -const MAX_ITEMS = 5 +const MAX_ITEMS = 40 var nbItemTotal:int = 0 var timer = null -var item_delay = 15 +var item_delay = 50 signal deleteItem var rng = RandomNumberGenerator.new() - -var typeItems = ["beer","trumpet"] +#,"trumpet" +var typeItems = ["beer"] @@ -118,17 +118,20 @@ 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]+".gd") + var itemScene = load("res://entities/items/"+typeItems[typeItem]+".tscn") + var newitemScene = itemScene.instance() var i=rng.randi_range(0,len(listAvailableItem)-1) var position = get_node(GAMEPATH+"spawnCollection/spawn"+str(listAvailableItem[i]+1)).get_translation() - var newitemScene:Object = itemScene.new(nbItemTotal,typeItem,position) - newitemScene.set_name("item"+str(newitemScene.id)) - get_node(GAMEPATH+"itemCollection").add_child(newitemScene) + newitemScene.set_name("item"+str(nbItemTotal)) + get_node(GAMEPATH+"itemCollection/").add_child(newitemScene) + newitemScene.id = nbItemTotal + newitemScene.typeItem = typeItem self.connect("deleteItem",newitemScene,"on_timeout_complete") newitemScene.translate(position) listAvailableItem.remove(i) rpc("registerItem",nbItemTotal,typeItem,position) - timer.start() + + timer.start() #func on_createNewItem(id): # listAvailableItem.push_back(id.to_int()-1) diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd index 6bae220e7ac666b20dbc0c559c6c1af37c9b5cdc..8fa2abc988d668f2f9e839965d9fc1c50ef74899 100644 --- a/server/entities/characters/player.gd +++ b/server/entities/characters/player.gd @@ -193,9 +193,9 @@ mouseX:int, mouseY:int, itemInput:bool): if itemInput : print("input") var list = get_node(GAMEPATH+"itemCollection/").get_children() -# for i in list: -## print("node :"+str(i.id)) -# i.nearItem() + for i in list: +# print("node :"+str(i.id)) + i.nearItem(ownId) pass diff --git a/server/entities/items/beer.gd b/server/entities/items/beer.gd index 4824238665916908c3688d3b68831b3ade4a10d4..2b536e034092c373cb4a6e06a139fe7b4b17a08f 100644 --- a/server/entities/items/beer.gd +++ b/server/entities/items/beer.gd @@ -1,24 +1,28 @@ -extends Area +extends Spatial const player: = preload("res://entities/characters/player.gd") - const GAMEPATH = "/root/game/" - var id:int var typeItem:int -var position:Vector3 +var nearPlayer:Array + + +func nearItem(idPlayer: int): + print("item: "+str(id)+" player "+str(idPlayer)) + return nearPlayer.has(idPlayer) +func _on_beer_body_entered(body): + print("fonction entrer body beer") + if body is player: + nearPlayer.append(body.name) + -func _init(id: int, typeItem: int, position:Vector3): - self.id = id - self.typeItem = typeItem - self.position = position +func _on_beer_body_exited(body): + print("fonction sortir body beer") + if body is player: + nearPlayer.erase(body.name) - -func nearItem(): - var listBody = self.get_overlapping_bodies() - print(listBody) func on_timeout_complete(): diff --git a/server/entities/items/beer.tscn b/server/entities/items/beer.tscn index ba8a2ed3b2b6630bb6242af7b82ea1b00e89a6f3..ceb40550dac6e9231194f5634df92bc892eb9418 100644 --- a/server/entities/items/beer.tscn +++ b/server/entities/items/beer.tscn @@ -287,15 +287,18 @@ surfaces/4 = { } [sub_resource type="SphereShape" id=12] +radius = 2.39275 -[node name="Beer" type="Area"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) +[node name="Spatial" type="Spatial"] +script = ExtResource( 1 ) + +[node name="Beer" type="Area" parent="."] +transform = Transform( 0.267735, 0, 0, 0, 0.270111, 0, 0, 0, 0.446903, 0, 0, 0 ) collision_layer = 4 collision_mask = 3 -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.358291, 0 ) +[node name="Cylinder" type="MeshInstance" parent="Beer"] +transform = Transform( 1.23014, 0, 0, 0, 1.23014, 0, 0, 0, 1.23014, 0, -0.131254, 0 ) layers = 4 mesh = SubResource( 11 ) material/0 = null @@ -304,5 +307,8 @@ material/2 = null material/3 = null material/4 = null -[node name="CollisionShape" type="CollisionShape" parent="."] +[node name="CollisionShape" type="CollisionShape" parent="Beer"] +transform = Transform( 3.60417, 0, 0, 0, 2.77809, 0, 0, 0, 2.27813, 0, 0, 0 ) shape = SubResource( 12 ) +[connection signal="body_entered" from="Beer" to="." method="_on_beer_body_entered"] +[connection signal="body_exited" from="Beer" to="." method="_on_beer_body_exited"] diff --git a/server/entities/items/trumpet.gd b/server/entities/items/trumpet.gd index 4824238665916908c3688d3b68831b3ade4a10d4..efb3eeca3a8c2f57d25d3d1fc6518b726c0dddb9 100644 --- a/server/entities/items/trumpet.gd +++ b/server/entities/items/trumpet.gd @@ -8,17 +8,19 @@ const GAMEPATH = "/root/game/" var id:int var typeItem:int var position:Vector3 +var nearPlayer:Array func _init(id: int, typeItem: int, position:Vector3): self.id = id self.typeItem = typeItem self.position = position + self.nearPlayer = [] - -func nearItem(): - var listBody = self.get_overlapping_bodies() - print(listBody) + +func nearItem(idPlayer: int): + print("item: "+str(self.id)+" player "+str(idPlayer)) + return self.nearPlayer.has(idPlayer) func on_timeout_complete(): diff --git a/server/levels/test/game.tscn b/server/levels/test/game.tscn index 1005f6e78f4ae6d1805c2360c28085d63301b12c..75c9221f990f46412bdf33cdb2e47fdf9d7c114d 100644 --- a/server/levels/test/game.tscn +++ b/server/levels/test/game.tscn @@ -11,7 +11,7 @@ extents = Vector3( 175.136, 87.8901, 1 ) script = ExtResource( 1 ) [node name="camera" type="Camera" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.08, 22.8 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.08, 43.645 ) fov = 30.0 [node name="structure" type="Spatial" parent="."] @@ -29,7 +29,6 @@ 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="."] -editor/display_folded = true [node name="spawn1" type="Position3D" parent="spawnCollection"] transform = Transform( 1, -5.16593e-10, 0, -7.3851e-10, 1, 0, -2.6077e-08, 0, 1, -34.6373, 16.6167, 0 )