1

Hello. Can you tell me which libraries to use for the game? I know about which pygame, pyglet, pyall, libaudioverse, I have a library that uses soundlib. I need the simplest option. And I do not know with which pygame or pyglet. As I understand it, I need to create a window, work with the keyboard. I'm using Python 2.7. Thank you in advance!

Thumbs up

2

Have you tried pyttsx, tolk and accessible_output2?

Thumbs up

3 (edited by magurp244 2017-04-01 22:05:44)

Both Pygame and Pyglet are equally good, but if you were to pick from only those two then Pyglet can give you a bit more flexibility and power as it has hardware acceleration with 3D support if you need it. Pyglet can also handle 3D audio via OpenAL with a bit of adjustment, but enabling that may not be as simple as you'd like, so going with libaudioverse or PyAL could be a more straight forward choice if you need more advanced audio. I primarily program with Pyglet, so if you like I can supply a template script demonstrating how to create a window, use the keyboard, audio, etc.

I'm also becoming quite fond of Tolk, the setup was relatively painless, it's fairly reliable, compact, and seems to pack nicely with pyinstaller. Pyttsx is also really reliable, but only supports native TTS options.

-BrushTone v1.2.8: Accessible Paint Tool

Thumbs up

4

I will not oppose the examples.

Thumbs up

5

Well, it's me or libaudioverse takes a lot of memory? When i played deathmatch i noticed some clicks on the audio even having a good machine, is the way that the game was programmed or is the propper libaudioverse?

Thumbs up

6 (edited by magurp244 2017-04-01 23:39:13)

I've not used libaudioverse so I can't say whether there's an issue with it or not. I have encountered something similar with Pyglets build in OpenAL functions at times, I think it may have had to do with the audio samples themselves, though i'm not sure.

Here's that example:

import pyglet
from pyglet.window import key

#create window
window = pyglet.window.Window(640,480,caption='Example')
#clear window
window.clear()
#key input container
key_input = []
#load sound
sound = pyglet.media.load('example.wav',streaming=False)
#load image
picture = pyglet.image.load('example.png')

#main update loop
@window.event
def update(dt):
    global key_input
#play sound
    if 'SPACE press' in key_input:
        sound.play()
#quit program
    if 'ESCAPE press' in key_input:
        window.close()
#purge key presses for next update
    if len(key_input) > 0:
        key_input = []

#capture key presses
@window.event
def on_key_press(symbol,modifiers):
    key_input.append(key.symbol_string(symbol) + " press")
    print key.symbol_string(symbol) + " press"

#capture key releases
@window.event
def on_key_release(symbol,modifiers):
    key_input.append(key.symbol_string(symbol) + " release")
    print key.symbol_string(symbol) + " release"

#draw window
@window.event()
def on_draw():
    window.clear()
    picture.blit(0,0)


#schedule and run update function
pyglet.clock.schedule_interval(update, .01)

pyglet.app.run()
-BrushTone v1.2.8: Accessible Paint Tool

Thumbs up

7 (edited by jonikster 2017-04-02 05:21:42)

Thanks for the example!
There are a few questions in this code:
    If 'SPACE press' in key_input:
As I understand it, key_input is a list. In such case, what is being checked?

Thumbs up

8

Who has a similar example with Pygame, please share it!

Thumbs up

9

Whenever a key is pressed, the functions on_key_press() and on_key_release() add a text string in to the key_input list. That particular line checks to see if the string "SPACE press" is inside that list, indicating that the space bar has been pressed.

There are other ways to doing it, that just happened to be the method I went with. For example you could also write it directly in the on_key_press function like this:

def on_key_press(symbol,modifiers):
    if symbol == key.SPACE:
        sound.play()
-BrushTone v1.2.8: Accessible Paint Tool

Thumbs up

10

Here's the same example in Pygame:

import pygame
from pygame import mixer
import sys

def Example():
#initialize pygame
    pygame.init()
#initialize sound mixer
    mixer.init()
#set window caption
    pygame.display.set_caption('Example')
#create display
    window = pygame.display.set_mode([640,480])
#load sound
    sound = mixer.Sound('example.wav')
#load image
    picture = pygame.image.load('example.png')

#main update loop
    while True:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
            #if space is pressed, play sound
                if event.key == pygame.K_SPACE:
                    sound.play()
            #if escape is pressed, quit
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit(0)

    #clear window
        window.fill([0,0,0])
    #draw picture to window
        window.blit(picture,(0,0))
    #update window
        pygame.display.update()

Example()
-BrushTone v1.2.8: Accessible Paint Tool

Thumbs up

11

Pygame seems to me more convenient. In pyglet, I do not understand where the main loop is, plus I do not know the decorators very well.

Thumbs up

12 (edited by magurp244 2017-04-02 09:04:35)

Fair enough, keep in mind though that there are different ways of writing code, these are just a few of examples. In the Pyglet example the update() function is the main loop, its called continuously by schedule_interval(). Other functions like on_key_press() wait for input and trigger events as needed. Here's a different example:

import pyglet
from pyglet.window import key

#main class
class Example(pyglet.window.Window):
    def __init__(self):
        super(Example, self).__init__(640, 480, caption="Example")
    #load a sound
        self.sound = pyglet.media.load('example.wav',streaming=False)
    #load an image
        self.picture = pyglet.image.load('example.png')
    #run our update function continuously
        pyglet.clock.schedule_interval(self.update, .01)

#primary update loop
    def update(self,dt):
    #draw screen
        self.draw()

#draw to the screen
    def draw(self):
        self.clear()
        self.picture.blit(0,0)

#capture key presses        
    def on_key_press(self,symbol,modifiers):
    #if space is pressed, play sound
        if symbol == key.SPACE:
            self.sound.play()
    #if escape pressed, quit
        if symbol == key.ESCAPE:
            self.close()

window = Example()
pyglet.app.run()

In the end it really depends on what you have in mind, you should pick and choose which library you want to use based on your current needs. If you feel Pygame is an easier fit, then go for it and see how it goes.

-BrushTone v1.2.8: Accessible Paint Tool

Thumbs up

13

Do i have to copy the openal.dll to my folder? Cause i had success setting up PyAL but when i import it i got an error saying that openal32.dll is missing.

Thumbs up

14 (edited by magurp244 2017-04-02 21:08:03)

Copying it to the same folder as your script is one way yes. Another method would be to install OpenAL on your system, though that takes a bit of effort to setup properly. If you plan on distributing your script it may be a good idea to include the OpenAL32.dll with it in case the users don't have OpenAL installed.

First you would need to install [OpenAL], then download [OpenAL Soft]. Then follow the instructions in the OpenAL Soft archive to rename and copy over the required files.

-BrushTone v1.2.8: Accessible Paint Tool

Thumbs up

15

Thank you.

Thumbs up