Skip to content
Snippets Groups Projects
Commit b0f812fc authored by STEINMETZ THOMAS's avatar STEINMETZ THOMAS
Browse files

#125 fix position and detection

parent e9cf9b73
Branches
No related merge requests found
......@@ -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)
......
......@@ -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
......
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():
......
......@@ -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"]
......@@ -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():
......
......@@ -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 )
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment