コード例 #1
0
def main():
    #cause I don't want to pass these around
    global WINDOW, REN, SPRITE_FACTORY, SPRITE_RENDERER, MUSIC

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)

    WINDOW = ext.Window("Tetromino", size=(WINDOWWIDTH, WINDOWHEIGHT))
    REN = ext.Renderer(WINDOW)
    WINDOW.show()

    font_file = sysfont.get_font("freesans", sysfont.STYLE_BOLD)
    font_manager = ext.FontManager(font_file, size=18)

    #fontmanager=font_manager will be default_args passed to every sprite creation method
    SPRITE_FACTORY = ext.SpriteFactory(renderer=REN,
                                       fontmanager=font_manager,
                                       free=True)
    SPRITE_RENDERER = SPRITE_FACTORY.create_sprite_render_system(WINDOW)

    sdlmixer.Mix_Init(sdlmixer.MIX_INIT_OGG)
    sdlmixer.Mix_OpenAudio(22050, sdlmixer.MIX_DEFAULT_FORMAT, 2, 1024)
    #BEEP1 = sdlmixer.Mix_LoadWAV(b"beep1.ogg")

    showTextScreen("Tetromino")
    while True:
        if random.randint(0, 1) == 0:
            MUSIC = sdlmixer.Mix_LoadMUS(b"tetrisb.mid")
        else:
            MUSIC = sdlmixer.Mix_LoadMUS(b"tetrisc.mid")
        sdlmixer.Mix_PlayMusic(MUSIC, -1)
        runGame()
        sdlmixer.Mix_HaltMusic()
        showTextScreen("Game Over")
コード例 #2
0
ファイル: audio.py プロジェクト: michael-lazar/playscii
 def __init__(self, app):
     self.app = app
     # initialize audio
     sdlmixer.Mix_Init(sdlmixer.MIX_INIT_OGG | sdlmixer.MIX_INIT_MOD)
     sdlmixer.Mix_OpenAudio(self.sample_rate, sdlmixer.MIX_DEFAULT_FORMAT,
                            2, 1024)
     self.reset()
     # sound callback
     # retain handle to C callable even though we don't use it directly
     self.sound_cb = ctypes.CFUNCTYPE(None,
                                      ctypes.c_int)(self.channel_finished)
     sdlmixer.Mix_ChannelFinished(self.sound_cb)
コード例 #3
0
ファイル: main.py プロジェクト: eyedeekay/surviveler
    def __enter__(self):
        LOG.debug('Initializing SDL context')
        sdl.SDL_Init(sdl.SDL_INIT_EVERYTHING)

        LOG.debug('Initializing SDL mixer')
        if sdlmixer.Mix_OpenAudio(44100, sdlmixer.MIX_DEFAULT_FORMAT, 2, 1024):
            raise RuntimeError(
                'Cannot open mixed audio: {}'.format(sdlmixer.Mix_GetError()))

        if sdlmixer.Mix_Init(0) == -1:
            raise RuntimeError(
                'Cannot initialize mixer: {}'.format(sdlmixer.Mix_GetError()))

        return self
コード例 #4
0
ファイル: sdlinfo.py プロジェクト: ppb/pursuedpybear
def check_audio_codecs():
    sdl2.SDL_Init(sdl2.SDL_INIT_AUDIO)
    try:
        libs = {
            'FLAC': sdlmixer.MIX_INIT_FLAC,
            'MOD': sdlmixer.MIX_INIT_MOD,
            'MP3': sdlmixer.MIX_INIT_MP3,
            'OGG': sdlmixer.MIX_INIT_OGG,
            'MIDI': sdlmixer.MIX_INIT_MID,
            'OPUS': sdlmixer.MIX_INIT_OPUS
        }
        for lib, flags in libs.items():
            sdlmixer.Mix_SetError(b"")
            ret = sdlmixer.Mix_Init(flags)
            err = sdlmixer.Mix_GetError()
            if err:
                yield lib, err.decode('utf-8')
            if ret & flags == flags:
                yield lib, None
            else:
                yield lib, True
            sdlmixer.Mix_Quit()
    finally:
        sdl2.SDL_Quit()
コード例 #5
0
ファイル: sdlmixer_test.py プロジェクト: josewtf01/py-sdl2
 def setUpClass(cls):
     sdlmixer.Mix_Init(0)
