ot: creating game in pygame

5 views
Skip to first unread message

Vojtěch Polášek

unread,
Aug 28, 2011, 11:19:16 AM8/28/11
to soundr...@googlegroups.com
Hello,
I would like to create my own game using pygame, because it is
multiplatform. Yes, I can use BGT but pygame is free and I believe it
can run on windows and on linux as well.
However, I found several tutorials on pygame and I find them quite
useless to me, because they deal mainly with sprites, images etc. But I
would like to create pure audio game.
Can anyone recommend me some tutorial aimed at pygame and audio? Or can
anyone help me directly with some basic stuff? I can use python, I have
experiences with it, so this isn't a problem. But I need some starting kick.
For example I would like to create simple game as my first one. Standard
supershot - there is sound coming at you and you should press right
arrow key to hit it. I think this is fairly good for begining.
Thank you,
Vojtěch

SoundMUD

unread,
Aug 29, 2011, 7:33:44 AM8/29/11
to soundr...@googlegroups.com
Check the first example of my tutorial:
http://soundrts.blogspot.com/2008/01/some-pygame-examples-for-audiogame.html

The second example is a bit misleading because the loop uses pygame.event.wait() which is not the usual game loop with pygame.event.get() or pygame.event.poll().

I will try to create very soon a third example with a simple game loop.

2011/8/28 Vojtěch Polášek <kre...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "soundRTSChat" group.
To post to this group, send email to soundr...@googlegroups.com.
To unsubscribe from this group, send email to soundrtschat...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/soundrtschat?hl=en.


SoundMUD

unread,
Aug 29, 2011, 3:38:51 PM8/29/11
to soundr...@googlegroups.com
I have just added a third example to the blog. Hope it helps.

http://soundrts.blogspot.com


2011/8/29 SoundMUD <soun...@gmail.com>

SoundMUD

unread,
Aug 29, 2011, 3:42:13 PM8/29/11
to soundr...@googlegroups.com

Vojtěch Polášek

unread,
Sep 1, 2011, 8:23:02 AM9/1/11
to soundr...@googlegroups.com
Thank you very much for that tutorial.
This is something I have created this noon. It's bad, so I would be very happy if you, as experienced pygame and python programmer, could please help me.
Maybe direct connection (skype etc.) would help as well, but I don't want to spare you of your time.
I just wanted this game to play sound, then wait for imput till sounds finishes. If there is right imput, add one to score. If there is bad imput or there is none imput, just continue.
There is strange thin - I have to sleep for some time to let sound play completely. And I plaied with set_endevent, but I am not sure if I got pygame events in the right way. I couldn't find any help on event.type etc.
Can you please give me some advice?
Thank you,
Vojtěch
game.zip

SoundMUD

unread,
Sep 3, 2011, 9:20:56 AM9/3/11
to soundr...@googlegroups.com
The target sound have a 10 seconds silence at its end, so the end event is sent very late. For a strange reason the end event doesn't seem to contain the right code (code = 0), I don't know why. I don't use set_endevent often, especially with recent versions of pygame, and I'll have to check if my old code using it still works with pygame > 1.7.1.

By the way, and this is just my opinion, I don't like how pygame has evolved. The best version of pygame is in my opinion 1.7.1. The later versions have numerous regressions and unnecessary improvements, and are not strictly compatible (even if it claims to be "very compatible"). For example, with a recent pygame (and Windows XP), the bird in the example 3 sings irregularly, while with pygame 1.7.1 and Python 2.5 the bird sings regularly. It seems that the sound doesn't start when the program requests it anymore. It just starts sooner or later, and doesn't even returns a channel systematically. This is not a serious problem for visual games where sound is optional. But if you write an audio game testing reflexes and every sound doesn't start when you want, you are in trouble. The 1.7.1 Windows binary version of pygame, while officially deprecated, without a link pointing to it, and incompatible with the new installer, is still available on the official site at the following url: http://pygame.org/ftp/

Additionally, the sounds doesn't stop when you want with pygame > 1.7.1

I'll have to check if pygame > 1.7.1 have the same trouble in Linux.

Back to your game, I have removed the silences from the sounds (important) and converted them from stereo to mono (optional).
I have also changed the code a bit. Examine it and try it.

2011/9/1 Vojtěch Polášek <kre...@gmail.com>
game.zip

Vojtěch Polášek

unread,
Sep 5, 2011, 8:23:58 AM9/5/11
to soundr...@googlegroups.com
Hello,
thank you for modifications and I'm sorry, I didn't look at the length of sounds.
I would like to ask you for  general advice:
I want to create menu for this game. Does it make sense to for example create one module for game, one for menu and one for putting it all together?
I noticed that soundrts has lots of modules, however soundrts is somewhat much larger than my nameless game. What are you for example using modules for?
And Now I fully understand that time.time() thing. It is nice thing.
I'll post here my progress if I can.
Thank you again,
Vojta

