def __init__(self, c): # music is actually streamed, so we don't load it. . . so this is kinda # sorta mostly useless, for now. self.music = { "It's Melting": load_sound(c, "music/It's Melting.ogg"), "Spicy Chips": load_sound(c, "music/Spicy Chips.ogg"), "The Power Supply": load_sound(c, "music/The Power Supply.ogg"), "menu": load_sound(c, "music/menuV3.ogg"), "menu2": load_sound(c, "music/Space1 by alaupas.ogg") } self.sounds = { "Enter 1": load_sound(c, "enter 1.ogg"), "Enter 2": load_sound(c, "enter 2.ogg"), "Enter 3": load_sound(c, "enter 3.ogg"), "scroll": load_sound(c, "scroll.ogg"), "test": load_sound(c, "test.ogg") } # set volume by a factor of current volume. inputVol = 8 self.sounds["Enter 1"].set_volume(self.sounds["Enter 1"].get_volume() / inputVol) self.sounds["Enter 2"].set_volume(self.sounds["Enter 2"].get_volume() / inputVol) self.sounds["Enter 3"].set_volume(self.sounds["Enter 3"].get_volume() / inputVol) self.sounds["scroll"].set_volume(self.sounds["scroll"].get_volume() / inputVol)
def breakout(screen): # スプライトグループを作成して登録 all = pygame.sprite.RenderUpdates() # 描画用グループ blocks = pygame.sprite.Group() # 衝突判定用グループ breakout_obj.Paddle.containers = all breakout_obj.Ball.containers = all breakout_obj.Block.containers = all, blocks score_board = breakout_obj.ScoreBoard() # サウンドのロード breakout_obj.Ball.paddle_sound = loader.load_sound("wood00.wav") # パドルとの衝突音 breakout_obj.Ball.brick_sound = loader.load_sound("chari06.wav") # ブロックとの衝突音 breakout_obj.Ball.fall_sound = loader.load_sound("fall06.wav") # ボールを落とした音 # パドルを作成 paddle = breakout_obj.Paddle() # ボールを作成するとスプライトグループallに自動的に追加される breakout_obj.Ball(paddle, blocks, score_board) # ブロックを作成 # 自動的にblocksグループに追加される for x in range(1, 11): # 1列から10列まで for y in range(1, 6): # 1行から5行まで breakout_obj.Block(x, y) breakout_obj.life = 3 clock = pygame.time.Clock() while breakout_obj.game_state == PLAY: clock.tick(60) screen.fill((0,0,0)) all.update() all.draw(screen) score_board.draw(screen) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit()
def __init__(self): pygame.init() #Height and width for game window self.width = 520 self.height = 650 #Font for in-game text self.font = pygame.font.Font(None, 30) self.font2 = pygame.font.Font(None, 48) #Variables for timer self.timer = pygame.time.Clock() self.frameRate = 60 self.frameCount = 0 #use for pausing game self.paused = 0 #Initialize game level self.level = 1 self.screen = pygame.display.set_mode((self.width, self.height)) #Game sound self.sound = loader.load_sound('Jump-SoundBible.com-1007297584.wav') self.menu = MainMenu.MainMenu(self.screen, ('Start', 'Quit'), self.font2)
pygame.mixer.music.play() # set up pygame, the window, and the mouse cursor windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) iconImage = pygame.image.load('data/pygame_icon.bmp').convert() icon = pygame.transform.scale(iconImage, (32, 32)) pygame.display.set_icon(icon) pygame.display.set_caption('JShooter') pygame.mouse.set_visible(False) mainClock = pygame.time.Clock() # set up font pygame.font.init() font = pygame.font.Font('data/freesansbold.ttf', 32) # set up sounds gameOverSound = loader.load_sound('gameover.wav') #TODO build some sort of music handling queue / control object. pygame.mixer.music.load('./data/theme.ogg') #pygame.mixer.music.load('data/background.mid') # set up images player = player.Player() proxy = proxy.Proxy() baddieImage, baddieRect = loader.load_png('baddie.png') bulletImage, bulletRect = loader.load_png('bullet.png') powerupImage, powerupRect = loader.load_png('powerup.png') # show the "Start" screen drawText('JShooter', font, windowSurface, (WINDOWWIDTH / 10), (WINDOWHEIGHT / 10)) drawText('Mouse Move', font, windowSurface, (WINDOWWIDTH / 10), (WINDOWHEIGHT / 10)+50) drawText('Mouse Button1 Shoots', font, windowSurface, (WINDOWWIDTH / 10), (WINDOWHEIGHT / 10)+100)
import pygame from pygame.locals import * import bullet import loader import math SHIP_IMAGE = pygame.transform.smoothscale(loader.load_image("ship.png"), (50, 50)) BULLET_SOUND = loader.load_sound("bullet.wav") class Ship(pygame.sprite.Sprite): def __init__(self, pos): pygame.sprite.Sprite.__init__(self) self.image = SHIP_IMAGE self.rect = self.image.get_rect() self.rect.center = pos self.bullets = pygame.sprite.RenderUpdates() self.reload = 0 self.angle = 0 def update(self): keys = pygame.key.get_pressed() if keys[K_UP]: self.rect.center = (self.rect.center[0] + 5 * math.cos((self.angle + 90) * math.pi / 180.0), self.rect.center[1] - 5 * math.sin((self.angle + 90) * math.pi / 180.0)) if keys[K_DOWN]: self.rect.center = (self.rect.center[0] - 5 * math.cos((self.angle + 90) * math.pi / 180.0), self.rect.center[1] + 5 * math.sin((self.angle + 90) * math.pi / 180.0)) if keys[K_LEFT]:
def load_sounds(self): """サウンドのロード""" Player.shot_sound = loader.load_sound("shot.wav") Alien.kill_sound = loader.load_sound("kill.wav") Player.bomb_sound = loader.load_sound("bomb.wav")
def play(self): sound = load_sound(self.soundfile) sound.play(0) # Sound.play(loops=0, maxtime=0, fade_ms=0)