home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / Button.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-10-27  |  12.9 KB  |  353 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import Bladex
  5. import Actions
  6. import ObjStore
  7. import GameStateAux
  8.  
  9. class ButtonCombination:
  10.     ObjId = ''
  11.     activates = 0
  12.     corrects = 0
  13.     n_buttons = 0
  14.     correct_func = None
  15.     failed_func = None
  16.     order = 0
  17.     state = 0
  18.     combi = 0
  19.     first_button = 0
  20.     last_button = 0
  21.     Cycle = -1
  22.     
  23.     def __init__(self, correct_func, failed_func):
  24.         self.ObjId = ObjStore.GetNewId()
  25.         self.correct_func = correct_func
  26.         self.failed_func = failed_func
  27.         ObjStore.ObjectsStore[self.ObjId] = self
  28.  
  29.     
  30.     def AddButton(self, button_name, time, dir, dist, order, state, correct_state):
  31.         button = CreateButton(button_name, time, dir, dist, order, state, correct_state, self)
  32.         if self.first_button:
  33.             last_button = Bladex.GetEntity(self.last_button).Data
  34.             last_button.next_button = button_name
  35.         else:
  36.             self.first_button = button_name
  37.         self.last_button = button_name
  38.         return button
  39.  
  40.     
  41.     def Reset(self, type, entity = 'Player1'):
  42.         button = Bladex.GetEntity(self.first_button).Data
  43.         char = Bladex.GetEntity(entity)
  44.         for i in range(self.n_buttons):
  45.             button_e = Bladex.GetEntity(button.entity)
  46.             char.Data.obj_used = button_e
  47.             if self.state == 0:
  48.                 if type:
  49.                     ActivateButton(entity, 0)
  50.                 else:
  51.                     button.state = 0
  52.             elif type:
  53.                 if button.state != button.initial_state:
  54.                     ActivateButton(enmtity, 0)
  55.                 
  56.             elif button.state != button.initial_state:
  57.                 button.state = button.initial_state
  58.             
  59.             button = Bladex.GetEntity(button.next_button).Data
  60.         
  61.  
  62.     
  63.     def __setstate__(self, parm):
  64.         if parm[0] == 1:
  65.             self.ObjId = parm[1]
  66.             ObjStore.ObjectsStore[self.ObjId] = self
  67.             self.activates = parm[2]
  68.             self.corrects = parm[3]
  69.             self.n_buttons = parm[4]
  70.             GameStateAux.LoadFunctionAux(parm[5], self, 'correct_func')
  71.             GameStateAux.LoadFunctionAux(parm[6], self, 'failed_func')
  72.             self.order = parm[7]
  73.             self.state = parm[8]
  74.             self.combi = parm[9]
  75.             self.first_button = parm[10]
  76.             self.last_button = parm[11]
  77.             self.Cycle = parm[12]
  78.         else:
  79.             print 'ButtonCombination.__setstate__() -> Version mismatch'
  80.             self.ObjId = ObjStore.GetNewId()
  81.             ObjStore.ObjectsStore[self.ObjId] = self
  82.  
  83.     
  84.     def __getstate__(self):
  85.         return (1, self.ObjId, self.activates, self.corrects, self.n_buttons, GameStateAux.SaveFunctionAux(self.correct_func), GameStateAux.SaveFunctionAux(self.failed_func), self.order, self.state, self.combi, self.first_button, self.last_button, self.Cycle)
  86.  
  87.     
  88.     def persistent_id(self):
  89.         return self.ObjId
  90.  
  91.     
  92.     def __del__(self):
  93.         del ObjStore.ObjectsStore[self.ObjId]
  94.  
  95.  
  96.  
  97. def CreateButtonCombination(type = 0, correct_func = '', failed_func = ''):
  98.     combi = ButtonCombination(correct_func, failed_func)
  99.     if type == 1:
  100.         combi.order = 1
  101.     
  102.     if type == 2:
  103.         combi.state = 1
  104.     
  105.     return combi
  106.  
  107.  
  108. class BUTTON:
  109.     ObjId = ''
  110.     time = 0
  111.     last_time = 0
  112.     finish_time = 0
  113.     state = 0
  114.     correct_state = 1
  115.     v = [
  116.         0,
  117.         0,
  118.         0]
  119.     dir = [
  120.         0,
  121.         0,
  122.         0]
  123.     order = 0
  124.     position_i = [
  125.         0,
  126.         0,
  127.         0]
  128.     position_f = [
  129.         0,
  130.         0,
  131.         0]
  132.     entity = 0
  133.     sound = None
  134.     combi = None
  135.     
  136.     def __init__(self):
  137.         self.ObjId = ObjStore.GetNewId()
  138.         self.sound = Bladex.CreateSound('..\\..\\Sounds\\block-sliding.wav', 'Sound Button')
  139.         self.sound.Volume = 1.0
  140.         self.sound.MinDistance = 7000
  141.         self.sound.MaxDistance = 20000
  142.         self.next_button = 0
  143.         self.position_i = [
  144.             0,
  145.             0,
  146.             0]
  147.         self.position_f = [
  148.             0,
  149.             0,
  150.             0]
  151.         self.v = [
  152.             0,
  153.             0,
  154.             0]
  155.         self.dir = [
  156.             0,
  157.             0,
  158.             0]
  159.         self.combi = None
  160.         ObjStore.ObjectsStore[self.ObjId] = self
  161.  
  162.     
  163.     def __getstate__(self):
  164.         return (1, self.ObjId, self.last_time, self.finish_time, self.state, self.correct_state, self.v, self.dir, self.order, self.position_i, self.position_f, self.entity, self.sound.Name, self.next_button, self.combi, self.time)
  165.  
  166.     
  167.     def __setstate__(self, parm):
  168.         if parm[0] == 1:
  169.             self.ObjId = parm[1]
  170.             ObjStore.ObjectsStore[self.ObjId] = self
  171.             self.last_time = parm[2]
  172.             self.finish_time = parm[3]
  173.             self.state = parm[4]
  174.             self.correct_state = parm[5]
  175.             self.v = parm[6]
  176.             self.dir = parm[7]
  177.             self.order = parm[8]
  178.             self.position_i = parm[9]
  179.             self.position_f = parm[10]
  180.             self.entity = parm[11]
  181.             sound_Name = parm[12]
  182.             self.sound = Bladex.GetSound(sound_Name)
  183.             self.next_button = parm[13]
  184.             self.combi = parm[14]
  185.             self.time = parm[15]
  186.         else:
  187.             print 'Door.__setstate__() -> Version mismatch'
  188.             self.ObjId = ObjStore.GetNewId()
  189.             ObjStore.ObjectsStore[self.ObjId] = self
  190.             self.sound = Bladex.CreateSound('..\\..\\Sounds\\block-sliding.wav', 'Sound Button')
  191.             self.sound.Volume = 1.0
  192.             self.sound.MinDistance = 7000
  193.             self.sound.MaxDistance = 20000
  194.             self.next_button = 0
  195.             self.combi = None
  196.             self.time = 0
  197.  
  198.     
  199.     def persistent_id(self):
  200.         return self.ObjId
  201.  
  202.     
  203.     def __del__(self):
  204.         del ObjStore.ObjectsStore[self.ObjId]
  205.  
  206.  
  207.  
  208. def MoveButton(button_name, time):
  209.     button_e = Bladex.GetEntity(button_name)
  210.     button = button_e.Data
  211.     timer = Bladex.GetTime()
  212.     itime = timer - button.last_time
  213.     if timer < button.finish_time:
  214.         x = button_e.Position[0] + itime * button.v[0]
  215.         y = button_e.Position[1] + itime * button.v[1]
  216.         z = button_e.Position[2] + itime * button.v[2]
  217.         button_e.Position = (x, y, z)
  218.     elif button.state:
  219.         x = button.position_f[0]
  220.         y = button.position_f[1]
  221.         z = button.position_f[2]
  222.         button_e.Position = (x, y, z)
  223.     else:
  224.         button_e.Position = button.position_i
  225.     button_e.RemoveFromList('TimerButton')
  226.     button.sound.Stop()
  227.     button.last_time = timer
  228.  
  229.  
  230. def ActivateButton(entity, event):
  231.     Char = Bladex.GetEntity(entity)
  232.     button_e = Char.Data.obj_used
  233.     button = button_e.Data
  234.     combi = button.combi
  235.     Bladex.CreateTimer('TimerButton', 1.0 / 60.0)
  236.     button_e.SubscribeToList('TimerButton')
  237.     button.sound.Play(button_e.Position[0], button_e.Position[1], button_e.Position[2], combi.Cycle)
  238.     if button.state:
  239.         button.state = 0
  240.     else:
  241.         button.state = 1
  242.     button.v[0] = button.v[0] * -1
  243.     button.v[1] = button.v[1] * -1
  244.     button.v[2] = button.v[2] * -1
  245.     combi.activates = combi.activates + 1
  246.     print 'Buttons Activados ', combi.activates
  247.     if combi.order and button.order == combi.activates:
  248.         combi.corrects = combi.corrects + 1
  249.     elif combi.state:
  250.         if button.correct_state == button.state:
  251.             combi.corrects = combi.corrects + 1
  252.         else:
  253.             combi.corrects = combi.corrects - 1
  254.         combi.activates = combi.corrects
  255.     
  256.     if combi.activates == combi.n_buttons:
  257.         if combi.order or combi.state:
  258.             if combi.corrects == combi.n_buttons and combi.correct_func:
  259.                 apply(combi.correct_func, ())
  260.             elif combi.failed_func:
  261.                 apply(combi.failed_func, ())
  262.             
  263.         elif combi.correct_func:
  264.             apply(combi.correct_func, ())
  265.         
  266.     
  267.     time = Bladex.GetTime()
  268.     button.last_time = time
  269.     button.finish_time = time + button.time
  270.     Char.DelAnmEventFunc('Activate')
  271.     Char.Data.obj_used = None
  272.  
  273.  
  274. def UseButton(button_name, type):
  275.     button_e = Bladex.GetEntity(button_name)
  276.     button = button_e.Data
  277.     if button.state == 0 or button.combi.state:
  278.         Char = Bladex.GetEntity('Player1')
  279.         Actions.QuickTurnToFaceEntity('Player1', button_name)
  280.         Char.LaunchAnmType('pulsador')
  281.         Char.Data.obj_used = button_e
  282.         Char.AddAnmEventFunc('Activate', ActivateButton)
  283.     
  284.  
  285.  
  286. def Turn(name):
  287.     button_e = Bladex.GetEntity(name)
  288.     button = button_e.Data
  289.     if button.state == 0 or button.combi.state:
  290.         Char = Bladex.GetEntity('Player1')
  291.         Char.Data.obj_used = button_e
  292.         apply(ActivateButton, ('Player1', 'Activate'))
  293.     
  294.  
  295.  
  296. def HitFunc(stick, sticker, x, y, z, xc, yc, zc, wcx, wcy, wcz, wdx, wdy, wdz):
  297.     button_e = Bladex.GetEntity(stick)
  298.     button = button_e.Data
  299.     if button.state == 0 or button.combi.state:
  300.         Char = Bladex.GetEntity('Player1')
  301.         Char.Data.obj_used = button_e
  302.         apply(ActivateButton, ('Player1', 'Activate'))
  303.     
  304.  
  305.  
  306. def StickArrow(sticker, stick):
  307.     button_e = Bladex.GetEntity(stick)
  308.     button = button_e.Data
  309.     if button.state == 0 or button.combi.state:
  310.         Char = Bladex.GetEntity('Player1')
  311.         Char.Data.obj_used = button_e
  312.         apply(ActivateButton, ('Player1', 'Activate'))
  313.     
  314.  
  315.  
  316. def CreateButton(button_name, time, dir, dist, order, state, correct_state, combi):
  317.     button = BUTTON()
  318.     button_e = Bladex.GetEntity(button_name)
  319.     button_e.Static = 0
  320.     button_e.Data = button
  321.     button_e.UseFunc = UseButton
  322.     button_e.TimerFunc = MoveButton
  323.     button_e.StickFunc = StickArrow
  324.     button_e.HitFunc = HitFunc
  325.     button.entity = button_name
  326.     button.position_i = button_e.Position
  327.     button.position_f[0] = button_e.Position[0] + dist * dir[0]
  328.     button.position_f[1] = button_e.Position[1] + dist * dir[1]
  329.     button.position_f[2] = button_e.Position[2] + dist * dir[2]
  330.     button.combi = combi
  331.     a = dist / time
  332.     if combi.state and correct_state == state:
  333.         combi.corrects = combi.corrects + 1
  334.         combi.activates = combi.activates + 1
  335.     
  336.     if state:
  337.         button_e.Position = button.position_f
  338.         button.v[0] = a * dir[0]
  339.         button.v[1] = a * dir[1]
  340.         button.v[2] = a * dir[2]
  341.     else:
  342.         button.v[0] = a * dir[0] * -1
  343.         button.v[1] = a * dir[1] * -1
  344.         button.v[2] = a * dir[2] * -1
  345.     button.order = order
  346.     button.time = time
  347.     button.state = state
  348.     button.initial_state = state
  349.     button.correct_state = correct_state
  350.     combi.n_buttons = combi.n_buttons + 1
  351.     return button
  352.  
  353.