self.check_spawn() def stop_spawning(self): self.spawning = False @component_method def on_destroy(self): """unregister keys when component is destroyed""" scene = PigDirector.scene for k in self.k_info: scene.unregister_key(k) self.k_info = [] @component_method def on_spawn(self, obj, component): """Tint spawned objects according to notes held""" if not self.note_tint or not self.on_notes: return total = 0 count = 0 for notes in self.on_notes.itervalues(): total += sum(notes) count += 1.0 avg_key = total / count diff = self.spectrum_range[1] - self.spectrum_range[0] hue = ((avg_key - self.spectrum_range[1]) % diff) / float(diff) obj.color = colorsys.hsv_to_rgb(hue, 1, 1) register_component(Midi_Spawn)
_type = 'spawn' _class_list = [Node] # attributes: ['name','desc'] or ['name', agui, {'doc':'desc', extra info}] _field_list = [ ['spawner_name', MyComponents, {'doc':'Name of the spawner component. '+\ 'If blank, all spawners will be affected.'}] ] _field_list += Set_Attribute._field_list # defaults _spawner_name = "" @component_method def on_added_to_scene(self): "Over-ride Set_Component's auto-set." # don't do the auto-set from Set_Component pass @component_method def on_spawn( self, obj, component): if not self._spawner_name or self._spawner_name == component.gname: Set_Attribute.do_change(self, obj) def get_spawner_name(self): return self._spawner_name def set_spawner_name(self, name): self._spawner_name = name.strip() spawner_name = property(get_spawner_name, set_spawner_name) register_component( Spawned_Attribute_Change)
["spawn_location", Dropdown, {'list':['area', 'center', 'edges', 'top', 'bottom','left','right'], 'doc':"The area where objects can be spawned"}], ["spawn_offset", "Spawn location is offset by this much (0 to 1, 0 to 1). (0,0) "+\ "is top-left, (0.5,0.5) is center, (1,1) is bottom-right etc."], ["obs_per_spawn","Number of objects created per spawn"], ["obs_per_spawn_variance", "obs_per_spawn can vary by this much"], ["match_scale", "Multiply spawned object's scale by owner's scale"], ["add_rotation", "Add owner's rotation to spawned object's rotation"], ["add_velocity", "Add owner's velocity to spawned object's velocity"], ["obj_callback", "\n".join(["Call this method of spawned object right after a spawn happens.", "callback( this_component)"])], ] @component_method def on_added_to_scene(self): "Setup the spawner" self.setup_spawner() @component_method def on_destroy(self): "Do spawn when object is destroyed" self.spawn() register_component( Spawn_On_Destroy)
spawner_name = "" flowering = None @component_method def on_spawn( self, obj, component): "Trigger extra spawns at new angles." if self.spawner_name and self.spawner_name != component.gname: return if self.flowering is None: # the spawning is just starting self.flowering = component # the spawning component else: # this is a spawn created by this component. Don't flower it. return self.start_rotation = self.owner.rotation # how much to rotate for each copy rotation = 360 / float(self.petals) # flower the spawn for i in range(self.petals - 1): # next rotation self.owner.rotation += rotation # this component works through recursion... the spawn call below # will end up calling this on_spawn function again component.spawn() # return to non-flowering state self.flowering = None self.owner.rotation = self.start_rotation register_component( Spawn_Flower)
# defaults _component_name = "" @component_method def on_added_to_scene(self): "Clean up names." # don't do the auto-set from Set_Component Spawned_Attribute_Change.on_added_to_scene(self) @component_method def on_spawn(self, spawn_object, component): if not self._component_name: return if not self._spawner_name or self._spawner_name == component.gname: list = spawn_object.components.get() for spawned_comp in list: if spawned_comp.gname != self._component_name: continue Set_Attribute.do_change(self, spawned_comp) def get_component_name(self): return self._component_name def set_component_name(self, name): self._component_name = name.strip() component_name = property(get_component_name, set_component_name) register_component(Spawned_Component_Change)
from Opioid2D.public.Node import Node from pug.component import register_component from pig.components import Face_Object class Mouse_Face( Face_Object): """Object turns to face the mouse. This is exactly like the Face_Object component with the mouse-pointer as the target.""" #component_info _set = 'pig' _type = 'controls' _class_list = [Node] # attributes: ['name','desc'] or ['name', agui, {'doc':'desc', extra info}] _field_list = [ ['rotation_speed', 'Speed to turn. Negative = always face mouse exactly.'], ['offset', 'Offset the rotation by this much'] ] def check_facing(self, position=None): """check_facing(position=None) position: an Opioid vector Turn the object toward position. If None, use mouse position.""" if position is None: position = Mouse.position Face_Object.check_facing(self, position) register_component( Mouse_Face)
flowering = None @component_method def on_spawn(self, obj, component): "Trigger extra spawns at new angles." if self.spawner_name and self.spawner_name != component.gname: return if self.flowering is None: # the spawning is just starting self.flowering = component # the spawning component else: # this is a spawn created by this component. Don't flower it. return self.start_rotation = self.owner.rotation # how much to rotate for each copy rotation = 360 / float(self.petals) # flower the spawn for i in range(self.petals - 1): # next rotation self.owner.rotation += rotation # this component works through recursion... the spawn call below # will end up calling this on_spawn function again component.spawn() # return to non-flowering state self.flowering = None self.owner.rotation = self.start_rotation register_component(Spawn_Flower)
interval = self.get_next_spawn_wait() # set a timer to change interval_complete to True self.owner.do( Delay(interval) + CallFunc(self.set_complete, True)) def set_complete(self, val): self.interval_complete = val if self.rapid_fire and self.owner and self.spawning: # when rapid_firing, we CAN shoot, so try to shoot! self.check_spawn() def stop_spawning(self): self.spawning = False @component_method def on_destroy(self): """unregister keys when component is destroyed""" scene = PigDirector.scene for k in self.k_info: scene.unregister_key(k) self.k_info = [] @component_method def on_delete(self): """unregister keys when component is deleted""" self.rapid_fire = False self.on_destroy() register_component(Key_Spawn)
# set a timer to change interval_complete to True self.owner.do( Delay(interval) + CallFunc(self.set_complete, True)) def set_complete(self, val): self.interval_complete = val if self.rapid_fire and self.owner and self.spawning: # when rapid_firing, we CAN shoot, so try to shoot! self.check_spawn() def stop_spawning(self): self.spawning = False @component_method def on_destroy(self): """unregister keys when component is destroyed""" scene = PigDirector.scene for k in self.k_info: scene.unregister_key(k) self.k_info = [] @component_method def on_delete(self): """unregister keys when component is deleted""" self.rapid_fire = False self.on_destroy() register_component( Key_Spawn)
["sound", SoundFile, {'doc':"Sound to play when a spawn occurs"}], ["spawn_location", Dropdown, {'list':['area', 'center', 'edges', 'top', 'bottom','left','right'], 'doc':"The area where objects can be spawned"}], ["spawn_offset", "Spawn location is offset by this much (0 to 1, 0 to 1). (0,0) "+\ "is top-left, (0.5,0.5) is center, (1,1) is bottom-right etc."], ["obs_per_spawn","Number of objects created per spawn"], ["obs_per_spawn_variance", "obs_per_spawn can vary by this much"], ["match_scale", "Multiply spawned object's scale by owner's scale"], ["add_rotation", "Add owner's rotation to spawned object's rotation"], ["add_velocity", "Add owner's velocity to spawned object's velocity"], ["obj_callback", "\n".join(["Call this method of spawned object right after a spawn happens.", "callback( this_component)"])], ] @component_method def on_added_to_scene(self): "Setup the spawner" self.setup_spawner() @component_method def on_destroy(self): "Do spawn when object is destroyed" self.spawn() register_component(Spawn_On_Destroy)
from pug.component import register_component from pig.components import Face_Object class Mouse_Face(Face_Object): """Object turns to face the mouse. This is exactly like the Face_Object component with the mouse-pointer as the target.""" #component_info _set = 'pig' _type = 'controls' _class_list = [Node] # attributes: ['name','desc'] or ['name', agui, {'doc':'desc', extra info}] _field_list = [[ 'rotation_speed', 'Speed to turn. Negative = always face mouse exactly.' ], ['offset', 'Offset the rotation by this much']] def check_facing(self, position=None): """check_facing(position=None) position: an Opioid vector Turn the object toward position. If None, use mouse position.""" if position is None: position = Mouse.position Face_Object.check_facing(self, position) register_component(Mouse_Face)
] _field_list += Set_Attribute._field_list # defaults _component_name = "" @component_method def on_added_to_scene(self): "Clean up names." # don't do the auto-set from Set_Component Spawned_Attribute_Change.on_added_to_scene(self) @component_method def on_spawn( self, spawn_object, component): if not self._component_name: return if not self._spawner_name or self._spawner_name == component.gname: list = spawn_object.components.get() for spawned_comp in list: if spawned_comp.gname != self._component_name: continue Set_Attribute.do_change(self, spawned_comp) def get_component_name(self): return self._component_name def set_component_name(self, name): self._component_name = name.strip() component_name = property(get_component_name, set_component_name) register_component( Spawned_Component_Change)
def stop_spawning(self): self.spawning = False @component_method def on_destroy(self): """unregister keys when component is destroyed""" scene = PigDirector.scene for k in self.k_info: scene.unregister_key(k) self.k_info = [] @component_method def on_spawn(self, obj, component): """Tint spawned objects according to notes held""" if not self.note_tint or not self.on_notes: return total = 0 count = 0 for notes in self.on_notes.itervalues(): total += sum(notes) count += 1.0 avg_key = total/count diff = self.spectrum_range[1] - self.spectrum_range[0] hue = ((avg_key - self.spectrum_range[1]) % diff) / float(diff) obj.color = colorsys.hsv_to_rgb( hue, 1, 1) register_component( Midi_Spawn)
"spawner_name", MyComponents, {"doc": "Name of the spawner component. " + "If blank, all spawners will be affected."}, ] ] _field_list += Set_Attribute._field_list # defaults _spawner_name = "" @component_method def on_added_to_scene(self): "Over-ride Set_Component's auto-set." # don't do the auto-set from Set_Component pass @component_method def on_spawn(self, obj, component): if not self._spawner_name or self._spawner_name == component.gname: Set_Attribute.do_change(self, obj) def get_spawner_name(self): return self._spawner_name def set_spawner_name(self, name): self._spawner_name = name.strip() spawner_name = property(get_spawner_name, set_spawner_name) register_component(Spawned_Attribute_Change)