示例#1
0
 def on_destroy(self):
     if self.lives:
         self.lives -= 1
         (Delay(self.respawn_time) + CallFunc(do_respawn, self.owner.__class__, self.lives, PigDirector.scene)).do()
     elif self.do_gameover:
         gamedata = get_gamedata()
         gamedata.gameover()
示例#2
0
 def do_stop_scene(self, doRevert=True):      
     if _DEBUG: print "stop_scene"
     if not getattr(self.Director, "project_started", False):
         return
     if _DEBUG: print "stop_scene 1.5"
     wait_for_state(None)
     if _DEBUG: print "stop_scene 2"
     self.scene.stop()
     if _DEBUG: print "stop_scene 3"        
     wait_for_exit_scene()
     if _DEBUG: print "stop_scene 4"        
     gamedata = get_gamedata()
     scene = gamedata.start_sceneclass
     create_gamedata()
     if _DEBUG: print "stop_scene 5"
     pug.set_default_pugview("Component", _dataPugview)
     if _DEBUG: print "stop_scene 6", scene.__name__        
     if doRevert:
         if self.edit_info:
             wx.GetApp().set_busy_state( True)
             Director.switch_scene = self.edit_info[0]
             while Director.scene != self.edit_info[0]:
                 time.sleep(0.05)
             self.restore_editor()
             wx.CallAfter( entered_scene)
         else:
             self.set_scene(scene.__name__, True)
             self.edit_info = None
     if _DEBUG: print "stop_scene 7"  
示例#3
0
 def do_stop_scene(self, doRevert=True):
     if _DEBUG: print "stop_scene"
     if not getattr(self.Director, "project_started", False):
         return
     if _DEBUG: print "stop_scene 1.5"
     wait_for_state(None)
     if _DEBUG: print "stop_scene 2"
     self.scene.stop()
     if _DEBUG: print "stop_scene 3"
     wait_for_exit_scene()
     if _DEBUG: print "stop_scene 4"
     gamedata = get_gamedata()
     scene = gamedata.start_sceneclass
     create_gamedata()
     if _DEBUG: print "stop_scene 5"
     pug.set_default_pugview("Component", _dataPugview)
     if _DEBUG: print "stop_scene 6", scene.__name__
     if doRevert:
         if self.edit_info:
             wx.GetApp().set_busy_state(True)
             Director.switch_scene = self.edit_info[0]
             while Director.scene != self.edit_info[0]:
                 time.sleep(0.05)
             self.restore_editor()
             wx.CallAfter(entered_scene)
         else:
             self.set_scene(scene.__name__, True)
             self.edit_info = None
     if _DEBUG: print "stop_scene 7"
示例#4
0
 def get_lives(self):
     "get_lives()->self._lives"
     gamedata = get_gamedata()
     try:
         return getattr(gamedata, self.value_name)
     except:
         if self._lives is None:
             self.set_lives(self.start_lives - 1)
         return self._lives
示例#5
0
 def on_added_to_scene(self):
     """Set score to zero unless otherwise set"""
     gamedata = get_gamedata()
     try:
         getattr(gamedata, self.value_name)
     except:
         setattr( gamedata, self.value_name, self.start_value)            
     gamedata.register_callback( self.value_name, self.on_value_change)
     self.set_text()
示例#6
0
 def get_lives(self):
     "get_lives()->self._lives"
     gamedata = get_gamedata()         
     try:
         return getattr(gamedata, self.value_name)   
     except:
         if self._lives is None:
             self.set_lives( self.start_lives - 1)
         return self._lives
示例#7
0
 def on_destroy(self):
     if self.lives:
         self.lives -= 1
         (Delay(self.respawn_time) + CallFunc(do_respawn, 
                                              self.owner.__class__,
                                              self.lives,
                                              PigDirector.scene)).do()
     elif self.do_gameover:
         gamedata = get_gamedata()
         gamedata.gameover()
示例#8
0
 def rewind_scene(self):
     """rewind_scene(): reset the scene and play it again"""
     if not self.Director.project_started:
         return
     gamedata = get_gamedata()
     scene = gamedata.start_sceneclass
     create_gamedata()
     self.Director.project_started = False
     oldscene = self.Director.scene
     self.Director.set_scene(scene)
     while Director.scene == oldscene:
         time.sleep(0.05)
     entered_scene()
