home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / ConcenEf.py < prev    next >
Encoding:
Text File  |  2000-10-27  |  6.6 KB  |  218 lines

  1. #
  2. # ----------------------------------------
  3. #  C O N C E N T R A T I O N   E F F E C T
  4. # ----------------------------------------
  5. #
  6. # For launching a concentration effect :
  7. #    1st) Create it . Ex:
  8. #        c_ef=CONCEN_EF()
  9. #    2nd) When you want to launch it :
  10. #        c_ef.StartConcentrationEffect(Bladex.GetEntity("Player1").Position,"Player1","R_Hand","Aparicion_espada",0.5)
  11. #    
  12. #    PARAMETERS of the StartConcentrationEffect function :
  13. #        1- Position in which it will be located
  14. #        2- Name of the entity to be linked with (if the entity moves , the effect will move with it)
  15. #            None if not linked to any entity (it will be in the pos of the first parameter for the whole effect)
  16. #        3- (applies only if par2 was given)
  17. #            Name of the areaof the entity (the 2nd parameter) where the effect will be link
  18. #            Useful to link effects to the hands of a given character , of the eyes , etc ...
  19. #        4- Name of the sound that will be played during the effect
  20. #        5- % of the size of the effect (related to the textures used ...)
  21. #
  22. #        (from now on , the rest of the parameter have got default values)
  23. #
  24. #
  25. #        6- Time that the effect will last (NO perfectly accurate , but will be fix if needed)
  26. #        7- Name of the texture1 name  used
  27. #        8,9,10 - r,g,b components that will be applied to texture1
  28. #        11,12,13,14,15 - As 7-10 , but for texture2
  29. #        16,17,18 - Rgb values of the particles of the particle system
  30. #
  31. #
  32. #
  33. #    If more parameters arte needed , or if you have any questions , ask Jose .
  34. #
  35. #
  36. #
  37.  
  38. import Bladex
  39.  
  40. B_PARTICLE_GTYPE_COPY=0
  41. B_PARTICLE_GTYPE_BLEND=1
  42. B_PARTICLE_GTYPE_ADD=2
  43. B_PARTICLE_GTYPE_MUL=3
  44.  
  45.  
  46. Bladex.ReadBitMap("..\\..\\Data\\Prueba Flare Magico 256.bmp","Flare Magico 256")
  47. Bladex.ReadBitMap("..\\..\\Data\\Prueba Flare Magico 128.bmp","Flare Magico 128")
  48.  
  49. Bladex.ReadAlphaBitMap("..\\..\\Data\\GenericPrtl.bmp","GenericParticle")
  50. Bladex.AddParticleGType("Concentrado","GenericParticle",B_PARTICLE_GTYPE_BLEND,600)
  51.  
  52.  
  53.  
  54. class CONCEN_EF:
  55.     luzA=0
  56.     luzB=0
  57.     parts=0
  58.     size_factor=1.0
  59.     main_ent_name=""
  60.     entity_name_link=""
  61.     ent_area=""
  62.     sonido_aparicion=0
  63.  
  64.     def SetPos(self,pos):
  65.         self.luzA.Position=pos
  66.         self.luzB.Position=pos    
  67.         self.parts.Position=pos
  68.  
  69.     def PosMe(self,ent_name):
  70.         me=Bladex.GetEntity(ent_name)
  71.         if self.entity_name_link:
  72.             ent=Bladex.GetEntity(self.entity_name_link)
  73.             if self.ent_area<>"":
  74.                 me.Position=ent.GraspPos(self.ent_area)
  75.             else:
  76.                 me.Position=ent.Position
  77.  
  78.  
  79.     def RelocateMe(self,ent_name, time):
  80.         self.PosMe(ent_name)
  81.         
  82.  
  83.     def GrowMe(self,ent_name, time):
  84.         luz=Bladex.GetEntity(ent_name)
  85.         luz.SizeFactor=luz.SizeFactor+0.2*self.size_factor    
  86.         if luz.SizeFactor>15.0*self.size_factor:
  87.             luz.TimerFunc=""
  88.             luz.RemoveFromList("Timer60")
  89.             #luz.TimerFunc=self.StrinkMe
  90.             #self.parts.DeathTime=Bladex.GetTime()+0.0
  91.  
  92.         if ent_name==self.main_ent_name:
  93.             if luz.SizeFactor<10*self.size_factor:
  94.                 luz.Intensity=3.0-(10.0*self.size_factor-luz.SizeFactor)*3.0/(10.0*self.size_factor)
  95.             else:
  96.                 luz.Intensity=3
  97.             #print "SizeF is " + `luz.SizeFactor` + " Intensity is  " + ` luz.Intensity ` 
  98.  
  99.         self.PosMe(ent_name)
  100.  
  101.         
  102.     def StrinkMe(self,ent_name, time):
  103.         luz=Bladex.GetEntity(ent_name)
  104.         if luz.SizeFactor>10*self.size_factor:
  105.             luz.SizeFactor=luz.SizeFactor-0.1*self.size_factor
  106.         else:
  107.             if luz.SizeFactor>5*self.size_factor:
  108.                 luz.SizeFactor=luz.SizeFactor-0.2*self.size_factor
  109.             else:
  110.                 luz.SizeFactor=luz.SizeFactor-0.4*self.size_factor
  111.         
  112.         if luz.SizeFactor<0.1*self.size_factor:
  113.             luz.RemoveFromList("Timer60")
  114.             luz.SubscribeToList("Pin")
  115.  
  116.         if ent_name==self.main_ent_name:
  117.             if luz.SizeFactor<5*self.size_factor:
  118.                 luz.Intensity=(5*self.size_factor-luz.SizeFactor)*2.0+3.0
  119.             #print "SizeF is " + `luz.SizeFactor` + " Intensity is  " + ` luz.Intensity ` 
  120.  
  121.         self.PosMe(ent_name)
  122.  
  123.  
  124.     def EndConcentrationEffect(self):
  125.         self.luzA.TimerFunc=self.StrinkMe
  126.         self.luzA.SubscribeToList("Timer60")
  127.         self.luzB.TimerFunc=self.StrinkMe
  128.         self.luzB.SubscribeToList("Timer60")    
  129.         
  130.         self.parts.DeathTime=Bladex.GetTime()+0.0
  131.  
  132.     def StartConcentrationEffect(self,pos,ent2follow,ent_bit,sound_name,s_factor,time=2,
  133.                                 text1_name="Flare Magico 256",text1_r=255,text1_g=255,text1_b=255,
  134.                                 text2_name="Flare Magico 128",text2_r=128,text2_g=128,text2_b=255,
  135.                                 part_r=128,part_g=128,part_b=200):
  136.  
  137.         self.size_factor=s_factor
  138.  
  139.         self.main_ent_name=Bladex.GenerateEntityName()
  140.         self.luzA=Bladex.CreateEntity(self.main_ent_name,"Entity Spot",0,0,0)        
  141.         self.luzA.Color=text1_r,text1_g,text1_b
  142.         self.luzA.Intensity=0
  143.         self.luzA.Precission=0.1
  144.         self.luzA.CastShadows=0    
  145.         self.luzA.GlowTexture=text1_name
  146.         self.luzA.GlowTestZ=0
  147.         self.luzA.AngVel=1.59
  148.         self.luzA.SizeFactor=0.05*self.size_factor
  149.  
  150.         self.luzB=Bladex.CreateEntity(Bladex.GenerateEntityName(),"Entity Spot",0,0,0)
  151.         self.luzB.Color=text2_r,text2_g,text2_b
  152.         self.luzB.Intensity=0.1
  153.         self.luzB.Precission=0.1
  154.         self.luzB.CastShadows=0
  155.         self.luzB.GlowTexture=text2_name
  156.         self.luzB.GlowTestZ=0
  157.         self.luzB.AngVel=-3.14
  158.         self.luzB.SizeFactor=0.05*self.size_factor
  159.  
  160.         self.luzA.TimerFunc=self.GrowMe
  161.         self.luzA.SubscribeToList("Timer60")
  162.         self.luzB.TimerFunc=self.GrowMe
  163.         self.luzB.SubscribeToList("Timer60")    
  164.  
  165.         self.parts=Bladex.CreateEntity("Parts", "Entity Particle System D1", 0.0, 0.0, 0.0)
  166.         self.parts.ParticleType="Concentrado"
  167.         self.parts.Time2Live=25 #*self.size_factor
  168.         self.parts.YGravity=0
  169.         self.parts.Friction=0
  170.         self.parts.RandomVelocity=-50.0*self.size_factor
  171.         #-100.0*self.size_factor
  172.         self.parts.RandomVelocity_V=0.0
  173.         self.parts.PPS=512
  174.  
  175.         self.parts.TimerFunc=self.RelocateMe
  176.         self.parts.SubscribeToList("Timer60")    
  177.         
  178.         for i in range(600):
  179.             a=255
  180.             size=33*self.size_factor
  181.             if size<20:
  182.                 size=20
  183.             Bladex.SetParticleGVal("Concentrado",i,part_r,part_g,part_b,a,size)
  184.  
  185.         self.SetPos(pos)
  186.  
  187.         if ent2follow and ent2follow<>"":
  188.             self.entity_name_link=ent2follow
  189.             if ent_bit and ent_bit<>"":
  190.                 self.ent_area=ent_bit
  191.             else:
  192.                 self.ent_area=""
  193.         else:
  194.             self.entity_name_link=""
  195.             self.ent_area=""
  196.  
  197.  
  198.         file_name="..\\..\\Sounds\\"+ sound_name +".wav"
  199.         self.sonido_aparicion=Bladex.CreateSound(file_name,"Aparicion")
  200.         self.sonido_aparicion.MaxDistance=20000.0
  201.         self.sonido_aparicion.Play(pos[0], pos[1], pos[2], 0)
  202.  
  203.  
  204.         Bladex.AddScheduledFunc(Bladex.GetTime()+time, self.EndConcentrationEffect,   ())
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213. c_ef=CONCEN_EF()
  214. c_ef2=CONCEN_EF()
  215.  
  216. def LanzaC():
  217.     c_ef.StartConcentrationEffect(Bladex.GetEntity("Player1").Position,"Player1","R_Hand","Aparicion_espada",0.5)
  218.     c_ef2.StartConcentrationEffect(Bladex.GetEntity("Player1").Position,"Player1","Shield","Aparicion_espada",0.5)