From b0f812fc674690d83698a4c6bdd43a26d1502229 Mon Sep 17 00:00:00 2001 From: STEINMETZ THOMAS <thomas.steinmetz2@etu.unistra.fr> Date: Sun, 19 Apr 2020 14:28:55 +0200 Subject: [PATCH] #125 fix position and detection --- server/autoloads/gamestate.gd | 21 ++++++++++++--------- server/entities/characters/player.gd | 6 +++--- server/entities/items/beer.gd | 28 ++++++++++++++++------------ server/entities/items/beer.tscn | 18 ++++++++++++------ server/entities/items/trumpet.gd | 10 ++++++---- server/levels/test/game.tscn | 3 +-- 6 files changed, 50 insertions(+), 36 deletions(-) diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index ac65b48..7f1e727 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 6bae220..8fa2abc 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 4824238..2b536e0 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 ba8a2ed..ceb4055 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 4824238..efb3eec 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 1005f6e..75c9221 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 ) -- GitLab