示例#9
0
 def rewind_scene(self):
     """rewind_scene(): reset the scene and play it again"""
     if not self.Director.project_started:
         return
     gamedata = get_gamedata()
     scene = gamedata.start_sceneclass
     create_gamedata()
     self.Director.project_started = False
     oldscene = self.Director.scene
     self.Director.set_scene(scene)
     while Director.scene == oldscene:
         time.sleep(0.05)
     entered_scene()
示例#10
0
 def on_added_to_scene(self):
     """Set starting value"""
     gamedata = get_gamedata()
     try:
         getattr(gamedata, self.value_name)
     except:
         setattr(gamedata, self.value_name, float(self.start_value))
     Value_Tracker_Text.on_added_to_scene(self)
     # set up countdown if end is less than start
     if self.end_value < self.start_value:
         self.interval = -abs(self.interval)
     # if interval is set, start tickin
     if self.interval:
         (Delay(0) + CallFunc(self.timer_tick, 0)).do()
示例#11
0
 def on_added_to_scene(self):
     """Set starting value"""
     gamedata = get_gamedata()
     try:
         getattr(gamedata, self.value_name)
     except:
         setattr( gamedata, self.value_name, float(self.start_value))
     Value_Tracker_Text.on_added_to_scene(self)
     # set up countdown if end is less than start
     if self.end_value < self.start_value:
         self.interval = - abs(self.interval)
     # if interval is set, start tickin
     if self.interval:
         ( Delay(0) + CallFunc(self.timer_tick, 0)).do()       
示例#12
0
 def timer_tick(self, amount=None):
     if amount == None:
         amount = self.interval 
     gamedata = get_gamedata()
     value = gamedata.timer                
     newval = value + amount
     if self.end_value >=0:
         if self.interval < 0 and newval <= self.end_value or\
                     self.interval > 0 and newval >= self.end_value:
             # we've reached the end value
             gamedata.timer = self.end_value
             self.owner.do( Delay(0) + CallFunc(self.owner.on_time_up))
             return
     gamedata.timer = newval
     if self.interval:
         self.owner.do( Delay(abs(self.interval)) + \
                    CallFunc(self.timer_tick))
示例#13
0
 def set_text(self, text=None):
     "Show current value"
     gamedata = get_gamedata()
     if text is None:
         if getattr(gamedata, self.value_name, None) is None:
             # gamedata not set up... show default
             text = self.prefix + self.default
         else:
             # get gamedata
             val = getattr(gamedata, self.value_name, self.default)
             # format output
             if type(val) == float:
                 val =  ("%."+str(self.decimal_places)+"f") % val
             else:
                 val = str(val)
             text = self.prefix + val
     Textbox.set_text( self, text)
示例#14
0
 def timer_tick(self, amount=None):
     if amount == None:
         amount = self.interval
     gamedata = get_gamedata()
     value = gamedata.timer
     newval = value + amount
     if self.end_value >= 0:
         if self.interval < 0 and newval <= self.end_value or\
                     self.interval > 0 and newval >= self.end_value:
             # we've reached the end value
             gamedata.timer = self.end_value
             self.owner.do(Delay(0) + CallFunc(self.owner.on_time_up))
             return
     gamedata.timer = newval
     if self.interval:
         self.owner.do( Delay(abs(self.interval)) + \
                    CallFunc(self.timer_tick))
示例#15
0
 def _get_shell_info(self):
     "_get_shell_info()->info for pug's open_shell command"
     scene = PigDirector.scene
     items = {'_Project':self, 
              '_'+scene.__class__.__name__:scene}
     nodes = scene.nodes
     indexes = {}
     for node in nodes:
         name = node._get_shell_name()
         if name not in indexes:
             indexes[name]=1
         else:
             indexes[name]+=1
             name=name+"_"+str(indexes[name])
         items[name] = node
     items['_gamedata'] = get_gamedata()
     locals = items.copy()
     import pig.actions
     for action in dir(pig.actions):
         if action[0] != "_":
             locals[action]=getattr(pig.actions,action)
     return dict(rootObject=items,rootLabel="Project Data",locals=locals,
                 pug_view_key=self)
