本文整理汇总了Python中sound.play函数的典型用法代码示例。如果您正苦于以下问题:Python play函数的具体用法?Python play怎么用?Python play使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了play函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
def update(self, dt, player):
if player.grounded:
if globals.keys[key.RIGHT] or globals.keys[key.LEFT]:
player.dy = self.JUMP_DY
sound.play('clunk.wav')
super(SpringPlayerMovement, self).update(dt, player)
示例2: checkForCollisions
def checkForCollisions(self, data):
shake = True
collided = pygame.sprite.spritecollideany(self, data.destroyableEntities)
if collided:
collided.isBombed(data) # tell the entity it has been bombed
if collided in data.buildings:
data.shakeScreen(20)
shake = False
if self in data.superBombs and isinstance(collided, Bullet):
# super bombs go back upwards if shot
if self.fallSpeed > 0: # is falling
self.fallSpeed = -self.fallSpeed
self.baseImage = pygame.transform.rotate(self.baseImage, 180)
sound.play("plup", 0.8)
data.score += data.scoreValues["shoot superBomb"]
return
elif isinstance(collided, Bullet):
data.score += data.scoreValues["shoot bomb"]
if collided or self.rect.bottom > data.WINDOWHEIGHT: # collided or touch bottom of screen
self.explode(data, shake)
elif self.rect.bottom < -20: # out of sight at the top (disappear silently)
self.kill()
self.smoke.kill()
if self in data.superBombs:
collided = pygame.sprite.spritecollideany(self, data.superbombableEntities)
if collided:
collided.isBombed(data)
self.explode(data, False)
示例3: at_beeper
def at_beeper(self, x, y):
'''Notifies interested parties about robot
being at a beeper.
'''
onbeepersound = os.path.join(conf.getSettings().SOUNDS_DIR, 'beep.wav')
if os.path.isfile(onbeepersound):
play(onbeepersound)
示例4: meleeAttack
def meleeAttack(self, target, damage, dt):
self.justAttacked = True
target.health -= (damage + randint(damage - damage / my.DAMAGEMARGIN, damage + damage / my.DAMAGEMARGIN)) * dt
if target.health < 1:
if self.weapon:
target.causeOfDeath = 'slain by the %s of %s.' %(self.weapon.name, self.name)
else:
target.causeOfDeath = 'killed by %s.' %(self.name)
self.animation = self.idleAnim
self.animNum = 0
else:
try:
if str(type(self.attackAnim)) == "<type 'dict'>":
if target.rect.x > self.rect.x: facing = 'right'
else: facing = 'left'
self.animation = self.attackAnim[facing]
else:
self.animation = self.attackAnim
except AttributeError:
pass # has no attack animation
if time.time() - self.lastAttackSoundTime > 1 and randint(0, 60)==0 and my.camera.isVisible(self.rect): # attack sounds
if self.weapon and self.weapon.name == 'sword':
sound.play('sword%s' %(randint(1, 4)))
if not self.weapon:
sound.play('punch%s' %(randint(1, 2)))
self.lastAttackSoundTime = time.time()
示例5: __init__
def __init__(self, name, quantity, coords, destinationGroup='default', imageName=None):
"""imageName need only be specified if it's not the same as the item name"""
pygame.sprite.Sprite.__init__(self)
self.add(my.allItems)
self.add(my.itemsOnTheFloor)
self.name, self.quantity, self.coords = name, quantity, coords
self.rect = pygame.Rect(my.map.cellsToPixels(self.coords), (my.CELLSIZE, my.CELLSIZE))
if not imageName:
imageName = self.name
self.image = Item.IMG[imageName]
self.carryImage = pygame.transform.scale(self.image, (10, 10))
if destinationGroup == 'default':
self.destinationGroup = my.storageBuildingsWithSpace
else:
self.destinationGroup = destinationGroup
self.bob = 10 # item will float up and down on the spot
self.bobDir = 'up'
self.reserved = None
self.beingCarried = False
self.lastCoords = None
if self.sound and my.camera.isVisible(self.rect):
sound.play(self.sound, 0.2)
示例6: on_button_order_clicked
def on_button_order_clicked(self, widget, is_reverse = False):
"""单词显示顺序按钮
is_reverse: 是否逆序显示
"""
play("buttonactive")
word_new_order = []
for i in range(self.words_len):
iter = self.liststore_recite.get_iter(i)
word = self.liststore_recite.get_value(iter, COLUMN_WORD)
word_new_order.append(word)
word_old_order = word_new_order[:]
if not is_reverse:
word_new_order.sort()
else:
word_new_order.sort(reverse = True)
new_order_map = []
for word in word_new_order:
new_order_map.append(word_old_order.index(word))
# print word_old_order
# print word_new_order
# print new_order_map
self.liststore_recite.reorder(new_order_map)
示例7: play_backspace_sound
def play_backspace_sound(self, widget, data = None):
"""播放退格声音或者错误提示音
"""
if self.typing_sound:
play("back")
self.character_pos -= 1
示例8: build
def build(self, dt):
"""If at site, construct it. If site is done, look for a new one."""
done = False
for site in my.buildingsUnderConstruction:
for x in range(len(site.buildersPositions)):
for y in range(len(site.buildersPositions[0])):
if done: break
if site.buildersPositionsCoords[x][y] == self.coords:
self.building = site
self.destinationSite = None
self.building.buildProgress += my.CONSTRUCTIONSPEED * dt
self.intention = 'working'
done = True
if done: break
if done: break
if not done:
if self.animation not in [self.idleAnim, self.moveAnim]:
self.animation = self.idleAnim
self.animFrame = 0
self.building = None
else:
if self.animation != Human.buildAnim:
self.animation = Human.buildAnim
self.animFrame = 0
if self.animFrame != 6:
self.buildSoundPlaying = False
elif self.animFrame == 6 and my.camera.isVisible(self.rect) and not self.buildSoundPlaying:
sound.play('hammering%s' %(randint(1, 6)))
self.buildSoundPlaying = True
if my.builtBuildings.has(self.building):
self.building = None
self.intention = None
示例9: updateWoodcutter
def updateWoodcutter(self, dt):
if self.intention in [None, 'working'] and not self.chopping and my.tick[self.tick]:
self.intention = 'working'
self.findTree()
if self.destinationSite and self.coords == self.destinationSite.coords:
self.chopping = True
self.thought = 'working'
self.destinationSite.chop(dt)
if self.animFrame != 6:
self.chopSoundPlaying = False
if self.animFrame == 6 and my.camera.isVisible(self.rect) and not self.chopSoundPlaying:
num = randint(1, 2)
sound.play('chop%s' %(num), 0.4)
self.chopSoundPlaying = True
if self.destinationSite.isDead:
self.destinationSite = None
self.intention, self.thought = None, None
self.chopping = False
if my.camera.isVisible(self.rect):
sound.play('treeFalling', 0.3)
else:
self.chopping = False
if self.animation not in [self.idleAnim, self.moveAnim]:
self.animation = self.idleAnim
self.animFrame = 0
if self.chopping:
self.destinationSite.reserved = self
self.animation = Human.chopAnim
self.lastSite = self.destinationSite
示例10: toggle_paused
def toggle_paused(self):
self.paused = not self.paused
if self.paused:
sound.pause_music()
else:
sound.resume_music()
sound.play("pause")
示例11: __init__
def __init__(self, data, startAtLeft, yPos):
pygame.sprite.Sprite.__init__(self)
self.add(data.bombers)
self.add(data.bulletproofEntities)
self.add(data.superbombableEntities)
self.imageL = data.loadImage("assets/enemies/bomber.png")
self.imageR = pygame.transform.flip(self.imageL, 1, 0)
self.droppedBomb = False
self.timeTillBombPrimed = random.uniform(Bomber.minTimeToDropBomb, Bomber.maxTimeToDropBomb)
self.lastBombDropTime = time.time()
self.rect = self.imageR.get_rect()
self.targetingRect = pygame.Rect((0, 0), (6, 10)) # BOMB SIZE
self.smoke = SmokeSpawner(data, self.rect.topleft, 10)
if startAtLeft:
self.direction = "right"
self.image = self.imageR
self.rect.topright = (0, yPos)
else:
self.direction = "left"
self.image = self.imageL
self.rect.topleft = (data.WINDOWWIDTH, yPos)
self.coords = list(self.rect.topleft) # for more accurate positioning using floats
sound.play("swoosh", 0.3)
示例12: __init__
def __init__(self, text, highScore='do not display', score='do not display', isNewHighscore=False):
self.playAgainText, self.playAgainRect = genText(text, (0, 0), ( 60, 60, 60), MenuScreen.instructionFont) # light grey
self.playAgainAlpha = 0
self.playAgainRect.midbottom = (WINDOWWIDTH / 2, WINDOWHEIGHT)
self.playAgainTargetY = WINDOWHEIGHT / 2 + 20
if highScore != 'do not display':
sound.play('booshWhaWhaWhaWha')
self.highScoreText, self.highScoreRect = genText('HIGH SCORE: ' + str(highScore), (0, 0), (255, 255, 102), MenuScreen.numberFont)
self.highScoreRect.bottomleft = (WINDOWWIDTH / 2 + 20, 0) # ^ yellow
if score != 'do not display':
self.scoreText, self.scoreRect = genText('LAST SCORE: ' + str(score), (0, 0), (255, 255, 102), MenuScreen.numberFont) # yellow
self.scoreRect.bottomright = (WINDOWWIDTH / 2 - 20, 0)
self.scoreRectsTargetY = WINDOWHEIGHT / 2 - 20
if isNewHighscore:
tempNewTextSurf, self.newTextRect = genText('NEW!', (0, 0), (250, 105, 97), MenuScreen.newHighscoreFont) # red
tempNewTextSurf.convert_alpha()
tempNewTextSurf = pygame.transform.rotate(tempNewTextSurf, -25)
self.newTextSurf = pygame.Surface(tempNewTextSurf.get_size())
self.newTextSurf.set_colorkey((0, 0, 0))
self.newTextSurf.fill((135, 206, 250))
self.newTextSurf.blit(tempNewTextSurf, (0,0))
self.isNewHighscore = isNewHighscore
self.keyboardImg = MenuScreen.keyboardImg.copy().convert_alpha()
self.keyboardRect = MenuScreen.keyboardImg.get_rect()
self.keyboardRect.midbottom = (WINDOWWIDTH / 2, WINDOWHEIGHT / 2 - 20)
示例13: pressed
def pressed():
if throttle.check():
log.info('Doorbell pressed')
sound.play()
pushover.send(config.message_text)
thingspeak.update()
else:
log.info('THROTTLING')
示例14: unbuild
def unbuild(structure):
if structure is hq or structure in artifacts:
sound.play("error")
return
structures.remove(structure)
structure.alive = False
effects.append(things.Explosion(structure.u, structure.f))
updatenetwork()
示例15: play_backspace_sound
def play_backspace_sound(self, widget, data = None):
"""播放退格声音或者错误提示音
"""
if self.typing_sound:
if not self.entry_word.get_editable():
play ("answerno")
else:
play("back")