def on_enter(self): self.components.add( Set_Mouse_Cursor( image='art/pug.png') ) # Archetypes LetterPetal_archetype = LetterPetal(gname='LetterPetal') LetterPetal_archetype.archetype = True # Sprites sprite_instance = Sprite() sprite_instance.image = 'art/pug.png' sprite_instance.layer = 'Background' sprite_instance.position = (400.0, 300.0) sprite_instance.alpha = 0.0 sprite_instance.components.add( Key_Spawn( gname='spawner', spawn_object='LetterPetal', spawn_interval=0.2) ) sprite_instance.components.add( Spawn_Flower( gname='flower') ) sprite_instance.components.add( Spawned_Component_Change( gname='key_shifter', component_name='symbol', attribute='text', change_value='$') ) ### End Flower autocode ### self.key_shifter = get_gnamed_object('key_shifter') self.spawner = get_gnamed_object('spawner') self.flower = get_gnamed_object('flower')
def on_enter(self): self.components.add(Set_Mouse_Cursor(image='art/pug.png')) # Archetypes LetterPetal_archetype = LetterPetal(gname='LetterPetal') LetterPetal_archetype.archetype = True # Sprites sprite_instance = Sprite() sprite_instance.image = 'art/pug.png' sprite_instance.layer = 'Background' sprite_instance.position = (400.0, 300.0) sprite_instance.alpha = 0.0 sprite_instance.components.add( Key_Spawn(gname='spawner', spawn_object='LetterPetal', spawn_interval=0.2)) sprite_instance.components.add(Spawn_Flower(gname='flower')) sprite_instance.components.add( Spawned_Component_Change(gname='key_shifter', component_name='symbol', attribute='text', change_value='$')) ### End Flower autocode ### self.key_shifter = get_gnamed_object('key_shifter') self.spawner = get_gnamed_object('spawner') self.flower = get_gnamed_object('flower')
def check_facing(self, position=None): """check_facing(position=None) position: an Opioid vector Turn the object toward position. If None, use obj.position""" if not self.enabled: self.action.abort() return if position is None: if not self.target: return obj = get_gnamed_object(self.target) if not obj: return position = obj.position target_angle = angle_to(self.owner.position, position) + self.offset if self.rotation_speed < 0: # set owner to proper rotation instantly self.owner.rotation = target_angle else: if self.target_angle != target_angle: #create an action that will rotate owner to proper angle if self.action: self.action.abort() self.action = (RotateTo(target_angle, speed=self.rotation_speed) + \ self.end_action).do(self.owner) self.target_angle = target_angle if self.owner.rotation == self.target_angle: self.target_reached()
# except: # pass def __del__(self): # don't know why this try is necessary, but I get an exception without # it try: self.clear_callbacks() BaseObject.__del__(self) except: pass if __name__ == '__main__': from pug import get_gnamed_object def pr(*a, **kw): print "PR!",a, kw obj = CallbackObject("doo") print get_gnamed_object("doo") obj.register_callback( "x", pr) obj.x = 4 obj.y = 5 obj.x = "xxx" obj.unregister_callback( "x", pr) obj.x = "yyy" obj.unregister_callback( "x", pr) del(obj) print get_gnamed_object("doo")
# except: # pass def __del__(self): # don't know why this try is necessary, but I get an exception without # it try: self.clear_callbacks() BaseObject.__del__(self) except: pass if __name__ == '__main__': from pug import get_gnamed_object def pr(*a, **kw): print "PR!", a, kw obj = CallbackObject("doo") print get_gnamed_object("doo") obj.register_callback("x", pr) obj.x = 4 obj.y = 5 obj.x = "xxx" obj.unregister_callback("x", pr) obj.x = "yyy" obj.unregister_callback("x", pr) del (obj) print get_gnamed_object("doo")