示例#16
0
 def set_text(self, text=None):
     "Show current value"
     gamedata = get_gamedata()
     if text is None:
         val = getattr(gamedata, 'timer', None)
         if self.show_minutes:
             if val is None:
                 # no gamedata value, show default
                 text = "00:00"
             else:
                 # format value
                 minutes = int(val / 60)
                 seconds = int(val % 60)
                 text = str(minutes) + ':' + str(seconds)
         else:
             if val is None:
                 # no gamedata value, show default
                 text = "00"
             else:
                 #format value
                 text = "%0.f" % val
         text = self.prefix + text
     Textbox.set_text(self, text)
示例#17
0
 def set_text(self, text=None):
     "Show current value"
     gamedata = get_gamedata()
     if text is None:
         val = getattr(gamedata, 'timer', None)
         if self.show_minutes:
             if val is None:
                 # no gamedata value, show default
                 text = "00:00"
             else:
                 # format value
                 minutes = int(val / 60)
                 seconds = int(val % 60)
                 text = str(minutes) + ':' + str(seconds)
         else:
             if val is None:
                 # no gamedata value, show default
                 text = "00"
             else:
                 #format value
                 text = "%0.f" % val
         text = self.prefix + text
     Textbox.set_text( self, text)
示例#18
0
 def _get_shell_info(self):
     "_get_shell_info()->info for pug's open_shell command"
     scene = PigDirector.scene
     items = {'_Project': self, '_' + scene.__class__.__name__: scene}
     nodes = scene.nodes
     indexes = {}
     for node in nodes:
         name = node._get_shell_name()
         if name not in indexes:
             indexes[name] = 1
         else:
             indexes[name] += 1
             name = name + "_" + str(indexes[name])
         items[name] = node
     items['_gamedata'] = get_gamedata()
     locals = items.copy()
     import pig.actions
     for action in dir(pig.actions):
         if action[0] != "_":
             locals[action] = getattr(pig.actions, action)
     return dict(rootObject=items,
                 rootLabel="Project Data",
                 locals=locals,
                 pug_view_key=self)
示例#19
0
 def on_time_up(self):
     """Callback for when timer reaches end_value"""
     if self.gameover:
         gamedata = get_gamedata()
         gamedata.gameover()
示例#20
0
 def on_destroy(self):
     """Add self.amount to gamedata.<value_name> when object is destroyed"""
     gamedata = get_gamedata()        
     setattr(gamedata, self.value_name, 
             getattr(gamedata, self.value_name, 0) + self.amount)
示例#21
0
 def on_destroy(self):
     """Add self.amount to gamedata.<value_name> when object is destroyed"""
     gamedata = get_gamedata()
     setattr(gamedata, self.value_name,
             getattr(gamedata, self.value_name, 0) + self.amount)
示例#22
0
 def set_lives(self, lives):
     "set_lives(lives): set self._lives"
     self._lives = lives
     if self.value_name:
         gamedata = get_gamedata()
         setattr(gamedata, self.value_name, lives)
示例#23
0
 def set_health(self, health):
     "set_health(health): set self._health"
     self._health = health
     if self.value_name:
         gamedata = get_gamedata()
         setattr(gamedata, self.value_name, health)
示例#24
0
 def on_time_up(self):
     """Callback for when timer reaches end_value"""
     if self.gameover:
         gamedata = get_gamedata()
         gamedata.gameover()
示例#25
0
 def set_lives(self, lives):
     "set_lives(lives): set self._lives"
     self._lives = lives
     if self.value_name:
         gamedata = get_gamedata()
         setattr(gamedata, self.value_name, lives)            
示例#26
0
 def on_destroy(self):
     gamedata = get_gamedata()
     gamedata.unregister_callback(self.value_name, self.on_value_change)
示例#27
0
 def on_added_to_scene(self):
     """Add self.amount to gamedata.<value_name> when object is created"""
     gamedata = get_gamedata()        
     setattr(gamedata, self.value_name, 
             getattr(gamedata, self.value_name, 0) + self.amount)
示例#28
0
 def set_health(self, health):
     "set_health(health): set self._health"
     self._health = health
     if self.value_name:
         gamedata = get_gamedata()
         setattr(gamedata, self.value_name, health)