Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bge,ast,math, time,bpy
- from mathutils import Vector
- from mathutils import Matrix
- cont = bge.logic.getCurrentController()
- own = cont.owner
- def stick():
- scene = bge.logic.getSceneList()['Scene']
- for obj in scene.objects:
- if 'Stick' in obj:
- obj.localLinearVelocity.x=0
- obj.localLinearVelocity.y=0
- obj.localLinearVelocity.z=0
- def navigate(data):
- self = data[0]
- self = own.childrenRecursive[self]
- topSpeed = data[1]
- if own['Target']=="None" and 'Player' not in own:
- own['X']*=.999
- own['Y']*=.999
- if 'nav_Point' in own and own['Impacted']==0:
- #print('engaged')
- v2 = own.getVectTo(own['nav_Point'])
- if 'Reverse' not in own:
- own.worldPosition = own.worldPosition + (v2[1]*(topSpeed*.125))
- else:
- own.worldPosition = own.worldPosition + (v2[1]*(topSpeed*-.06125))
- target = None
- if 'KDTree' in own.scene.objects['Plane']:
- kd = own.scene.objects['Plane']['KDTree']
- near = kd.find(own.worldPosition)
- point = own.scene.objects['Plane']['KDList'][near[1]]
- z = point.z
- #print(z-own.worldPosition.z)
- own.alignAxisToVect(own.getVectTo(own['nav_Point'])[1],1,.1)
- own.alignAxisToVect([0,0,1],2,1)
- own.worldPosition.z = (( z+.45) + (own.worldPosition.z*15) )/16
- if own['Target']!="None" and own['Target']!="None":
- target = own['Target']
- #print(target)
- if own.getDistanceTo(target[0])<4:
- target = target[0]
- own['nav_Point']= kd.find(own.scene.objects[target].worldPosition)[0]
- own.worldLinearVelocity*=0
- own.worldAngularVelocity*=0
- own['Steer']=0
- own['Speed']=0
- local = own.worldTransform.inverted() @ own['nav_Point']
- local.z=0
- #print(local.magnitude)
- #bge.render.drawLine(own['nav_Point'],own['nav_Point']+Vector([0,0,1]),(0,0,1))
- if local.magnitude>2:
- v1 = own.worldLinearVelocity.copy()
- v1.z = 0
- v1*=.125
- end = own.worldPosition+(v1.normalized()*(v1.magnitude+.06125))
- start=own.worldPosition
- ray = own.rayCast(end,start,0,"",0,0,0)
- #bge.render.drawLine(start,end,(1,0,0))
- if not ray[0]:
- for wheel in own['Front_Wheels']:
- end = wheel.worldPosition+(v1*.05)
- start=wheel.worldPosition
- ray = own.rayCast(end,start,0,"",0,0,0)
- if ray[0]:
- break
- go = 1
- if ray[0]:
- #bge.render.drawLine(start,end,(1,0,0))
- own['Speed']=-1
- go = 0
- own['Steer']+=.1
- own['Reverse']=15
- s=own['Steer']
- if local.y>0:
- if 'Reverse' not in own:
- own['Forward']=15
- if own['Speed']<.15 and go==1:
- own['Speed']=.15
- if abs(local.x*1.5)-local.y<0:
- if local.magnitude>16:
- if own['Speed']<=1.9 and go==1:
- own['Speed']+=.1
- else:
- own['Speed']*=.99
- else:
- if own['Speed']<=.5 and go==1:
- own['Speed']+=.05
- else:
- own['Speed']*=.99
- if local.x>0 and own['Steer']<1.9:
- #own.applyTorque([0,0,-1.25],1)
- own['Steer']-=.05
- if local.x<0 and own['Steer']>-1.9:
- own['Steer']+=.05
- #own.applyTorque([0,0,1.25],1)
- if own.localLinearVelocity.x>topSpeed:
- own['Speed']*=.9
- elif own['Reverse']>=1:
- own['Reverse']-=1
- else:
- del own['Reverse']
- else:
- if 'Forward' not in own:
- own['Reverse']=15
- own['Read']=str(local)
- if local.x>0 and own['Steer']<1.49:
- #own.applyTorque([0,0,-5.5],1)
- own['Steer']-=.05
- if local.x<0 and own['Steer']>-1.49:
- #own.applyTorque([0,0,5.5],1)
- own['Steer']+=.05
- elif own['Forward']>=1:
- own['Forward']-=1
- else:
- del own['Forward']
- else:
- own['Speed']*=.9
- #print('rem')
- if target==None:
- del own['nav_Point']
- def goal(data):
- self = data[0]
- self = own.childrenRecursive[self]
- plan = data[1]
- target = data[2]
- if type(target) is str:
- target= own.scene.objects[target]
- if own.getDistanceTo(target)<4 and 'Plan' in own:
- del own['Plan']
- navmesh = own.scene.objects['Navmesh']
- #print(target)
- if plan == "Attack":
- #print('think')
- if target['Health']<=0:
- if target.name!='Bob_3':
- own['Parts'][data[-1]][3] ='Bob_3'
- #print('set next target')
- path = navmesh.findPath(own.worldPosition,own.scene.objects['Bob_3'].worldPosition)
- #print(path)
- #print('has plan')
- own['nav_Point'] = path.pop(0)
- self['Plan'] = path
- own['Target']="None"
- if 'Plan' not in self:
- if own.getDistanceTo(target)>4:
- #print(help(navmesh.findPath))
- path = navmesh.findPath(own.worldPosition,target.worldPosition)
- #print(path)
- self['Plan'] = path
- #print('has plan')
- else:
- if 'KDTree' in own.scene.objects['Plane']:
- kd = own.scene.objects['Plane']['KDTree']
- own['nav_Point']= kd.find(target.worldPosition)[0]
- else:
- own['nav_Point']=target.worldPosition
- local = own.worldTransform.inverted() @ target.worldPosition
- if local.y>0:
- if local.x<0 and own['Steer']>-1.9:
- own['Steer'] -=.1
- if local.x>0 and own['Steer']<1.9:
- own['Steer'] +=.1
- else:
- if local.x>0 and own['Steer']>-1.9:
- own['Steer'] -=.1
- if local.x<0 and own['Steer']<1.9:
- own['Steer'] +=.1
- if len(self['Plan'])>=1:
- if 'nav_Point' not in own:
- if own.getDistanceTo(target)>4:
- own['nav_Point'] = self['Plan'].pop(0)
- print('set point')
- else:
- if 'KDTree' in own.scene.objects['Plane']:
- kd = own.scene.objects['Plane']['KDTree']
- own['nav_Point']= kd.find(target.worldPosition)[0]
- else:
- own['nav_Point']=target.worldPosition
- if own.getDistanceTo(target)<2 and 'Steer' in own:
- #print('too close')
- own.worldLinearVelocity*=.9
- own.worldAngularVelocity*=.9
- if 'KDTree' in own.scene.objects['Plane']:
- kd = own.scene.objects['Plane']['KDTree']
- own['nav_Point']= kd.find(target.worldPosition)[0]
- else:
- own['nav_Point']=target.worldPosition
- own['Speed']=-.25
- own['Reverse']=15
- else:
- if 'Plan' in own:
- if len(own['Plan'])>=2:
- if own.getDistanceTo(own['Plan'][0])<2 and 'nav_Point' in own:
- del own['nav_Point']
- if target['Health']<=0:
- if target.name!='Bob_3':
- own['Parts'][data[-1]][3] ='Bob_3'
- print('set next target')
- path = navmesh.findPath(own.worldPosition,own.scene.objects['Bob_3'].worldPosition)
- print(path)
- self['Plan'] = path
- print('has plan')
- if 'nav_Point' in own:
- del own['nav_Point']
- if own.getDistanceTo(target)<4 and 'nav_Point' in own:
- del own['nav_Point']
- if 'Plan' in own and bge.logic.getRandomFloat()>.9:
- del own['Plan']
- def tracker(data):
- self = data[0]
- self = own.childrenRecursive[self]
- if 'Aim' in own['Act']:
- own['Aiming']=True
- elif 'Aim' in own:
- del own['Aiming']
- x = data[1]
- if type(x) is str:
- x = own[x]
- y = data[2]
- if type(y) is str:
- y = own[y]
- if 'init_tracker_p' not in self:
- self['init_tracker_p'] = self.parent.worldTransform.inverted() @ self.worldPosition
- self['init_tracker_r'] = self.parent.worldOrientation.inverted() @ self.worldOrientation
- else:
- self.worldPosition = self.parent.worldTransform @ self['init_tracker_p']
- self.worldOrientation = self.parent.worldOrientation @ self['init_tracker_r']
- self.applyRotation([y,0,x],1)
- if own['Target']!=None and own['Target']!="None":
- if own['Target'][1]>=1:
- target=own['Target'][0]
- if type(target)==str:
- target = own.scene.objects[target]
- if 'Armed' not in self:
- self['Armed']=[500, 0,0]
- print('armed')
- d = self.getDistanceTo(target)
- #v = abs((d*d)*.0225)
- p = target.worldPosition.copy()
- ##p.z+=v
- local = self.worldTransform.inverted() @ p
- if local.y>0:
- mod = local.y*.01
- own['Sens']=0
- if local.x<0:
- own['X']+=mod+.01
- elif local.x>0:
- own['X']-=mod+.01
- mod = local.y*.01
- if local.z>0:
- own['Y']+=mod+.01
- elif local.z<0:
- own['Y']-=mod+.01
- else:
- own['X']*=.9
- own['Y']*=.9
- p = own.worldPosition
- p2 = p+(own.worldOrientation.col[1]*10)
- #bge.render.drawLine(p,p2,(0,0,1))
- self.alignAxisToVect(self.getVectTo(target)[1],1,.25)
- else:
- if 'Armed' in self:
- if self['Armed'][0]>=1:
- #print('aligning')
- self['Armed'][0]-=1
- own['X']*= .99
- own['Y']*= .99
- #self.worldPosition = self.parent.worldTransform @ self['init_tracker_p']
- #self.worldOrientation = self.worldOrientation.lerp( self.parent.worldOrientation @ self['init_tracker_r'],.01)
- #self.applyRotation([0,0,0],1)
- else:
- del self['Armed']
- #print('safe')
- #own['X']=0
- #own['Y']=0
- def barrel(data):
- self = data[0]
- self = own.childrenRecursive[self]
- projectile = data[1]
- axis = data[2]
- speed = data[3]
- offset = data[4]
- owner = own
- cost =1
- if 'cost' in self:
- cost=self['cost']
- if 'owner' in own:
- owner = own['owner']
- if 'Charge' in self:
- if 'HOLDING' not in owner:
- if self['Charge']>=1:
- added = own.scene.addObject(projectile,own,0)
- added['Charge']=self['Charge']
- added.applyMovement((0,offset,0),1)
- self['Charge']=0
- if 'FX' in self:
- self['FX'].applyMovement((0,offset,0),1)
- self['FX'].setParent(added,0,1)
- self['FX'].localScale*= Vector([1.25,2,1.25])
- added['FX'] = self['FX']
- cont.deactivate(cont.actuators['Action'])
- del self['FX']
- print('destroyedFX')
- elif 'FX' not in self:
- self['FX'] = own.scene.addObject(self['ChargeFX'],self,0)
- print('createdFX')
- cont.activate(cont.actuators['Action'])
- self['FX'].setParent(self,0,1)
- self['FX'].applyMovement((0,.25,0),1)
- self['FX2'] = own.scene.addObject('Point',self,0)
- self['FX2'].applyMovement((0,.25,0),1)
- self['FX2'].setParent( self['FX'],0,1)
- else:
- c = .125+(self['Charge']*.001)
- self['FX'].localScale = [c*1.5,c,c*1.5]
- self['FX'].color = [c*64, c*64 , c*64,1]
- self['FX'].applyRotation((0,c*-.1*c,0),1)
- bpy.data.lights[self['FX2'].name].energy = (self['Charge']*8)*(.5 + (bge.logic.getRandomFloat()*.5))
- if 'Firing' in own:
- prop = projectile+"s_Clip"
- #print(prop)
- if 'Running' in own:
- own['Running']+=(math.pi*2)/60
- if own['Running']>math.pi*2:
- own['Running']=0
- if prop in own:
- if own[prop]>=cost:
- if 'Charge' not in self:
- #print(self)
- own[prop]-=cost
- added = own.scene.addObject(projectile,self,0)
- if 'extra' in self:
- own.scene.addObject(self['extra'],own,0)
- if 'Stay' in added:
- added.setParent(own,0,1)
- added.worldLinearVelocity = self.worldOrientation.col[axis]*(speed*1)
- try:
- added.worldLinearVelocity+=own.worldLinearVelocity
- except:
- pass
- added.worldPosition += self.worldOrientation.col[axis]*offset
- added['owner']=own
- if 'Color' in self:
- added.color = self.color
- print(self.color)
- print('set')
- if 'Damage' in self:
- added['Damage']=self['Damage']
- added['owner']=own
- if 'Target' in owner:
- if owner['Target']!="None" and owner['Target']!=None:
- added['Target']=owner['Target']
- elif self['Charge']+cost<100:
- #print(self['Charge'])
- own[prop]-=cost
- self['Charge']+=cost
- else:
- own['reload_needed']=True
- elif 'Punch' not in owner['Act'] and 'Running' in own:
- own['Running']=0
- if 'Charge' in self:
- own['Charge']=self['Charge']
- def fire_control(data):
- self = data[0]
- if self!=own.name:
- self = own.childrenRecursive[self]
- else:
- self = own
- if 'owner' not in own:
- owner = own
- else:
- owner = own['owner']
- if own['Fire']==4:
- if owner!=own:
- owner['Recoil']=own['Recoil']
- if own['Fire']==1:
- own['Fire']=2
- own['Firing']=True
- elif 'Firing' in own:
- del own['Firing']
- if own['Fire']>1 and own['Fire']<own['Rechamber']:
- own['Fire']+=1
- elif own['Rechamber']<=own['Fire']:
- own['Fire']=0
- if 'Recharge' in own:
- #print(own['Recharge'])
- added = own.scene.addObject(own['Recharge'],own,0)
- if 'Charge' in own:
- added.actuators['Sound'].pitch =-.66+( own['Charge']*.2)
- if own['Fire']==own['Reload']:
- own.scene.addObject(own['Reload_Sound'],own,0)
- own['Reloading']=True
- #print('start')
- #print(owner.name)
- for prop in own.getPropertyNames():
- if prop[-6:]=="s_Clip":
- #print(prop)
- length = len(prop)
- ammo = prop[:-5 or None]
- #ammo = prop[:7]
- #print('ammo'+ammo)
- max = prop+"_Max"
- diff = own[max]-own[prop]
- if max in own and ammo in owner:
- #print('set')
- if owner[ammo]-diff>0:
- owner[ammo]-=diff
- own[prop]=own[max]
- else:
- own[prop]+=owner[ammo]
- owner[ammo]=0
- else:
- if max in own:
- print('found '+max)
- if ammo in owner:
- print('found '+ammo)
- else:
- print('did not find'+ammo)
- else:
- if 'Reloading' in own:
- del own['Reloading']
- if own['Fire']<0:
- own['Fire']+=1
- #print(own.children)
- def push(data):
- self = data[0]
- self = own.childrenRecursive[self]
- if 'push_init' not in self:
- self['push_init']=own.worldTransform.inverted() @ self.worldPosition
- amount = data[1]
- if type(amount) is str:
- amount = own[amount]*1.5
- axis = data[2]
- distance = data[3]
- start = (self.parent.worldTransform @ self['push_init'] ) + (own.worldOrientation.col[2] *0)
- end = start + own.worldOrientation.col[2]* -distance
- end2 = end+own.worldOrientation.col[1]*(own.localLinearVelocity.y*.1)
- ray = own.rayCast(end,start,0,"",0,0,0)
- if ray[0]==self:
- ray = self.rayCast(end,ray[1],0,"",0,0,0)
- ray2 = self.rayCast(end2,self.worldPosition,0,"",0,0,0)
- if ray2[0]:
- own.alignAxisToVect(ray2[2],2,.075)
- #print(ray)
- if ray[0]:
- #print(ray[0])
- #own.alignAxisToVect(ray[2],2,.075)
- own['hit'].append((ray[1],ray[2]) )
- #bge.render.drawLine(start,ray[1],(0,0,1))
- d = (start - ray[1]).magnitude
- d2 = (start-end).magnitude
- d = d/d2
- d = 1-d
- d*=d*.2
- if axis =="X":
- angle = own.worldOrientation.col[1]
- #print(amount)
- if d>1:
- d=1
- own.applyImpulse(ray[1],own.worldOrientation.col[2]*(d))
- if abs(own['Speed'])<.1:
- own.localLinearVelocity.y*=.95
- own.localLinearVelocity.x*=.1
- if own.localLinearVelocity.z<.0125:
- own.localLinearVelocity.z*=.95
- own.localLinearVelocity.z*=.95
- if 'Controller' in own:
- self.removeParent()
- own.localAngularVelocity.x*=.01
- #own.localLinearVelocity.y*=.1
- own.localAngularVelocity.z*=.1
- own.localAngularVelocity.y*=.01
- if abs(own['Speed'])<.1:
- own.localLinearVelocity.x*=.01
- own.localLinearVelocity.y*=.01
- self.worldPosition = ray[1]+(own.worldOrientation.col[2]*.175)
- if 'Controller' in own:
- self.setParent(own,0,1)
- self.worldPosition+=own.worldOrientation.col[2] * -.05
- if own['Speed']>0:
- if own.localLinearVelocity.y<own['Speed']*1.5:
- own.applyForce((0,own['Speed']*2,0),1)
- else:
- if own.localLinearVelocity.y>own['Speed']*1.5:
- own.applyForce((0,own['Speed']*2,0),1)
- own.alignAxisToVect(ray[2],2,.1)
- if 'steer_init' in self:
- if own['Speed']>.01:
- own.applyRotation((0,0,own['Steer']*.05),1)
- elif own['Speed']<-.01:
- own.applyRotation((0,0,-own['Steer']*.05),1)
- else:
- if 'Controller' in own:
- self.removeParent()
- self.worldPosition = self.worldPosition.lerp((own.worldTransform @ self['push_init']) + (own.worldOrientation.col[2]*-(distance-.125) ),.06125)
- if 'Controller' in own:
- self.setParent(own,0,1)
- def steer(data):
- self = data[0]
- self = own.childrenRecursive[self]
- amount = data[1]
- if type(amount) is str:
- amount = own[amount]
- axis = data[2]
- if 'steer_init' not in self:
- self['steer_init']=self.parent.worldOrientation.inverted() @ self.worldOrientation
- self.worldOrientation = self.parent.worldOrientation @ self['steer_init']
- if axis=="Z":
- local = own.worldTransform.inverted() @ self.worldPosition
- val=-1
- if local.y>0:
- val=1
- self.applyRotation(own.worldOrientation.col[2]*(amount*val),0)
- if 'R' in self:
- self.applyRotation((self['R'],0,0),1)
- if own.localLinearVelocity.y>.1:
- own.localAngularVelocity.z = ((own.localAngularVelocity.z*15) + (own['Steer']*64))/16
- elif own.localLinearVelocity.y<-.1:
- own.localAngularVelocity.z = ((own.localAngularVelocity.z*15) + (-own['Steer']*64))/16
- #print('ran')
- def sense(data):
- #print(own.name)
- self = data[0]
- self = own.childrenRecursive[self]
- prop = data[1]
- value = data[2]
- freqency = data[3]
- #print(data)
- if prop+'Track' not in self:
- l = []
- for obj in own.scene.objects:
- if 'Health' in obj:
- if obj['Health']>=1:
- if prop in obj:
- if value =="Any":
- l.append(obj)
- elif obj[prop]==value:
- l.append(obj)
- self[prop+'Track'] = [ l, data[3]]
- elif self[prop+'Track'][1]>=1:
- self[prop+'Track'][1]-=1
- targets = []
- dat = self[prop+'Track'][0]
- #print(dat)
- for obj in dat:
- local = self.worldTransform.inverted() @ obj.worldPosition
- #print(local)
- if local.z>0 and abs(local.x*2)-local.z<0 and abs(local.y*2)-local.z<0 and obj['Health']>=1:
- ray = own.rayCast(obj.worldPosition,self.worldPosition,0,"",0,0,0)
- #if ray[0]:
- # print(ray[0])
- if ray[0]==obj:
- targets.append( (obj,local, local.magnitude) )
- closest = None
- d = 10000
- for obj in targets:
- if obj[2]<d:
- d = obj[2]
- closest = obj
- if closest!=None and d<data[4]:
- own['Target']= [obj[0].name ,int(freqency)]
- if 'Fire' in own and 'owner' not in own:
- if 'reload_needed' not in own:
- if own['Fire']==0:
- own['Fire']=1
- else:
- own['Fire']=own['Reload']
- del own['reload_needed']
- own['Read']= str(own['Target'])
- else:
- if 'Target' in own:
- if own['Target']!=None and own['Target']!="None":
- if own['Target'][1]>=1:
- own['Target'][1]-=1
- else:
- own['Target']="None"
- own['Read']= str(own['Target'])
- else:
- del self[prop+'Track']
- def track(data):
- aiming = data[0]
- target = None
- g=1
- if own['Target']!="None":
- if own['Target'][1]>=1:
- target = own.scene.objects[own['Target'][0]]
- own['Target'][1]-=1
- else:
- own['Target']= "None"
- g=0
- if g==1:
- if type(target) is str:
- target = own.scene.objects[target]
- axis = data[2]
- amount = data[3]
- aiming = own.childrenRecursive[aiming]
- if 'track_init' not in aiming:
- aiming['track_init']=aiming.parent.worldOrientation.inverted() @ aiming.worldOrientation
- aiming['track_init2']=aiming.parent.worldTransform.inverted() @ aiming.worldPosition
- aiming.worldPosition = aiming.parent.worldTransform @ aiming['track_init2']
- aiming.worldOrientation = aiming.worldOrientation.lerp(aiming.parent.worldOrientation @ aiming['track_init'],.5)
- if target!=None:
- #print(target)
- aiming.alignAxisToVect(aiming.getVectTo(target)[1],axis,amount)
- def glow(data):
- target =data[0]
- target = own.childrenRecursive[target]
- color1 = Vector(data[1])
- color2 = Vector(data[2])
- freqency = data[3]*.5
- time = data[4]
- if type(time) is str:
- time = own[time]
- value = abs(math.sin(time*freqency))
- target.color = color1.lerp(color2,value)
- def piston(data):
- target = data[0]
- target = own.childrenRecursive[target]
- time = data[1]
- if type(time) is str:
- min = data[5]
- max = data[6]
- consume = data[7]
- time = own[time]
- if time<min:
- time=0
- elif time>max:
- time=0
- if own[consume]<=0:
- time =0
- axis = data[2]
- freqency = data[3]*.5
- distance = data[4]
- #print(data)
- #print(time)
- if 'piston_init' not in target:
- pt = target.parent
- matrix = pt.worldTransform.inverted()
- target['piston_init'] = matrix @ target.worldPosition
- target.worldPosition = target.parent.worldTransform @ target['piston_init']
- if axis==1 and time!=0:
- #print('fire')
- target.applyMovement([0,math.sin(time*freqency)*distance,0],1)
- def rotate(data):
- #print(data)
- target = data[0]
- target = own.childrenRecursive[target]
- amount = data[1]
- if type(amount) is str:
- amount = own[amount]
- #print(data)
- axis = data[2]
- if axis=="X":
- if data[1]=="Speed":
- local = target.parent.worldTransform.inverted() @ target.worldPosition
- if local.x>0:
- val=1
- else:
- val=-1
- if 'R' in target:
- target['R']+=(amount*val)
- if target['R']>math.pi*2:
- target['R']-=math.pi*2
- elif target['R']<0:
- target['R']=math.pi + target['R']
- target.applyRotation((amount,0,0),1)
- elif axis==0:
- target.applyRotation((amount,0,0),1)
- elif axis==1:
- target.applyRotation((0,amount,0),1)
- else:
- target.applyRotation((0,0,amount),1)
- Functions = { 'Rotate':rotate, 'Piston':piston, 'Glow':glow ,"Track":track, "Sense":sense, 'Steer':steer, "Push":push ,"Fire_Control":fire_control, 'Barrel':barrel, 'Tracker':tracker, 'Goal':goal, 'Navigate':navigate}
- def main():
- #if 'start_stick' not in own.scene.objects['Plane']:
- #own.scene.objects['Plane']['start_stick']=True
- #own.scene.pre_draw.append(stick)
- #own.scene.post_draw.append(stick)
- own['hit']=[]
- if 'init' not in own:
- own['Impacted']=0
- own['Parts']= []
- own['Front_Wheels']=[]
- own['wheels']=[]
- own['Move']=[]
- own['Act']=[]
- own['Seats']=[]
- own['Up']=own.worldOrientation.col[2]
- w=0
- for prop in own.getPropertyNames():
- if prop[:4]=="part":
- prop1 = ast.literal_eval(own[prop])
- if prop1[1]=="self":
- prop1[1]=own.name
- own['Parts'].append(prop1)
- for child in own.childrenRecursive:
- if 'Helper' in child:
- own['Helper']=child
- if 'Seat_Check' in child:
- local = own.worldTransform.inverted() @ child.worldPosition
- diff = own.worldOrientation.inverted() @ child.worldOrientation
- own['Seats'].append([local,diff,child['Seat_Check'] ])
- child.endObject()
- else:
- for prop in child.getPropertyNames():
- #print(prop[:4])
- if prop[:4]=="part":
- if child[prop]!="None":
- prop1 = ast.literal_eval(child[prop])
- prop1.append(own.name)
- if prop1[1]=="self":
- prop1[1]=child.name
- own['Parts'].append(prop1)
- if prop1[0]=="Steer":
- own['Front_Wheels'].append(child)
- if prop1[0]=="Push":
- own['wheels'].append(child)
- prop1.append(w)
- w+=1
- if prop1[0]=="Tracker":
- own['Tracker']=child
- child['owner']=own
- if child.parent==own or 'Phys' in child and 'Seat_Check' not in child:
- child.setParent(own,1 ,0)
- elif 'Seat_Check' not in child:
- child.suspendPhysics()
- own['init']=True
- if 'Rider' in own and 'VehicleCheck' in own['Act']:
- own['Rider'][0].worldPosition = own.worldTransform @ own['Rider'][1]
- own['Rider'][0].worldOrientation = own.worldOrientation @ own['Rider'][2]
- own['Rider'][0].applyRotation((0,0,math.pi),1)
- del own['Rider'][0]['ActStrip'][0]
- own['Rider'][0]['Jump']=15
- own.scene.objects['Controller']['Target']=own['Rider'][0].name
- if 'GFX' in own:
- for gfx in own['GFX']:
- gfx[0].endObject()
- own['Rider'][0].removeParent()
- del own['Rider']
- i=0
- if own['Impacted']==1:
- if 'suspended' in own:
- del own['suspended']
- own.restoreDynamics()
- if own['Health']>=1 and cont.sensors['Property'].positive:
- if 'Impact' in own:
- pos = own.worldTransform @ own['Impact'][0]
- own.applyImpulse(pos,own['Impact'][2]*(own['Impact'][1]*.05))
- for part in own['Parts']:
- function = Functions[part[0]]
- data = part[1:]
- data.append(i)
- ret = function(data)
- i+=1
- #print(part[0])
- #print(data)
- #own['Helper'].worldPosition = own.worldPosition + (own.worldLinearVelocity*1.5)
- if 'Target' in own:
- if type(own['Target'][1]) is not str:
- if own['Target'][1]>=1:
- own['Target'][1]-=1
- if 'Player' not in own:
- own['X']*=.95
- own['Y']*=.95
- else:
- own['Target']="None"
- elif own['Health']<1:
- if 'Team' in own:
- del own['Team']
- if 'Impact' in own:
- pos = own.worldTransform @ own['Impact'][0]
- own.applyImpulse(pos,own['Impact'][2]*(own['Impact'][1]*.05))
- for child in own.children:
- if child.getDistanceTo(pos)<own['Impact'][1]:
- if 'rag_part' in child:
- added = own.scene.addObject(child['rag_part'],child,0)
- if 'rag_rot' in child:
- rot = ast.literal_eval(child['rag_rot'])
- added.applyRotation(rot,1)
- added.applyImpulse(pos,-(pos-added.worldPosition).normalized()*(own['Impact'][1]*.5) )
- for child2 in child.children:
- if 'rag_part' in child2:
- added = own.scene.addObject(child2['rag_part'],child2,0)
- added.applyImpulse(pos,-(pos-added.worldPosition).normalized()*(own['Impact'][1]*.5) )
- child2.removeParent()
- child2.endObject()
- child.removeParent()
- child.endObject()
- del own['Impact']
- own ['Impacted']=0
- own['Fire']=0
- for child in own.childrenRecursive:
- child.color = [0,0,0,1]
- if own['On']==True:
- own['On']=False
- own.restoreDynamics()
- for wheel in own['wheels']:
- pos = wheel.worldPosition
- wheel.removeParent()
- wheel.worldPosition =pos
- wheel.setParent(own,1,0)
- if 'Controller' in own:
- if 'Right' in own['Move'] and own['Steer']>=-1:
- if own['Steer']>0:
- own['Steer']*=.9
- own['Steer']-=.0125
- elif 'Left' in own['Move'] and own['Steer']<=1:
- if own['Steer']<0:
- own['Steer']*=.9
- own['Steer']+=.0125
- else:
- own['Steer']*=.5
- if 'Forward' in own['Move'] and own['Speed']<=1.8:
- own['Speed']+=.1
- elif 'Back' in own['Move'] and own['Speed']>=-1.8:
- own['Speed']-=.1
- else:
- own['Speed']*=.5
- if abs(own['Speed'])<.01:
- own['Speed']=0
- if 'Punch' in own['Act'] and own['Fire']==0 and 'owner' not in own:
- own['Fire']=1
- elif 'Reload' in own['Act'] and own['Fire']==0 and 'owner' not in own:
- own['Fire']=own['Reload']
- print('reload')
- if own.getDistanceTo(own.scene.objects['Cube'])>=10.5 and 'suspended' not in own:
- own.suspendDynamics()
- own['suspended']=True
- #print('ran')
- elif own.getDistanceTo(own.scene.objects['Cube'])<10.25 and 'suspended' in own:
- own.restoreDynamics()
- del own['suspended']
- #print('rem')
- own['Move']=[]
- own['Act']=[]
- own['hit']=[]
- main()
Advertisement
Add Comment
Please, Sign In to add comment