home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / stone.py < prev    next >
Encoding:
Python Source  |  2000-10-27  |  7.6 KB  |  258 lines

  1. ##########################################################
  2. #
  3. #    SCRIPT    : libreria para lanzar cosas
  4. #
  5. #    AUTH    : Yuio
  6. #
  7. #
  8. ##########################################################
  9.  
  10. import math
  11. import Bladex
  12. import Sounds
  13. import GameStateAux
  14. import ObjStore
  15.  
  16. # sonidos de las bolas
  17. stoneDrop = "..\\..\\Sounds\\golpe-bola-piedra.wav"    # sonido de inicio
  18. stoneLoop = "..\\..\\Sounds\\piedra-rodando-1.wav"    # loop
  19.  
  20. stoneDSound=Sounds.CreateEntitySound(stoneDrop, "stoneSound")
  21. stoneDSound.Volume=1.0
  22. stoneDSound.MinDistance=10000
  23. stoneDSound.MaxDistance=90000
  24.  
  25. MESSAGE_START_WEAPON=7                                
  26. MESSAGE_STOP_WEAPON=8
  27.  
  28. SQR_DELTA_HIT_VARIATION = 10000000
  29.  
  30. class DataStone:
  31.  
  32.     ObjId=""
  33.     stoneDictionary=None
  34.     stoneDictionaryB=None
  35.     stoneDictionaryC=None
  36.     stoneDictionaryD=None
  37.     Entidad = None
  38.     LastDelta = 0,0,0
  39.  
  40.  
  41.     def __init__(self,entName,A,B,C,D):
  42.         self.ObjId=ObjStore.GetNewId() # Para identificarlo al grabar/guardar
  43.         self.stoneDictionary=A
  44.         self.stoneDictionaryB=B
  45.         self.stoneDictionaryC=C
  46.         self.stoneDictionaryD=D
  47.         self.Entidad = entName
  48.         ObjStore.ObjectsStore[self.ObjId]=self
  49.         self.LastDelta = 0,0,0
  50.  
  51.     def __del__(self):
  52.         del ObjStore.ObjectsStore[self.ObjId]
  53.  
  54.     def persistent_id(self):
  55.         return self.ObjId
  56.  
  57.     def __getstate__(self):
  58.         # Tiene que devolver como poder guardar el estado de la clase
  59.  
  60.         return (1,
  61.                 self.ObjId,
  62.                 self.stoneDictionary,                
  63.                 self.stoneDictionaryB,                
  64.                 GameStateAux.SaveEntityAux(self.stoneDictionaryC),
  65.                 GameStateAux.SaveEntityAux(self.stoneDictionaryD),
  66.                 self.Entidad,
  67.                 GameStateAux.SaveNewMembers(self)
  68.                 )
  69.  
  70.     def __setstate__(self,parm):
  71.         # Toma como parßmetro lo que devuelve __getstate__() y debe recrear la clase
  72.         if parm[0]==1:
  73.             #self.ObjId=parm[1] En GameStateAux.PersistentObject()
  74. ##            GameStateAux.PersistentObject.__setstate__(self,parm)
  75.             self.ObjId=parm[1]
  76.             ObjStore.ObjectsStore[self.ObjId]=self
  77.             self.stoneDictionary  = parm[2]
  78.             self.stoneDictionaryB = parm[3]
  79.             self.stoneDictionaryC = GameStateAux.LoadEntityAux(parm[4])
  80.             self.stoneDictionaryD = GameStateAux.LoadEntityAux(parm[5])
  81.             self.Entidad = GameStateAux.LoadEntityAux(parm[6])
  82.             self.Entidad.Data = self
  83.             self.Entidad = parm[6]
  84.             GameStateAux.LoadNewMembers(self,parm[7])
  85.             self.LastDelta = 0,0,0
  86.  
  87. #            GameStateAux.LoadedPickledData[self.ObjId]=self
  88.         else:
  89.             # Valores de creaci≤n por si valen para algo.
  90.             self.stoneDictionary  = 0,0,0,0,0,0,0,0,0
  91.             self.stoneDictionaryB = 0,0,0
  92.             self.stoneDictionaryC = None
  93.             self.stoneDictionaryD = None
  94.             self.Entidad = None
  95.             self.ObjId=ObjStore.GetNewId()
  96.             ObjStore.ObjectsStore[self.ObjId]=self
  97.             self.LastDelta = 0,0,0
  98.  
  99.  
  100. Bladex.CreateTimer("stoneLibTimer",0.1)
  101. B_PARTICLE_GTYPE_BLEND=1
  102. Bladex.AddParticleGType("DesertDustB","SmokeParticle",B_PARTICLE_GTYPE_BLEND,32)
  103. for i in range(32):
  104.     r=200
  105.     g=170
  106.     b=140
  107.     a=i + 50.0
  108.     size= (i/32.0)*1000.0
  109.     Bladex.SetParticleGVal("DesertDustB",i,r,g,b,a,size)
  110.  
  111. Bladex.AddParticleGType("DesertDarkDustB","SmokeParticle",B_PARTICLE_GTYPE_BLEND,32)
  112. for i in range(32):
  113.     r=85
  114.     g=55
  115.     b=35
  116.     a=i + 125.0
  117.     size= (i/32.0)*1500.0
  118.     Bladex.SetParticleGVal("DesertDarkDustB",i,r,g,b,a,size)
  119.  
  120.  
  121. DROPNULL = 0
  122. DROPBROWNDUST = 1
  123. DROPDARKDUST = 2
  124.  
  125. SOUNDNULL = 0
  126. STONESOUND = 1
  127.  
  128. def cuadradox(x):
  129.     return x*x
  130.  
  131. def stoneHandler(ent,time) :
  132.     sto = Bladex.GetEntity(ent)
  133.     stoneData = sto.Data
  134.     params = stoneData.stoneDictionary
  135.     pos = sto.Position
  136.     cpos = (pos[0]+params[1], pos[1]+params[2], pos[2]+params[3] )
  137.     ppos = stoneData.stoneDictionaryB
  138.     stoneData.stoneDictionaryB = cpos
  139.     dx = ppos[0]-cpos[0]
  140.     dy = ppos[1]-cpos[1]
  141.     dz = ppos[2]-cpos[2]
  142.     size = math.sqrt(dx*dx + dy*dy + dz*dz)    
  143.     eval = size * stoneData.stoneDictionary[5]
  144.     deltaVariation = cuadradox(dx-stoneData.LastDelta[0])+cuadradox(dx-stoneData.LastDelta[1])+cuadradox(dx-stoneData.LastDelta[2])
  145.     
  146.     if SQR_DELTA_HIT_VARIATION < deltaVariation:
  147.         stoneDSound.Position = pos
  148.         if not stoneDSound.Playing:        
  149.             stoneDSound.PlaySound(0)
  150.  
  151.     
  152.     #print ent,": delta(",dx,",",dy,",",dy,",",dz," eval:", eval
  153.  
  154.     dtype = stoneData.stoneDictionary[0]
  155.     if (dtype<>DROPNULL and stoneData.stoneDictionaryC) :
  156.         if (dtype==DROPBROWNDUST) :
  157.             dust  = stoneData.stoneDictionaryC
  158.             dust.Position = cpos
  159.             dust.D1 = dx, dy, dz
  160.             dust.PPS = eval
  161.         elif (dtype==DROPDARKDUST):
  162.             dust  = stoneData.stoneDictionaryC
  163.             dust.Position = cpos
  164.             dust.D1 = dx, dy, dz
  165.             dust.PPS = eval * 0.85
  166.     
  167.     stype = params[6]
  168.     if (stype<>SOUNDNULL and stoneData.stoneDictionaryD) : 
  169.         if    (stype==STONESOUND) :
  170.             sound = stoneData.stoneDictionaryD
  171.             soundvolume = eval * 0.025 * params[7]
  172.             sound.Position = cpos
  173.             if (soundvolume>1.0): soundvolume=1.0
  174.             sound.Volume = 1
  175.             if not sound.Playing:        
  176.                 sound.PlaySound(0)
  177.             #print soundvolume
  178.     
  179.     stoneData.LastDelta = dx,dy,dz
  180.  
  181. def lock(entName, trail, offsetX, offsetY, offsetZ, trailParam, autodest, sound, soundParam ) :
  182.     ent = Bladex.GetEntity(entName)
  183.     stoneDictionary= trail, offsetX, offsetY, offsetZ, autodest, trailParam, sound, soundParam
  184.     stoneDictionaryB = ( ent.Position[0]+offsetX, ent.Position[1]+offsetY, ent.Position[2]+offsetZ )
  185.     stoneDictionaryC = 0
  186.     stoneDictionaryD = 0
  187.  
  188.     if (trail<>DROPNULL) : 
  189.         if    (trail==DROPBROWNDUST):
  190.             stoneDust=Bladex.CreateEntity("ps"+entName, "Entity Particle System D2", ent.Position[0], ent.Position[1], ent.Position[2] )
  191.             stoneDust.D1= 0,0,0
  192.             stoneDust.ParticleType="DesertDustB"
  193.             stoneDust.YGravity=-1030.0
  194.             stoneDust.Friction=0.3
  195.             stoneDust.PPS=0
  196.             stoneDust.DeathTime=Bladex.GetTime()+999999.0
  197.             stoneDust.Time2Live=31
  198.             stoneDust.Velocity=0.0, 4000.0, 0.0
  199.             stoneDust.RandomVelocity=110.0
  200.             stoneDictionaryC = stoneDust
  201.         elif (trail==DROPDARKDUST):
  202.             stoneDust=Bladex.CreateEntity("ps"+entName, "Entity Particle System D2", ent.Position[0], ent.Position[1], ent.Position[2] )
  203.             stoneDust.D1= 0,0,0
  204.             stoneDust.ParticleType="DesertDarkDustB"
  205.             stoneDust.YGravity=-1030.0
  206.             stoneDust.Friction=0.3
  207.             stoneDust.PPS=0
  208.             stoneDust.DeathTime=Bladex.GetTime()+999999.0
  209.             stoneDust.Time2Live=31
  210.             stoneDust.Velocity=0.0, 4000.0, 0.0
  211.             stoneDust.RandomVelocity=110.0
  212.             stoneDictionaryC = stoneDust
  213.  
  214.     if (sound<>SOUNDNULL) : 
  215.         if    (sound==STONESOUND) :
  216.             stonelSound=Sounds.CreateEntitySound(stoneLoop, "stoneSound")
  217.             stonelSound.Volume=1
  218.             stonelSound.MinDistance=7000
  219.             stonelSound.MaxDistance=70000
  220.             stoneDictionaryD = stonelSound
  221.     
  222.     ent.Data = DataStone(entName,stoneDictionary,stoneDictionaryB,stoneDictionaryC,stoneDictionaryD)
  223.  
  224.  
  225. def unlock(entName):
  226.     #print"entName",l
  227.     ent = Bladex.GetEntity(entName)
  228.     ent.TimerFunc = ""
  229.     ent.RemoveFromList("stoneLibTimer")
  230.     stoneData = ent.Data
  231.  
  232.     if (stoneData.stoneDictionary[0]<>DROPNULL and stoneData.stoneDictionaryC):
  233.         stoneData.stoneDictionaryC.DeathTime=Bladex.GetTime()        
  234.  
  235.     if (stoneData.stoneDictionary[6]<>SOUNDNULL and stoneData.stoneDictionaryD):
  236.         stoneData.stoneDictionaryD.StopSound()
  237.     
  238.     del stoneData
  239.     #print("delete")
  240.  
  241. def drop(entName,impulseX, impulseY, impulseZ):
  242.     ent = Bladex.GetEntity(entName)
  243.     ent.Impulse(impulseX, impulseY, impulseZ)
  244.     ent.TimerFunc = stoneHandler
  245.     ent.SubscribeToList("stoneLibTimer")
  246.     ent.MessageEvent(MESSAGE_START_WEAPON,0,0)    
  247.     autodest = ent.Data.stoneDictionary[4]
  248.     if (autodest>0.0) :
  249.         import stone
  250.         Bladex.AddScheduledFunc( Bladex.GetTime()+ent.Data.stoneDictionary[4], stone.unlock, (entName,) )
  251.  
  252.     if (ent.Data.stoneDictionary[6]<>SOUNDNULL and ent.Data.stoneDictionaryD):
  253.         snd = ent.Data.stoneDictionaryD
  254.         #snd.PlaySound(-1)
  255.  
  256.         stoneDSound.Position = ent.Position
  257.         stoneDSound.PlaySound(0)
  258.