def __collide_controller(self, game, last): """Checks for collusions Check for collusion with walls and enemies. Kill the player if collided with enemy. The enemy dies too. """ new = self.rect for cell in pygame.sprite.spritecollide(self, game.walls, False): cell_rect = cell.rect if last.right <= cell_rect.left and new.right > cell_rect.left: new.right = cell_rect.left if last.left >= cell_rect.right and new.left < cell_rect.right: new.left = cell_rect.right if last.bottom <= cell_rect.top and new.bottom > cell_rect.top: new.bottom = cell_rect.top if last.top >= cell_rect.bottom and new.top < cell_rect.bottom: new.top = cell_rect.bottom for enemy in game.enemies.sprites(): if pygame.sprite.collide_circle(self, enemy): enemy.kill() effects.Explosion(enemy.rect.midtop, game, game.sprites) sounds.Sound('death').play() self._zero_stats() self.kill() effects.Explosion(self.rect.midtop, game, game.sprites) sounds.Sound('death').play()
def __shoot(self, gun1, events, dt, game): """Manages the shooting of the player Player shoot with pressing the SPACE key. The weapon power and bullet count depend on the level of the weapon (gun_level) Manages the weapon cooldown. """ key = pygame.key.get_pressed() if key[pygame.K_SPACE] and not self.gun_cooldown and self.can_shoot: gun_power = self._get_gun_power() idx = self.gun_level while idx > 0: gun.Gun(self.gun_type, gun_power, self.gun_speed, False, self._get_gun_position(idx), self.gun_direction, game.sprites) idx -= 1 self.gun_cooldown = self.gun_cooldown_delay self.gun_overflow += self.gun_overflow_step if self.gun_overflow >= self.gun_overflow_max: self.can_shoot = False sounds.Sound('overflow').play() sounds.Sound('shot').play() self.gun_cooldown = max(0, self.gun_cooldown - dt)
def test_sound_generate(self): # Test with self-generated data rate = 22050 dt = 1. / rate t = np.arange(0, 0.5, dt) freq = 880 x = np.sin(2 * np.pi * freq * t) sounddata = np.int16(x * 2**13) inSound = sounds.Sound(inData=sounddata, inRate=rate) inSound.play() # Test if type conversion works inSound2 = sounds.Sound(inData=x, inRate=rate) inSound2.play()
def __check_death__(self, game, gamer): """Check if the player is dead.""" if gamer.health <= 0: gamer._zero_stats() gamer.kill() effects.Explosion(gamer.rect.midtop, game, game.sprites) sounds.Sound('death').play()
def __init__(self, parent): self._init_ctrls(parent) self.mixer = sounds.Mixer() self.currTime = libitl.Prayer() self.lastDiff = -1 self.imageFond = wx.Bitmap("interface.png", wx.BITMAP_TYPE_PNG) self.bous = boussole.BoussoleFrame(self, id=wx.NewId(), pos=wx.Point(508, 107), size=wx.Size(119, 120), style=wx.TAB_TRAVERSAL, name=u'bous') self.alertFrame = AlertFrame.AlertFrame(None) self.toolTip = wx.ToolTip(u'') self.remainText = u'' self.tbicon = NotificationIcon(self) pygame.mixer.init() bism = sounds.Sound(self, 'bismilleh.ogg') bism.play() self.athan = sounds.Sound(self, 'athan.ogg') self.bip = sounds.Sound(self, 'ding.ogg') self.nextSalFont = wx.Font(13, wx.SWISS, wx.NORMAL, wx.FONTWEIGHT_BOLD, False, u'Tahoma') self.salFont = wx.Font(11, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Tahoma') self.nextSalColour = wx.Colour(255, 0, 0) self.salColour = wx.Colour(0, 0, 0) self.conf = wx.GetApp().conf self.loc = wx.GetApp().loc self.newDay() self.Mytimer.Start(1000) self.startUp = True
def test_sound_select(self): # Test with GUI inSound = sounds.Sound() inSound.play() print('hi') # Info about sound, and its display (source, rate, numChannels, totalSamples, duration, bitsPerSample) = inSound.get_info() inSound.summary() print('ho')
def __collide_controller(self, game): """Check for collusions with enemy or player. Manages the health of the enemy and the player. Manages the shield of the player. Manages the sound and graphics effects on kill. Manages game stats. Creates the bonus if enemy is killed. """ for enemy in game.enemies.sprites(): if pygame.sprite.collide_circle(self, enemy) \ and not self.is_enemy_bullet \ and self.direction == -1: self.kill() enemy.health -= self.power sounds.Sound('e_hit').play() if enemy.health <= 0: bonus.Bonus(enemy.bonus, enemy.rect.midtop, game.sprites) enemy.kill() effects.Explosion(enemy.rect.midtop, game, game.sprites) sounds.Sound('death').play() game.gamer.score += game.game_level * 1000 game.gamer.kills += 1 for gamer in game.players.sprites(): if pygame.sprite.collide_circle(self, gamer) \ and self.is_enemy_bullet: self.kill() if gamer.shield > 0: gamer.shield -= self.power sounds.Sound('shield_hit').play() if gamer.shield <= 0: gamer.health += gamer.shield gamer.shield = 0 self.__check_death__(game, gamer) gamer.shield = max(0, gamer.shield) else: gamer.health -= self.power gamer.health = max(0, gamer.health) sounds.Sound('hit').play() self.__check_death__(game, gamer)
def test_sound_write(self): # Test with self-generated data rate = 22050 dt = 1. / rate t = np.arange(0, 0.5, dt) freq = 880 x = np.sin(2 * np.pi * freq * t) sounddata = np.int16(x * 2**13) inSound = sounds.Sound(inData=sounddata, inRate=rate) # Write sound-data inSound.write_wav()
def test_sound_read(self): # Single channel, stereo, and mp3 input sound_files = ['peas.wav', 'tiger.wav', 'YouAreNotIt.mp3'] for file in sound_files: try: inSound = sounds.Sound(file) inSound.play() except sounds.NoFFMPEG_Error: pass # Also make sure that # a) also another input gets read in correctly, and # b) that floats are converted properly to integers inSound.read_sound('float_sound.wav') inSound.play()
def __reward_player(self, game): """Rewar the player with the bonus taken. If bonus is points (100/200/300) add them to the score. If bonus is weapon then add 400 point to score and add DPS. If health or shield add points and raise the health/shield. """ if self.type == self.GIFTS[0]: game.gamer.score += 100 sounds.Sound('points').play() return if self.type == self.GIFTS[1]: game.gamer.score += 200 sounds.Sound('points').play() return if self.type == self.GIFTS[2]: game.gamer.score += 300 sounds.Sound('points').play() return if self.type == self.GIFTS[3]: game.gamer.score += 400 if game.gamer.gun_level < 3: game.gamer.gun_level += 1 else: dmg_min = game.gamer.gun_powers[0] + 5 dmg_max = game.gamer.gun_powers[1] + 5 game.gamer.gun_powers = (dmg_min, dmg_max) sounds.Sound('weapon').play() return if self.type == self.GIFTS[4]: game.gamer.score += 450 game.gamer.shield = min(100, game.gamer.shield + 50) sounds.Sound('shield').play() return if self.type == self.GIFTS[5]: game.gamer.score += 500 health = random.randint(25, 50) game.gamer.health = min(100, game.gamer.health + health) sounds.Sound('heal').play() return