本文整理汇总了Python中ggame.Sound.play方法的典型用法代码示例。如果您正苦于以下问题:Python Sound.play方法的具体用法?Python Sound.play怎么用?Python Sound.play使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ggame.Sound
的用法示例。
在下文中一共展示了Sound.play方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LifeControl
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class LifeControl(Sprite):
asset = TextAsset("Lives:", fill=white)
SAsset = SoundAsset("sounds/reappear.mp3")
def __init__(self, position):
super().__init__(LifeControl.asset, position)
self.lives = LIVES
self.dispLives()
self.RespawnSound = Sound(LifeControl.SAsset)
self.RespawnSound.volume = 10
def dispLives(self):
Lives(TextAsset(str(self.lives), fill=white), (55,20))
def loseLife(self):
for x in SpaceGame.getSpritesbyClass(Lives):
x.destroy()
self.lives -= 1
self.dispLives()
if self.lives == 0:
LoseText((SCREEN_WIDTH/2,SCREEN_HEIGHT/2))
else:
RespawnText((SCREEN_WIDTH/2,SCREEN_HEIGHT/2))
classDestroy(EnemyBullet)
def respawn(self):
if self.lives > 0:
sleep(1)
for x in SpaceGame.getSpritesbyClass(RespawnText):
x.destroy()
self.RespawnSound.play()
Player((SCREEN_WIDTH/2,SCREEN_HEIGHT/2))
classDestroy(Enemy)
EnemySpawn(NUM_ENEMIES)
示例2: Bullet
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class Bullet(GravitySprite):
asset = ImageAsset("images/blast.png", Frame(0,0,8,8), 8)
pewasset = SoundAsset("sounds/pew1.mp3")
def __init__(self, app, sun, sun2):
super().__init__(Bullet.asset, (0,0), (0,0), sun, sun2)
self.visible = False
self.firing = False
self.time = 0
self.circularCollisionModel()
self.pew = Sound(Bullet.pewasset)
self.pew.volume = 10
def shoot(self, position, velocity, time):
self.position = position
self.vx = velocity[0]
self.vy = velocity[1]
self.time = time
self.visible = True
self.firing = True
self.pew.play()
def step(self, T, dT):
if self.time > 0:
self.time = self.time - dT
if self.visible:
self.nextImage(True)
super().step(T, dT)
if self.collidingWith(self.sun):
self.visible = False
if self.collidingWith(self.sun2):
self.visible = False
ExplosionSmall(self.position)
ships = []
ships = self.collidingWithSprites(Ship1)
ships.extend(self.collidingWithSprites(Ship2))
if len(ships):
if not self.firing and ships[0].visible:
ships[0].hitCount = ships[0].hitCount + 1
self.visible = False
ExplosionSmall(self.position)
if ships[0].hitCount >= 3:
ships[0].explode()
ships[0].hitCount = 0
self.visible = False
if ships[0].hitCount >= 2:
ships[0].shipThrust = int(ships[0].shipThrust)/3
elif self.firing:
self.firing = False
else:
if self.visible:
self.visible = False
self.time = 0
示例3: ExplosionSmall
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class ExplosionSmall(Sprite):
asset = ImageAsset("images/explosion1.png", Frame(0,0,128,128), 10)
boomasset = SoundAsset("sounds/explosion1.mp3")
def __init__(self, position):
super().__init__(ExplosionSmall.asset, position)
self.image = 0
self.center = (0.5, 0.5)
self.boom = Sound(ExplosionSmall.boomasset)
self.boom.play()
def step(self):
self.setImage(self.image//2) # slow it down
self.image = self.image + 1
if self.image == 20:
self.destroy()
示例4: ExplosionBig
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class ExplosionBig(Sprite):
asset = ImageAsset("images/explosion2.png", Frame(0,0,4800/25,195), 25)
boomasset = SoundAsset("sounds/explosion2.mp3")
def __init__(self, position):
super().__init__(ExplosionBig.asset, position)
self.image = 0
self.center = (0.5, 0.5)
self.boom = Sound(ExplosionBig.boomasset)
self.boom.play()
def step(self):
self.setImage(self.image//2) # slow it down
self.image = self.image + 1
if self.image == 50:
self.destroy()
示例5: Explosion
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class Explosion(Sprite):
asset = ImageAsset("images/explosion1.png", Frame(0,0,128,128), 10)
SAsset = SoundAsset("sounds/explosion1.mp3")
def __init__(self, position):
super().__init__(Explosion.asset, position)
self.fxcenter = self.fycenter = 0.5
self.frame = 0
self.ExplodeSound = Sound(Explosion.SAsset)
self.ExplodeSound.volume = 10
self.ExplodeSound.play()
def step(self):
if self.frame == 8:
self.destroy()
else:
self.frame += 1
self.setImage(self.frame)
示例6: Bullet
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class Bullet(Sprite):
asset = ImageAsset("images/blast.png", Frame(0,0,8,8), 8)
pewasset = SoundAsset("sounds/pew1.mp3")
def __init__(self, position, vx, vy):
super().__init__(Bullet.asset, position)
self.exist = True
self.circularCollisionModel()
self.pew = Sound(Bullet.pewasset)
self.pew.play()
self.appear = 1
self.fxcenter = 0.5
self.fycenter = 0
self.X = vx
self.Y = vy
def step(self):
self.visible = True
if self.exist:
self.setImage(self.appear)
self.appear += 1
if self.appear == 8:
self.appear = 1
else:
self.setImage(0)
self.x -= 15*self.X
self.y -= 15*self.Y
collides = self.collidingWithSprites(Ship2)
collides.extend(self.collidingWithSprites(Ship1))
if len(collides):
if collides[0].visible:
self.visible = False
else:
self.visible = True
if self.x < 0 or self.x > SCREEN_WIDTH or self.y < 0 or self.y >SCREEN_HEIGHT:
self.destroy()
示例7: Ship
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class Ship(GravitySprite):
R = int(input("What speed do you want the ship to turn? (2.0 is standard)")) #This is the speed at which the ship spins
bullets = int(input("How many bullets can you shoot before relodaing?")) #this is how many bullets the ship can shoot before reloading
healthcount = int(input("How many lives should each player have?"))
reappearasset = SoundAsset("sounds/reappear.mp3")
def __init__(self, asset, app, position, velocity, sun, sun2, thrust):
self.bullets = []
for i in range(Ship.bullets):
self.bullets.append(Bullet(app, sun, sun2))
super().__init__(asset, position, velocity, sun, sun2)
self.initposition = position
self.initvelocity = self.vx, self.vy
self.initrotation = self.rotation
self.app = app
self.mass = 1.0
self.circularCollisionModel()
self.imagex = 0
self.reappear = Sound(Ship.reappearasset)
self.reappear.volume = 40
self.waitspawn = 0
self.respawnplayed = False
healthpos = 'left' if position[0] < app.width/2 else 'right'
self.health = HealthBar(asset, Ship.healthcount, healthpos, app)
self.dead = False
self.hitCount = 0
self.shipThrust = thrust
def registerKeys(self, keys):
commands = ["left", "right", "forward", "fire"]
self.keymap = dict(zip(keys, commands))
[self.app.listenKeyEvent("keydown", k, self.controldown) for k in keys]
[self.app.listenKeyEvent("keyup", k, self.controlup) for k in keys]
def shootvector(self):
vel = 200 # this is the velocity of the bullets normally 150
xv = vel*(-math.sin(self.rotation))
yv = vel*(-math.cos(self.rotation))
return xv + self.vx, yv + self.vy
def controldown(self, event):
if self.visible:
command = self.keymap[event.key]
if command == "left":
self.rrate = Ship.R
elif command == "right":
self.rrate = -Ship.R
elif command == "forward":
self.thrust = self.shipThrust #this is the ship thrust
self.imagex = 1 # start the animated rockets
self.setImage(self.imagex)
elif command == "fire":
for bullet in self.bullets:
if bullet.time == 0:
bullet.shoot(self.position, self.shootvector(), 10) #ten is the number of seconds that a bullet lasts before self destructing and reappearing able to shoot
break
def controlup(self, event):
command = self.keymap[event.key]
if command in ["left", "right"]:
self.rrate = 0.0
elif command == "forward":
self.thrust = 0.0
self.imagex = 0 # stop the animated rockets
self.setImage(self.imagex)
def step(self, T, dT):
if self.waitspawn > 0:
self.waitspawn = self.waitspawn - dT
if self.waitspawn < 1 and not self.respawnplayed:
self.reappear.play()
self.respawnplayed = True
if self.waitspawn <= 0:
self.reset()
for bullet in self.bullets:
bullet.step(T, dT)
if self.visible:
super().step(T, dT)
self.rotation = self.rotation + self.rrate * dT
if self.collidingWith(self.sun):
self.explode()
if self.collidingWith(self.sun2):
self.explode()
if self.thrust != 0.0:
self.imagex = self.imagex + 1 # animate the rockets
if self.imagex == 4:
self.imagex = 1
self.setImage(self.imagex)
if (self.x < -100 or self.x > self.app.width + 100 or
self.y < -100 or self.y > self.app.height + 100):
self.explode()
def explode(self):
self.visible = False
ExplosionBig(self.position)
self.waitspawn = 5
#.........这里部分代码省略.........
示例8: Ship
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
class Ship(GravitySprite):
R = 2.0
bullets = 6
healthcount = 6
reappearasset = SoundAsset("sounds/reappear.mp3")
def __init__(self, asset, app, position, velocity, sun):
self.bullets = []
for i in range(Ship.bullets):
self.bullets.append(Bullet(app, sun))
super().__init__(asset, position, velocity, sun)
self.initposition = position
self.initvelocity = self.vx, self.vy
self.initrotation = self.rotation
self.app = app
self.mass = 1.0
self.circularCollisionModel()
self.imagex = 0
self.reappear = Sound(Ship.reappearasset)
self.reappear.volume = 40
self.waitspawn = 0
self.respawnplayed = False
healthpos = 'left' if position[0] < app.width/2 else 'right'
self.health = HealthBar(asset, Ship.healthcount, healthpos, app)
self.dead = False
def registerKeys(self, keys):
commands = ["left", "right", "forward", "fire"]
self.keymap = dict(zip(keys, commands))
[self.app.listenKeyEvent("keydown", k, self.controldown) for k in keys]
[self.app.listenKeyEvent("keyup", k, self.controlup) for k in keys]
def shootvector(self):
vel = 150
xv = vel*(-math.sin(self.rotation))
yv = vel*(-math.cos(self.rotation))
return xv + self.vx, yv + self.vy
def controldown(self, event):
if self.visible:
command = self.keymap[event.key]
if command == "left":
self.rrate = Ship.R
elif command == "right":
self.rrate = -Ship.R
elif command == "forward":
self.thrust = 40.0
self.imagex = 1 # start the animated rockets
self.setImage(self.imagex)
elif command == "fire":
for bullet in self.bullets:
if bullet.time == 0:
bullet.shoot(self.position, self.shootvector(), 10)
break
def controlup(self, event):
command = self.keymap[event.key]
if command in ["left", "right"]:
self.rrate = 0.0
elif command == "forward":
self.thrust = 0.0
self.imagex = 0 # stop the animated rockets
self.setImage(self.imagex)
def step(self, T, dT):
if self.waitspawn > 0:
self.waitspawn -= dT
if self.waitspawn < 1 and not self.respawnplayed:
self.reappear.play()
self.respawnplayed = True
if self.waitspawn <= 0:
self.reset()
for bullet in self.bullets:
bullet.step(T, dT)
if self.visible:
super().step(T, dT)
self.rotation += self.rrate * dT
if self.collidingWith(self.sun):
self.explode()
if self.thrust != 0.0:
self.imagex += 1 # animate the rockets
if self.imagex == 4:
self.imagex = 1
self.setImage(self.imagex)
if (self.x < -100 or self.x > self.app.width + 100 or
self.y < -100 or self.y > self.app.height + 100):
self.explode()
def explode(self):
self.visible = False
ExplosionBig(self.position)
self.waitspawn = 5
def reset(self):
if not self.health.dead():
self.position = self.initposition
#.........这里部分代码省略.........
示例9: Sound
# 需要导入模块: from ggame import Sound [as 别名]
# 或者: from ggame.Sound import play [as 别名]
from ggame import Sound, SoundAsset
e5 = Sound(SoundAsset("sounds/00_part1_entry-5.wav"))
e6 = Sound(SoundAsset("sounds/00_part1_entry-6.wav"))
e7 = Sound(SoundAsset("sounds/00_part1_entry-7.wav"))
e7.play()