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

  1. import Bladex
  2. import AuxFuncs
  3. import whrandom
  4. import Reference
  5. import math
  6.  
  7. #########################################################
  8. ###############  EFECTO DE CONCENTRACION  ###############
  9. #########################################################
  10. MaximunAlpha = 0.15
  11.  
  12. def ConcentraTimer(e_name, time):
  13.     global MaximunAlpha
  14.     o = Bladex.GetEntity(e_name)
  15.     o.Data.Counter = o.Data.Counter + 1
  16.     
  17.     o.Scale = o.Data.Scale*(o.Data.Frames - o.Data.Counter)/o.Data.Frames + 1.0
  18.     
  19.     if o.Data.Counter > o.Data.Decon:
  20.         o.Alpha = MaximunAlpha-(MaximunAlpha*(o.Data.Counter-o.Data.Decon))/(o.Data.Frames-o.Data.Decon)
  21.     else:
  22.         o.Alpha = MaximunAlpha*o.Data.Counter/o.Data.Frames
  23.     
  24.     o.Rotate(o.Data.x, o.Data.y, o.Data.z, o.Data.delta)
  25.     if o.Data.Counter+1 > o.Data.Frames :
  26.         o.RemoveFromList("Timer30")
  27.         o.SubscribeToList("Pin")
  28.  
  29. def EfectoConcentracion(pos,name,frames=150,Scale = 30.0,RotSpeed = 32.0,Decon=100):
  30.     global ActualColor
  31.     class vacio:
  32.         pass
  33.     
  34.     if ActualColor == GREEN_GEM:
  35.         o=Bladex.CreateEntity(name,"EsferaGemaVerde", 0,0 ,0)
  36.     if ActualColor == RED_GEM:
  37.         o=Bladex.CreateEntity(name,"EsferaGemaRoja",  0,0 ,0)
  38.     if ActualColor == BLUE_GEM:
  39.         o=Bladex.CreateEntity(name,"EsferaGemaAzul",  0, 0,0)
  40.     
  41.     o.Static      = 1
  42.     o.Orientation = 0.707107,0.707107,0.000000,0.000000
  43.     o.Position    = pos
  44.     o.SelfIlum    = 1
  45.     o.CastShadows = 0
  46.     o.RasterMode  ="AdditiveAlpha"
  47.     o.RasterMode  ="Read"
  48.     o.Alpha       = 0.0
  49.     o.Scale       = 6.0
  50.     o.TimerFunc   = ConcentraTimer
  51.     o.SubscribeToList("Timer30")
  52.     o.Data        = vacio()
  53.     x             = whrandom.random()
  54.     y             = whrandom.random()
  55.     z             = whrandom.random()
  56.     tot           = x*x + y*y + z*z
  57.     x             = math.sqrt(x*x/tot)
  58.     y             = math.sqrt(y*y/tot)
  59.     z             = math.sqrt(z*z/tot)
  60.  
  61.     if whrandom.random() >0.5:
  62.         o.Data.x      = +x
  63.     else:
  64.         o.Data.x      = -x
  65.  
  66.     if whrandom.random() >0.5:
  67.         o.Data.y      = +y
  68.     else:
  69.         o.Data.y      = -y
  70.  
  71.     if whrandom.random() >0.5:
  72.         o.Data.z      = +z
  73.     else:
  74.         o.Data.z      = -z
  75.         
  76.     o.Data.delta   = (whrandom.random()+0.5)/RotSpeed
  77.     o.Data.Counter = 0
  78.     o.Data.Frames  = frames
  79.     o.Data.Scale   = Scale    
  80.     o.Data.Decon   = Decon
  81.     
  82.     
  83.     #print o.Data.x,o.Data.y,o.Data.z,o.Data.delta    
  84.     return o
  85.     
  86.  
  87.  
  88. Bladex.AddParticleGType("GemaConc","SmokeParticle",Reference.B_PARTICLE_GTYPE_ADD,64)
  89.  
  90. for i in range(64):
  91.     aux = 1.0-i/64.0
  92.     r=10
  93.     g=205
  94.     b=150
  95.     a=aux*128.0
  96.     size=aux*128+64
  97.     Bladex.SetParticleGVal("GemaConc",i,r,g,b,a,size)
  98.     
  99. Bladex.AddParticleGType("Particulate","Estrellita",1,32)
  100.  
  101. for i in range(32):
  102.     
  103.     a = i*4
  104.     
  105.     r=128.0
  106.     g=255.0
  107.     b=128.0
  108.     size= (i%8)*6
  109.     Bladex.SetParticleGVal("Particulate",i,r,g,b,a,size)
  110.  
  111.  
  112. def PiecesOfGema(pos):
  113.     RayoHit=Bladex.CreateEntity("RayoBastonHit", "Entity Particle System D1", pos[0],pos[1],pos[2])
  114.     RayoHit.Time2Live=32
  115.     RayoHit.YGravity=20000
  116.     RayoHit.ParticleType="Particulate"
  117.     RayoHit.Friction=0.95
  118.     RayoHit.Velocity=0,0,0
  119.     RayoHit.RandomVelocity=-5
  120.     RayoHit.DeathTime     = Bladex.GetTime()+1.0
  121.  
  122. GREEN_GEM = 0
  123. RED_GEM   = 1
  124. BLUE_GEM  = 2
  125.  
  126. ActualColor = GREEN_GEM
  127.  
  128. def SetGemColor(color):
  129.     global ActualColor
  130.     ActualColor = color
  131.         
  132.     if ActualColor==GREEN_GEM:
  133.         r = 10 
  134.         g = 205
  135.         b = 150
  136.     if ActualColor==RED_GEM:
  137.         r = 205
  138.         g = 150
  139.         b = 10 
  140.     if ActualColor==BLUE_GEM:
  141.         r = 10
  142.         g = 100
  143.         b = 205
  144.     
  145.     for i in range(64):
  146.         aux = 1.0-i/64.0
  147.         a=aux*128.0
  148.         size=aux*128+64
  149.         Bladex.SetParticleGVal("GemaConc",i,r,g,b,a,size)
  150.  
  151.  
  152.     #########################################################
  153.     if ActualColor==GREEN_GEM:
  154.         r = 128.0
  155.         g = 255.0
  156.         b = 128.0
  157.     if ActualColor==RED_GEM:
  158.         r = 255.0
  159.         g = 128.0
  160.         b = 128.0
  161.     if ActualColor==BLUE_GEM:
  162.         r = 128.0
  163.         g = 128.0
  164.         b = 255.0
  165.     
  166.     for i in range(32):        
  167.         a = i*4        
  168.         size= (i%8)*6
  169.         Bladex.SetParticleGVal("Particulate",i,r,g,b,a,size)    
  170.  
  171. def ConcentratorParticulate(pos,delta=(0,0,0)):
  172.  
  173.     RayoHit=Bladex.CreateEntity("RayoBastonHit", "Entity Particle System D1", pos[0],pos[1],pos[2])
  174.     RayoHit.ParticleType="GemaConc"
  175.     RayoHit.Time2Live=64
  176.     RayoHit.YGravity=0.0
  177.     RayoHit.Friction=0
  178.     RayoHit.PPS=255
  179.     RayoHit.Velocity=delta
  180.     RayoHit.RandomVelocity=-10
  181.     RayoHit.DeathTime     = Bladex.GetTime()+4.0
  182.  
  183. GemCallBack = None
  184. GemParams   = ()
  185.  
  186. def FlashGem():    
  187.     if ActualColor==GREEN_GEM:
  188.         AuxFuncs.FadeFrom(0.15,0.0,128,255,128)
  189.     if ActualColor==RED_GEM:
  190.         AuxFuncs.FadeFrom(0.15,0.0,255,128,128)
  191.     if ActualColor==BLUE_GEM:
  192.         AuxFuncs.FadeFrom(0.15,0.0,128,128,255)
  193.  
  194.     if GemCallBack != None:
  195.         apply(GemCallBack,GemParams)
  196.  
  197. def FaderUp():
  198.     global ABC_POS
  199.     
  200.     _SndConcentGem.Volume = _SndConcentGem.Volume+1.0/60.0
  201.     if _SndConcentGem.Volume >= 0.95:
  202.         _SndConcentGem.Stop()
  203.         _SndConcentGemHit.Play(ABC_POS[0],ABC_POS[1],ABC_POS[2],0)
  204.     else:
  205.         Bladex.AddScheduledFunc(Bladex.GetTime() + 0.1,  FaderUp,())
  206.  
  207. def Concentrator(pos,delta=(0,0,0)):
  208.     global ABC_POS
  209.     
  210.     _SndConcentGem.Play(pos[0],pos[1],pos[2],-1)
  211.     _SndConcentGem.Volume = 0
  212.     ABC_POS = pos
  213.     FaderUp()
  214.     
  215.     
  216.     Bladex.AddScheduledFunc(Bladex.GetTime() + 0.5,  EfectoConcentracion,(pos,"C1gema1a",))
  217.     Bladex.AddScheduledFunc(Bladex.GetTime() + 1.0,  EfectoConcentracion,(pos,"C2gema1a",))
  218.     Bladex.AddScheduledFunc(Bladex.GetTime() + 1.5,  EfectoConcentracion,(pos,"C3gema1a",))
  219.     Bladex.AddScheduledFunc(Bladex.GetTime() + 5.95, PiecesOfGema,(pos,))
  220.     Bladex.AddScheduledFunc(Bladex.GetTime() + 6.0,  FlashGem,())
  221.     ConcentratorParticulate(pos,delta)
  222.     
  223.     
  224. _SndConcentGem=Bladex.CreateSound("..\\..\\Sounds\\energy-ball.wav","SndConcentGem")
  225. _SndConcentGem.MinDistance=10000.0
  226. _SndConcentGem.MaxDistance=100000.0
  227.  
  228. _SndConcentGemHit=Bladex.CreateSound("..\\..\\Sounds\\energy-ball-impact.wav","SndConcentGemHit")
  229. _SndConcentGemHit.MinDistance=10000.0
  230. _SndConcentGemHit.MaxDistance=100000.0
  231.  
  232.  
  233. o=Bladex.CreateEntity("e1","EsferaGemaVerde", 0,0 ,0)
  234. o.SubscribeToList("Pin")
  235. o=Bladex.CreateEntity("e2","EsferaGemaRoja",  0,0 ,0)
  236. o.SubscribeToList("Pin")
  237. o=Bladex.CreateEntity("e3","EsferaGemaAzul",  0, 0,0)
  238. o.SubscribeToList("Pin")
  239.