def on_button_released(self, ev, signal): if self.frozen or not self.last_seed or self.tweener.is_tweening: if self.last_seed: self.last_seed.return_to_cell() self.last_seed = None return signal(SeedReleased()) x = round(ev.position.x) y = round(ev.position.y) lx = self.last_seed.x ly = self.last_seed.y if x == lx and y != ly: if ly - 2 == y: y += 1 elif ly + 2 == y: y -= 1 elif y == ly and x != lx: if lx - 2 == x: x += 1 elif lx + 2 == x: x -= 1 missed = False if (x, y) not in GRID: missed = True if (lx, ly) not in GRID: missed = True nx = abs(lx - x) == 1 ny = abs(ly - y) == 1 # If the seed was dropped in a cardinal direction to another seed, # swap them, signal movement start, and play the swap sound. if not missed and (nx or ny) and not (nx and ny): self.swap_seeds(x, y, lx, ly) signal(PlaySound(SOUND_SWAP)) signal(MovementStart()) # Otherwise, if there is a last seed remembered, return to its original # position. elif self.last_seed: self.last_seed.return_to_cell() # TODO... why would there not be a last seed here? if self.tweener.is_tweening: @self.tweener.when_done def on_tweening_done(): signal(MovementDone()) self.last_seed = None
def chime(t, signal): global _chime_playing if not _chime_playing: signal(PlaySound(SOUND_CHIME)) SOUND_CHIME.volume = 6.0 tween(SOUND_CHIME, 'volume', 0.0, t, easing='out_quad') _chime_playing = True def done(): global _chime_playing _chime_playing = False delay(t, done)
def on_damage_dealt(self, ev, signal): if ev.target == 'player': self.shield -= ev.dmg if self.shield < 0: self.hp += self.shield self.shield = 0 if self.hp < 0: self.hp = 0 if self.hp <= 0: signal(PlayerDeath(self)) else: tween(self, 'position', self.position - V(1, 0), 0.1, easing='in_quad') tween(self, 'position', self.position, 0.2, delay=0.1, easing='out_quad') signal(PlaySound(choice(SOUND_HURT_SET)))
def _fire_bullet(self, scene, signal): signal(PlaySound(self.fire_sound)) scene.add(Bullet(position=self.position), tags=['bullet'])