コード例 #6
0
def main():
	#cause I don't want to pass these around
	global REN, SPRITE_FACTORY, SPRITE_RENDERER
	global CLICKEDBUTTON, BEEP1, BEEP2, BEEP3, BEEP4

	sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO|sdl2.SDL_INIT_AUDIO)

	window = sdl2.ext.Window("Simulate", size=(WINDOWWIDTH, WINDOWHEIGHT))
	REN = sdl2.ext.Renderer(window)
	REN.blendmode = sdl2.SDL_BLENDMODE_BLEND
	
	window.show()

	font_file = sysfont.get_font("freesans", sysfont.STYLE_BOLD)
	font_manager = sdl2.ext.FontManager(font_file, size=16)

	#fontmanager=font_manager will be default_args passed to every sprite creation method
	SPRITE_FACTORY = sdl2.ext.SpriteFactory(renderer=REN, fontmanager=font_manager, free=True)
	SPRITE_RENDERER = SPRITE_FACTORY.create_sprite_render_system(window)



	sdlmixer.Mix_Init(sdlmixer.MIX_INIT_OGG)
	sdlmixer.Mix_OpenAudio(44100, sdlmixer.MIX_DEFAULT_FORMAT, 2, 1024)
	BEEP1 = sdlmixer.Mix_LoadWAV(b"beep1.ogg")
	BEEP2 = sdlmixer.Mix_LoadWAV(b"beep2.ogg")
	BEEP3 = sdlmixer.Mix_LoadWAV(b"beep3.ogg")
	BEEP4 = sdlmixer.Mix_LoadWAV(b"beep4.ogg")

	#channel = sdlmixer.Mix_PlayChannel(-1, BEEP1, 0)

	# Initialize some variables for a new game
	pattern = [] # stores the pattern of colors
	currentStep = 0 # the color the player must push next
	lastClickTime = 0 # timestamp of the player's last button push
	score = 0
	# when False, the pattern is playing. when True, waiting for the player to click a colored button:
	waitingForInput = False

	#directions text sprite
	info_text = make_text(SPRITE_FACTORY, "Match the pattern by clicking on the button or using the Q, W, A, S keys.", 10, WINDOWHEIGHT-25)

	CLICKEDBUTTON = []
	while True:
		REN.fill((0, 0, WINDOWWIDTH, WINDOWHEIGHT), BGCOLOR)
		drawButtons()

		score_text = make_text(SPRITE_FACTORY, "Score: "+str(score), WINDOWWIDTH - 100, 10)
		SPRITE_RENDERER.render([score_text, info_text])

		handle_events()

		if not waitingForInput:
			# play the pattern
			sdl2.SDL_Delay(1000)
			pattern.append(random.choice((YELLOW, BLUE, RED, GREEN)))
			for button in pattern:
				handle_events()
				flashButtonAnimation(button)
				sdl2.SDL_Delay(FLASHDELAY)
			waitingForInput = True
		else:
			# wait for the player to enter buttons
			if CLICKEDBUTTON and CLICKEDBUTTON[0] == pattern[currentStep]:
				# pushed the correct button
				flashButtonAnimation(CLICKEDBUTTON[0])
				currentStep += 1
				lastClickTime = sdl2.SDL_GetTicks()
				
				#could replace with collections.deque but premature optimizations and all that
				CLICKEDBUTTON.pop(0)

				if currentStep == len(pattern):
					# pushed the last button in the pattern
					changeBackgroundAnimation()
					score += 1
					waitingForInput = False
					currentStep = 0 # reset back to first step
					#CLICKEDBUTTON.clear() clear added in 3.3! ... I'm surprised it hasn't been there forever since it's way better than del l[:] or l[:] = []
					#and it parallels other collection clear functions
					del CLICKEDBUTTON[:]


			elif (CLICKEDBUTTON and CLICKEDBUTTON[0] != pattern[currentStep]) or (currentStep != 0 and sdl2.SDL_GetTicks() - TIMEOUT*1000 > lastClickTime):
				# pushed the incorrect button, or has timed out
				gameOverAnimation()
				# reset the variables for a new game:
				pattern = []
				#CLICKEDBUTTON.clear()
				del CLICKEDBUTTON[:]
				currentStep = 0
				waitingForInput = False
				score = 0
				sdl2.SDL_Delay(1000)
				changeBackgroundAnimation()


		sdl2.SDL_Delay(1000//FPS)

	
	shutdown()
コード例 #7
0
 def __init__(self, model):
     sdlmixer.Mix_Init(0)
     sdlmixer.Mix_OpenAudio(22050, sdlmixer.MIX_DEFAULT_FORMAT, 2, 1024)
     self.model = model
     self.loadaudiofx()
     self.player = self.play()