def fuck_me (self, pos = None): if not pos: pos = self.position self._model.detachNode () node = self.entities.render self._smoke_particles.start (node) self._smoke_particles.setPos (pos + Vec3 (0, 0, 2)) self._fire_particles.start (node) self._fire_particles.setPos (pos) self.entities.tasks.add (task.sequence ( task.wait (2.), task.run (self._fire_particles.softStop), task.wait (2.), task.run (self._smoke_particles.softStop), task.wait (2.), task.run (self.dispose))) self.disable_physics () random.choice (self.death_sounds).play () self.on_death () self.is_dead = True
def _make_roll_dice_task (self, dice_iter): def roll_dice_fn (): try: dice = dice_iter.next () dice.roll () self.manager.system.audio.play_sound (random.choice (map ( lambda i: 'data/sfx/canon/canon-%i.wav' % i, range (1, 4)))) self.tasks.add (self._make_roll_dice_task (dice_iter)) except StopIteration: self._evaluate_dices () return task.sequence (task.wait (.5), task.run (roll_dice_fn))
def on_hit (self, ev, me, other): """ Make sure that this gets executed on hittable only... """ _log.debug ("A weapon %s hitted a %s." % (str (me), str (other))) if self._timer.elapsed - other.hit_time > self.weapon_hit_delay: self.play_random_sound (self._hit_sounds) direction = normalize (other.position - self._owner.position) direction.setZ (math.sin (math.pi / 4.)) other.hit_time = self._timer.elapsed self.entities.tasks.add (task.sequence ( task.delay (), task.run ( lambda: other.set_linear_velocity (normalize (direction) * self.weapon_hit_speed)))) other.on_hit (self)
def _soft_move (self, dst): if self._move_task: self._move_task.kill () next_time = 0 group = task.parallel () for n in self._counter_nodes: group.add (task.sequence ( task.wait (next_time), task.linear (n.setPos, n.getPos (), dst, init = True))) next_time += .5 self.entities.tasks.add (group) self._move_task = group return group
def do_setup(self, message='', position=None, *a, **k): super(RootMessageState, self).do_setup(*a, **k) self.ui_text = ui.MultiLineString(self.root.ui_layer, unicode(message)) self.ui_text.set_center_rel(.5, .5) self.ui_text.set_position_rel(.5, .5) self.ui_text.set_size(40) if position is not None: self.ui_text.set_rotation(player.rotation[position]) self.root.enable_bg() self.tasks.add( task.sequence( self.make_fade_task(task.fade), task.run(lambda: self.root.ui_bg.on_click.connect( self.on_click_bg))))
def do_destroy (self): if self.active: #Buttons destroy self.do_disable () #Movement task creation self.move_task = task.sequence ( task.parallel( task.sinusoid (lambda x: self.sound.setPos (0.45-(x*0.55), 0, .8-(x*0.25))), task.sinusoid (lambda x: self.sound.setAlphaScale (1-x)), task.sinusoid (lambda x: self.keyboard.setPos (0.6-(x*0.7), 0, 0.55)), task.sinusoid (lambda x: self.keyboard.setAlphaScale (1-x)), task.sinusoid (lambda x: self.screen.setPos (0.55-(x*0.65), 0, 0.3+(x*0.25))), task.sinusoid (lambda x: self.screen.setAlphaScale (1-x)), task.sinusoid (lambda x: self.back.setPos (0.55-(x*0.65), 0, 0.05+(x*0.5))), task.sinusoid (lambda x: self.back.setAlphaScale (1-x)) ), task.run (self.sound.destroy), task.run (self.back.destroy), task.run (self.keyboard.destroy), task.run (self.screen.destroy) ) for n in self.sub_menus.keys(): if self.sub_menus[n].active: self.sub_menus[n].do_destroy () #The option_menu is set as inactive self.active = False else: self.move_task = task.wait(0) return self.move_task
def _make_dice_eval_task (self, dice_iter): use_on_attack = self.game.world.use_on_attack def eval_dice_fn (): try: attack_dice, defend_dice = dice_iter.next () if attack_dice.value > defend_dice.value: attack_dice.win () defend_dice.fail () self.defender.model.troops -= 1 else: attack_dice.fail () defend_dice.win () if use_on_attack: self.attacker.model.used -= 1 else: self.attacker.model.troops -= 1 self.manager.system.audio.play_sound (random.choice (map ( lambda i: 'data/sfx/swords/sword_%i.wav'%i, range (1,7)))) self.tasks.add (self._make_dice_eval_task (dice_iter)) except StopIteration: self.ui_attack.enable_continue () return task.sequence (task.wait (.5), task.run (eval_dice_fn))
def do_smile(self, time=0.2): return task.sequence(task.run(self.to_smile), task.wait(time), task.run(self.to_normal))
def _on_click_quit (self, ev = None): self.manager.enter_state ('dialog', mk_dialog = CreditsDialog) self.parent_state.tasks.add (task.sequence ( task.wait (5.), task.run (self.manager.leave_state), task.run (self.manager.leave_state)))
def __init__(self, model=pigeon_model, anims=pigeon_anims, boys=[], *a, **k): super(Pigeon, self).__init__( geometry=geom.capsule(2, 1), #mass = mass.sphere (1, 2), model=model, anims=anims, category=pigeon_category, *a, **k) self.on_is_on_floor_change += self.on_pigeon_is_on_floor self.on_hit += self.on_pigeon_hit self.on_death += self.on_pigeon_death for boy in boys: boy.on_boy_noise += self.on_boy_noise boy.on_entity_set_position += self.on_boy_move self.physical_hpr = Vec3(90, 0, 0) self.params = BoidParams() self.model_position = Vec3(0, 0, -2) self.model_scale = Vec3(0.08, 0.08, 0.08) self.model_hpr = Vec3(180, 0, 0) self.add_state('fly', FlyState) self.add_state('walk', WalkState) self.add_state('follow', FollowState) self.add_state('fear', FearState) self.add_state('eat', EatState) self.add_state('hit', HitState) self.add_state('land', LandState) self.add_state('return', ReturnState) self.add_state('attack', AttackState) self.model.loop('fly') self.curr_animation = 'fly' self.anim_speed = 50 # Hack: 3D audio seems very slow, so only some pigeons emit # some kinds of sounds. if random.uniform(0, 10) < 2.: self._coo_sounds = map( self.load_sound, map(lambda x: "snd/pigeon-coo-%i.wav" % x, range(1, 5))) self.tasks.add( task.sequence( task.wait(random.uniform(0, 20)), task.loop( task.func_wait(partial(random.uniform, 10, 30)), task.run( lambda: random.choice(self._coo_sounds).play())))) else: self._coo_sounds = [] if random.uniform(0, 10) < 2.: self._fly_sound = self.load_sound('snd/pigeon-start.wav') else: self._fly_sound = None if random.uniform(0, 10) < 2.: self._fear_sound = self.load_sound('snd/pigeon-flap.wav') else: self._fear_sound = None self.start('land')
def do_pigeon_setup (self): super (PatrolState, self).do_pigeon_setup () self.tasks.add (task.sequence ( task.wait (random.uniform (15, 30)), task.run (self.next_state)))
def do_connect(self): # Buttons task assigment if self.type == 'main': self.start["command"] = lambda: self.state.tasks.add( task.sequence( task.run(self.do_disable_this), task.parallel( self.options_menu.do_destroy(), self.credits_menu.do_destroy(), task.run(self.state.to_smile), ), task.run(lambda: self.state.manager.leave_state('game')) )) self.exit["command"] = lambda: self.state.tasks.add( task.sequence( task.run(self.do_disable_this), task.parallel( self.options_menu.do_destroy(), self.credits_menu.do_destroy(), task.run(self.state.to_smile), ), task.run(self.state.manager.leave_state))) self.state.events.event('panda-escape').connect( lambda: self.state.tasks.add( task.sequence(task.delay(), task.run(self.exit["command"])) )) if self.type == 'ingame': self.start["command"] = lambda: self.state.tasks.add( task.sequence( task.run(self.do_disable_this), task.parallel( self.options_menu.do_destroy(), self.credits_menu.do_destroy(), task.run(self.state.to_smile), ), task.run(lambda: self.state.manager.leave_state('continue') ))) self.exit["command"] = lambda: self.state.tasks.add( task.sequence( task.run(self.do_disable_this), task.parallel( self.options_menu.do_destroy(), self.credits_menu.do_destroy(), task.run(self.state.to_smile), ), task.run(lambda: self.state.manager.leave_state('quit')) )) self.state.events.event('panda-escape').connect( lambda: self.state.tasks.add( task.sequence(task.delay(), task.run(self.start["command"]) ))) self.credits["command"] = lambda: self.state.tasks.add( self.do_show_credits()) self.options["command"] = lambda: self.state.tasks.add( task.sequence( task.run(lambda: self.options.setProp('state', DGG.DISABLED)), task.parallel( self.state.do_smile(), self.do_show_options(), ), task.run(lambda: self.options.setProp('state', DGG.NORMAL))) )
def do_smile (self, time = 0.2): return task.sequence( task.run (self.to_smile), task.wait (time), task.run (self.to_normal))
def _on_click_quit(self, ev=None): self.manager.enter_state('dialog', mk_dialog=CreditsDialog) self.parent_state.tasks.add( task.sequence(task.wait(5.), task.run(self.manager.leave_state), task.run(self.manager.leave_state)))
def do_pigeon_setup (self): self.tasks.add (task.sequence (task.wait (2.), task.run (self.kill))) self.manager.pigeon_sweeping = False
def on_click_bg(self): self.root.disable_bg() self.tasks.add( task.sequence(self.make_fade_task(task.invfade), task.run(self.manager.leave_state)))
def do_paint (self): # Option-Buttons inicialitation self.sound = DirectButton(geom = self.state.bt_yellow, geom_scale = (4.5, 2, 2), geom_pos = (.4, 0, 0.3), text = "Sound", text_font = self.state.font, text_scale = (0.8, 0.9), scale = .1, pos = (-0.1, 0, 0.55), relief = None, state = DGG.DISABLED ) self.sound.setAlphaScale (0) self.keyboard = DirectButton(geom = self.state.bt_yellow, geom_scale = (6.8, 2, 2.2), geom_pos = (.6, 0, 0.3), text = "Keyboard", text_font = self.state.font, text_scale = (0.8, 0.9), scale = .1, pos = (-0.1, 0, 0.55), relief = None, state = DGG.DISABLED ) self.keyboard.setAlphaScale (0) self.screen = DirectButton(geom = self.state.bt_yellow, geom_scale = (4.7, 2, 2), geom_pos = (.4, 0, 0.3), text = "Screen", text_font = self.state.font, text_scale = (0.8, 0.9), scale = .1, pos = (-0.1, 0, 0.55), relief = None, state = DGG.DISABLED ) self.screen.setAlphaScale (0) self.back = DirectButton(geom = self.state.bt_yellow, geom_scale = (4, 2, 2), geom_pos = (.4, 0, 0.3), text = "Back", text_font = self.state.font, text_scale = (0.8, 0.9), scale = .1, pos = (-0.1, 0, 0.55), relief = None, state = DGG.DISABLED ) self.back.setAlphaScale (0) #Movement task creation self.move_task = task.sequence( task.parallel( task.sinusoid (lambda x: self.sound.setPos ((x*0.55)-0.1, 0, 0.55+(x*0.25))), task.sinusoid (lambda x: self.sound.setAlphaScale (x)), task.sinusoid (lambda x: self.keyboard.setPos ((x*0.7)-0.1, 0, 0.55)), task.sinusoid (lambda x: self.keyboard.setAlphaScale (x)), task.sinusoid (lambda x: self.screen.setPos ((x*0.65)-0.1, 0, 0.55-(x*0.25))), task.sinusoid (lambda x: self.screen.setAlphaScale (x)), task.sinusoid (lambda x: self.back.setPos ((x*0.65)-0.1, 0, 0.55-(x*0.5))), task.sinusoid (lambda x: self.back.setAlphaScale (x)) ), task.run (lambda: self.do_enable ()) ) self.do_connect () #The option_menu is set as active self.active = True return self.move_task
def do_pigeon_setup(self): super(PatrolState, self).do_pigeon_setup() self.tasks.add( task.sequence(task.wait(random.uniform(15, 30)), task.run(self.next_state)))
def do_pigeon_setup(self): self.tasks.add(task.sequence(task.wait(2.), task.run(self.kill))) self.manager.pigeon_sweeping = False
def do_connect (self): # Buttons task assigment if self.type == 'main': self.start["command"] = lambda: self.state.tasks.add( task.sequence( task.run (self.do_disable_this), task.parallel ( self.options_menu.do_destroy (), self.credits_menu.do_destroy (), task.run (self.state.to_smile), ), task.run (lambda: self.state.manager.leave_state ('game')) )) self.exit["command"] = lambda: self.state.tasks.add (task.sequence( task.run (self.do_disable_this), task.parallel( self.options_menu.do_destroy (), self.credits_menu.do_destroy (), task.run (self.state.to_smile), ), task.run (self.state.manager.leave_state) )) self.state.events.event ('panda-escape').connect (lambda: self.state.tasks.add (task.sequence ( task.delay (), task.run (self.exit["command"])))) if self.type == 'ingame': self.start["command"] = lambda: self.state.tasks.add( task.sequence( task.run (self.do_disable_this), task.parallel ( self.options_menu.do_destroy (), self.credits_menu.do_destroy (), task.run (self.state.to_smile), ), task.run (lambda: self.state.manager.leave_state ('continue')) )) self.exit["command"] = lambda: self.state.tasks.add (task.sequence( task.run (self.do_disable_this), task.parallel ( self.options_menu.do_destroy (), self.credits_menu.do_destroy (), task.run (self.state.to_smile), ), task.run (lambda: self.state.manager.leave_state ('quit')) )) self.state.events.event ('panda-escape').connect (lambda: self.state.tasks.add (task.sequence ( task.delay (), task.run (self.start["command"])))) self.credits["command"] = lambda: self.state.tasks.add ( self.do_show_credits ()) self.options["command"] = lambda: self.state.tasks.add (task.sequence ( task.run (lambda: self.options.setProp ('state', DGG.DISABLED)), task.parallel( self.state.do_smile (), self.do_show_options (), ), task.run (lambda: self.options.setProp ('state', DGG.NORMAL)) ))
def __init__ (self, model = pigeon_model, anims = pigeon_anims, boys = [], *a, **k): super (Pigeon, self).__init__ ( geometry = geom.capsule (2, 1), #mass = mass.sphere (1, 2), model = model, anims = anims, category = pigeon_category, *a, **k) self.on_is_on_floor_change += self.on_pigeon_is_on_floor self.on_hit += self.on_pigeon_hit self.on_death += self.on_pigeon_death for boy in boys: boy.on_boy_noise += self.on_boy_noise boy.on_entity_set_position += self.on_boy_move self.physical_hpr = Vec3 (90, 0, 0) self.params = BoidParams () self.model_position = Vec3 (0, 0, -2) self.model_scale = Vec3 (0.08, 0.08, 0.08) self.model_hpr = Vec3 (180, 0, 0) self.add_state ('fly', FlyState) self.add_state ('walk', WalkState) self.add_state ('follow', FollowState) self.add_state ('fear', FearState) self.add_state ('eat', EatState) self.add_state ('hit', HitState) self.add_state ('land', LandState) self.add_state ('return', ReturnState) self.add_state ('attack', AttackState) self.model.loop ('fly') self.curr_animation = 'fly' self.anim_speed = 50 # Hack: 3D audio seems very slow, so only some pigeons emit # some kinds of sounds. if random.uniform (0, 10) < 2.: self._coo_sounds = map (self.load_sound, map (lambda x: "snd/pigeon-coo-%i.wav" % x, range (1, 5))) self.tasks.add (task.sequence ( task.wait (random.uniform (0, 20)), task.loop ( task.func_wait (partial (random.uniform, 10, 30)), task.run (lambda: random.choice (self._coo_sounds).play () )))) else: self._coo_sounds = [] if random.uniform (0, 10) < 2.: self._fly_sound = self.load_sound ('snd/pigeon-start.wav') else: self._fly_sound = None if random.uniform (0, 10) < 2.: self._fear_sound = self.load_sound ('snd/pigeon-flap.wav') else: self._fear_sound = None self.start ('land')