Exemple #1
0
    def register(self, object, type="single"):
        """register( object, type="single")
        
object: the sprite to register for mouse events
type: "single", "multi", or "click". Gui objects check all mouse events. If one is
under the mouse, no other mouse events will be checked. Game objects check all
mouse events, but if one is found others are still checked. Click objects only
check for mouse down and mouse up events. 

Registering can upgrade type from "multi" to "single" or from "click" to "multi" or 
"single". It will NOT downgrade type. To downgrade, you must unregister then re-
register at the lower callback level.
"""
        if type not in ['single', 'multi', 'click']:
            raise ValueError("Must register for mouse events as"+\
                             " 'single', 'multi', or 'click'")
        if (type == "multi" and object._mouse_registered == "single") or \
                (type == "click" and (object._mouse_registered == "single" or \
                                      object._mouse_registered == "multi")):
            # we're already getting those events
            return
        if type == "single":
            group = self._single_objects
        elif type == "multi":
            group = self._multi_objects
        elif type == "click":
            group = self._click_objects
        (Delay(0) + CallFunc(group.add, object)).do()
        object._mouse_registered = type
Exemple #2
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))
Exemple #3
0
    def set_image_file(self, file):
        if isinstance(file, basestring):
            self._image_file = file
        else:
            self._image_file = None
#        OpioidSprite.set_image(self, file)
        if file:
            (Delay(0) + CallFunc(OpioidSprite.set_image, self, file)).do()
Exemple #4
0
 def on_delete(self):
     "Respawn if being deleted as an archetype"
     if self.owner.archetype and self.spawn_archetype and \
             getattr(PigDirector, 'start_project', False):
         # set up original lives
         (Delay(0) + CallFunc(do_respawn, 
                              self.owner.__class__,
                              self.lives, 
                              PigDirector.scene)).do()
Exemple #5
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()
Exemple #6
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()
Exemple #7
0
 def on_first_display(self):
     """Set up health and collisions"""
     if self.health is None:
         self.health = float(self.start_health)
     self.start_tint = self.owner.tint
     self.tint_difference = (
         self.damage_tint[0] - self.start_tint[0],
         self.damage_tint[1] - self.start_tint[1],
         self.damage_tint[2] - self.start_tint[2],
     )
     if self.invincible_time:
         self.action = (Delay(self.invincible_time) + \
             CallFunc(self.set_invincible, False)).do()
     else:
         self.invincible = False
Exemple #8
0
 def do_restart(self):
     "do_restart(): restart this scene (NOT the game itself)"
     #Director.project_started = False
     (Delay(0) + CallFunc(PigDirector.switch_scene_to,
                          PigDirector.scene.__class__)).do()
Exemple #9
0
 def start_timer(self, secs=None):
     "start_timer(secs=None): If secs is none, default to self.timer_secs"
     if secs is None:
         secs = self.timer_secs
     self.timerAction = self.owner.do(Delay(secs) + CallFunc(self.destruct))