import bge
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
LODlist=[]
len=-1
## get list of all objects with LOD
if 'LODList' not in own:
for objects in bge.logic.getCurrentScene().objects:
if 'LOD' in objects:
LODlist+=[objects]
len+=1
own['LODList']=LODlist
own['Len']=len
own['index']=0
own['Lights']=[]
own['LightNum']=-1
for child in own.children:
if 'Lights' in child:
own['Lights']+=[child]
own['LightNum']+=1
else:
s = own['index']
x=0
##proccess 10 piece of the list per frame
while (x<10):
item = own['LODList'][own['index']]
V= own.getVectTo(item)
Distance = V[0]
##print(str(own['index'])+" Distance is "+str(Distance))
## set LOD if the unit is less then 100 units
lights =[]
if Distance<100:
## get angle offset from player axis if its a light
if 'Light' in item:
Ang = V[1].angle(own.worldOrientation.col[1])
print(Ang)
## store the angle and the distance and the light object in a list
lights += [[Ang, V[0], item]]
if Distance > item['2']:
if item['LOD']!=3:
item.replaceMesh(item['Mesh3'],1,0)
item['LOD']=3
if Distance > item['1'] and Distance <= item['2']:
if item['LOD']!=2:
item.replaceMesh(item['Mesh2'],1,0)
item['LOD']=2
if Distance < item['1']:
if item['LOD']!=1:
item.replaceMesh(item['Mesh1'],1,0)
item['LOD']=1
else:
if item['LOD']!=4:
item.replaceMesh('Empty',1,0)
item['LOD']=4
own['index']+=1
if own['index']==s:
x=25
if own['index']>own['Len']:
own['index']=0
x+=1
if lights!=[]:
## this is where I need to sort the list somehow with distance and angle where
## the more lights are placed near the player, the less distance matters and the more
## angle matters (So there are lights near the player, and in the midground)
## and I need to do it in a manner where it is not too... twitchy....
print(str(lights))
for Hooks in lights:
if Hooks[1]>10:
Hooks[1]=Hooks[1]*2
if Hooks[0]<.1:
Hooks[1]*=.9
lights = sorted(lights[2], key=lambada)
print(str(lights))
print('Lights')
index=0
x2 = own['LightNum']
print(x2)
while x2>-1:
print('Light is'+own['Lights'][x2].name)
own['Lights'][x2].worldPosition=lights[index][2].worldPosition
print(own['Lights'][x2].name+" was placed at "+lights[index][2].name+"'s world position")
x2-=1
index +=1
main()
is what I have, but it’s not right,
I don’t really understand all of the stuff in list.sorted(stuff)
I want the to sort the list based on the second value of each tuple.
lights[index][1] = Distance after manipulation by scoring.