SoundMUD

unread,
Sep 5, 2011, 6:33:05 PM9/5/11
to soundr...@googlegroups.com
About modules, it's not easy to reply. I use modules to have smaller chunks of code, in order to limit collisions and bugs, and to edit and search code more easily. Another goal should be to reuse code by writing reusable modules, but in practice I don't reuse that much (except by cutting and pasting, shame on me, but it is how it is).

Anyway, if the game is small enough, there is no need to bother about modules. This way you have one less decision to make. There are already plenty of choices with classes, functions...

Of course, if you feel comfortable about some part of your code and think it could be easily reusable as a module for another game, feel free to try. But don't bother too much because writing a good library is harder than writing a game. Especially if your main goal is to write a game.

2011/9/5 Vojtěch Polášek <kre...@gmail.com>

Vojtěch Polášek

unread,
Oct 3, 2011, 10:20:50 AM10/3/11
to soundr...@googlegroups.com
Hello,
I made some progress. However, now I would like to create my own module for speech. This module will receive number and prononce it via preerecorded sound files in og.
But do I need to initialise display in this module if I know that it will be imported to some program with display already activated?
Thank you,
Vojta

SoundMUD

unread,
Oct 3, 2011, 5:56:05 PM10/3/11
to soundr...@googlegroups.com
Hello,
You don't need to initialize the display twice. Initialize the display once, in your main module for example.
Jean-Luc

2011/10/3 Vojtěch Polášek <kre...@gmail.com>

Vojtěch Polášek

unread,
Dec 17, 2011, 3:57:16 AM12/17/11
to soundr...@googlegroups.com
Hi,
I've made some progress. I have even written my own algorithm for speaking numbers recorded as ogg files.
But now when someone mentioned that accessible output python package, it is not neccessary any more. I would like to distribute my game as zip archive.
How to use this accessible output python package in such portable way?

Thank you,
Vojta

On 6.9.2011 00:33, SoundMUD wrote:

SoundMUD

unread,
Dec 20, 2011, 4:55:06 AM12/20/11
to soundr...@googlegroups.com
Portable? What is the name of this accessible output python package?

2011/12/17 Vojtěch Polášek <kre...@gmail.com>:

SoundMUD

unread,
Dec 20, 2011, 5:02:20 AM12/20/11
to soundr...@googlegroups.com
OK, I found it again: http://pypi.python.org/pypi/accessible_output/0.5.5
I thought you were developping for Linux.
Try py2exe to package the game.

2011/12/20 SoundMUD <soun...@gmail.com>:

Vojtěch Polášek

unread,
Dec 20, 2011, 5:13:46 AM12/20/11
to soundr...@googlegroups.com
Hi,
I try to be crossplatform. For example as your soundrts.
but I don't want for all people to install this accessible python
package to use it. So i would like to include it somehow in my game archive.
Is it enough to include folder with modules and just inport them?
Thank you,
Vojta

SoundMUD

unread,
Dec 20, 2011, 5:26:48 AM12/20/11
to soundr...@googlegroups.com
Hi,
Sometimes including the folder works. There are dll in lib, I don't
know if you would need them.
Anyway, if you don't want people to install this package, then you
probably don't want them to install Python either. That's why py2exe
is probably a solution, or package all manually but I never tried.
Jean-Luc

2011/12/20 Vojtěch Polášek <kre...@gmail.com>:

Vojtěch Polášek

unread,
Dec 26, 2011, 11:40:46 AM12/26/11
to soundr...@googlegroups.com
Hello,
I have made further progress in creating my first game.
Here it is, I didn't know about accessible_output python module, so I
prerecorded numbers. check my algorithm, what do you think about using
dictionaries for speaking of numbers? I have to check your code to learn
something new.
But I have big problem - when I run game.py it runs well. But when I run
game.pyc sounds aren't playing, there are only slight cracks but no sound.
Where can be the problem?
Thank you very much,
Vojta
game.zip

Vojtěch Polášek

unread,
Dec 26, 2011, 11:41:28 AM12/26/11
to soundr...@googlegroups.com
Oh yes and I forgot to record zero:-) Don't be scared.
Vojta

On 20.12.2011 11:26, SoundMUD wrote:

SoundMUD

unread,
Dec 27, 2011, 12:10:09 PM12/27/11
to soundr...@googlegroups.com
If numbers work then it's OK, but try to use a synthesized speech
engine or a screen reader or an accessible dialog like wxPython.
Maybe a different Python is used with .pyc
Anyway, the game works on a netbook with python 2.4 and pygame 1.7.1.

2011/12/26 Vojtěch Polášek <kre...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages