Re: [pygame] Re: error on mac

2007-10-10 Thread Ian Mallett
I'm not familiar with pygame or python on mac, but a segmentation fault
happens when a program tries to read non-existent data from video memory.
The only thing I can think of is that your surfaces are invalid; you didn't
make them right?
Ian


[pygame] Re: error on mac

2007-10-10 Thread flyaflya
I find this error just happen in full screen mode, even I use the newest
version get from svn.
This error some like the memory or (video memory)  question. Like more
memory lost with the game running.
Hope this bug can be fixed!

On 10/7/07, flyaflya <[EMAIL PROTECTED]> wrote:
>
> I use pygame 1.8pre, my game work fine on windows, but on mac, it ofter
> quit in 4 or 5 minutes with error message:
>
> pygame.error: display surface quit
> Fatal Python error: (pygame parachute) segmentation Fault
>
> This error appear when blit a surface to the screen after the programe run
> 4 or 5 mintues.
> I use pygame 1.8pre for mac download from here: 
> http://pythonmac.org/packages/py24-fat/index.html
>
> Maybe this verion is too old and has bugs, can anyone help me solve this
> question? has anyone bulit a new verion pygame for mac ?
>
> --
> http://www.flyaflya.com




-- 
http://www.flyaflya.com


Re: [pygame] pygame.init before pygame.mixer.init?

2007-10-10 Thread Brian Fisher
Hi Clare,

comments below

On 10/10/07, Clare Richardson <[EMAIL PROTECTED]> wrote:
> I writing a program to simply play one sound (see below for the code),
> and came across some interesting behavior.  If I call pygame.init()
> before pygame.mixer.init(), I don't hear any sound playing.  However if
> I call pygame.init *after* pygame.mixer.init (as below), the sound will
> play.
>
> Is this a known behavior?  What's causing the problem?  I understand
> that I don't need pygame.init to just play a sound, but I don't think it
> should matter if I call it.
>
The behavior you describe may very well be a bug, and is something
that should probably be fixed - and if some SDL and/or pygame source
programmer repro's it with your sample code, it probably will get
fixed.


However, I don't think calling pygame.mixer.init is ever really a good
thing, and you probably shouldn't bother. There is another function,
pygame.mixer.pre_init, which takes the same args as pygame.mixer.init,
and is specifically designed to be called before pygame.init

Basically if you are calling mixer.init without args... well I don't
think there is any benefit to doing so, and so you might be happier if
you don't

If you are calling it with args, well try calling
pygame.mixer.pre_init instead, just before your pygame.init call,
cause it will make sure your mixer gets init once only, the right way
for your given args you want to use.


Re: [pygame] pygame.init before pygame.mixer.init?

2007-10-10 Thread RR4CLB

Hi Clare,

I am curious about this. If you do the mixer.init after the pygame one, 
place this inside the parens and se if it works. Also, the get_busy can fail if 
the mode of the mixer is set wrong, and that may be what is going on. If the 
channel mode is wrong, the busy will never get set true.

I think the pygame.init is erasing all modes for the mixer. So you would 
have to place the modes in since the pygame.init erased them.
Try and see if that fixes it. I had a 
problem with the get_busy and discovered that might just be the issue.

Insert this into the mixer.init after the pygame init and see if it works.
pygame.mixer.init(21024) # (freq, size, stereo, buffersize)



# 1=mono, 2=stereo and 1024 buf size, 2050 for 16 bit
pygame.mixer.init(21024) # 2 for stereo and 1024 for Buf Size
- Original Message - 
From: Clare Richardson 
To: pygame-users@seul.org 
Sent: Wednesday, October 10, 2007 5:27 PM
Subject: RE: [pygame] pygame.init before pygame.mixer.init?


I tried running your code and don't hear anything playing.  I added back 
pygame.mixer.init() before pygame.init() in your code, and it played.

-- Clare

 




From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Mallett
Sent: Wednesday, October 10, 2007 4:18 PM
To: pygame-users@seul.org
Subject: Re: [pygame] pygame.init before pygame.mixer.init?

 

The simplest thing to do is:

---
import pygame
from pygame.locals import *
pygame.init()
sound = pygame.mixer.Sound("bark.wav")
sound.play()
while pygame.mixer.get_busy ():
   pass
---

...because "pygame.locals" is everything you'll need: the keys module, 
surfaces, sound, etc.  This way you don't have to do one line of code for every 
submodule you want to import: 


import pygame.key
import pygame.mixer
import pygame.draw
import pygame.image
import pygame.font
import pygame.mouse
--is = to:---
from pygame.locals import *
---

I recommend doing this.  I've been programming many times and realized that I 
hadn't imported all the necessary modules.  Opps.  Especially for simplicity, 
use "from pygame.locals import *"

Anyway, about your question:  Your first line, "pygame.mixer.init()" imports 
pygame.mixer (you can't init a non-loaded module), and then inits it.  Your 
next line, "pygame.init()" inits all of the imported modules and pygame.  So, 
here's what your code is doing:

pygame.mixer.init()  #imports pygame.mixer and inits pygame.mixer
pygame.init ()  #inits all imported modules and pygame. (This re-inits 
pygame.mixer)

One way to check would be to change the first line:

-
pygame.mixer.init()
-becomes--
import pygame.mixer


which will still work, but would not init the module, and so would be more 
efficient.

Ian






No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.488 / Virus Database: 269.14.6/1061 - Release Date: 10/10/2007 
8:43 AM



Re: [pygame] pygame.init before pygame.mixer.init?

2007-10-10 Thread Ethan Glasser-Camp
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Clare Richardson wrote:
> Is this a known behavior?  What's causing the problem?  I understand
> that I don't need pygame.init to just play a sound, but I don't think it
> should matter if I call it.

Hi,

I just ran your code, and it played the sound even without
pygame.mixer.init(). What OS, pygame version, etc. are you using?

Ethan
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHDUg0hRlgoLPrRPwRAvJtAJ9BODUhAF8ia6jLRdUPOHP/OHiGygCdFhBS
gpIdhhzRJIiDlHt7d8BfXrU=
=F2JG
-END PGP SIGNATURE-


RE: [pygame] pygame.init before pygame.mixer.init?

2007-10-10 Thread Clare Richardson
I tried running your code and don't hear anything playing.  I added back
pygame.mixer.init() before pygame.init() in your code, and it played.

-- Clare

 



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ian Mallett
Sent: Wednesday, October 10, 2007 4:18 PM
To: pygame-users@seul.org
Subject: Re: [pygame] pygame.init before pygame.mixer.init?

 

The simplest thing to do is:

---
import pygame
from pygame.locals import *
pygame.init()
sound = pygame.mixer.Sound("bark.wav")
sound.play()
while pygame.mixer.get_busy ():
   pass
---

...because "pygame.locals" is everything you'll need: the keys module,
surfaces, sound, etc.  This way you don't have to do one line of code
for every submodule you want to import: 


import pygame.key
import pygame.mixer
import pygame.draw
import pygame.image
import pygame.font
import pygame.mouse
--is = to:---
from pygame.locals import *
---

I recommend doing this.  I've been programming many times and realized
that I hadn't imported all the necessary modules.  Opps.  Especially for
simplicity, use "from pygame.locals import *"

Anyway, about your question:  Your first line, "pygame.mixer.init()"
imports pygame.mixer (you can't init a non-loaded module), and then
inits it.  Your next line, "pygame.init()" inits all of the imported
modules and pygame.  So, here's what your code is doing:

pygame.mixer.init()  #imports pygame.mixer and inits pygame.mixer
pygame.init ()  #inits all imported modules and pygame. (This re-inits
pygame.mixer)

One way to check would be to change the first line:

-
pygame.mixer.init()
-becomes--
import pygame.mixer


which will still work, but would not init the module, and so would be
more efficient.

Ian



Re: [pygame] pygame.init before pygame.mixer.init?

2007-10-10 Thread Ian Mallett
The simplest thing to do is:

---
import pygame
from pygame.locals import *
pygame.init()
sound = pygame.mixer.Sound("bark.wav")
sound.play()
while pygame.mixer.get_busy():
   pass
---

...because "pygame.locals" is everything you'll need: the keys module,
surfaces, sound, etc.  This way you don't have to do one line of code for
every submodule you want to import:


import pygame.key
import pygame.mixer
import pygame.draw
import pygame.image
import pygame.font
import pygame.mouse
--is = to:---
from pygame.locals import *
---

I recommend doing this.  I've been programming many times and realized that
I hadn't imported all the necessary modules.  Opps.  Especially for
simplicity, use "from pygame.locals import *"

Anyway, about your question:  Your first line, "pygame.mixer.init()" imports
pygame.mixer (you can't init a non-loaded module), and then inits it.  Your
next line, "pygame.init()" inits all of the imported modules and pygame.
So, here's what your code is doing:

pygame.mixer.init()  #imports pygame.mixer and inits pygame.mixer
pygame.init()  #inits all imported modules and pygame. (This re-inits
pygame.mixer)

One way to check would be to change the first line:

-
pygame.mixer.init()
-becomes--
import pygame.mixer


which will still work, but would not init the module, and so would be more
efficient.

Ian


Re: [pygame] Free chapter of my book

2007-10-10 Thread Kai Kuehne


On Oct 4, 2007, at 10:02 PM, Will McGugan wrote:


Hi folks,

I've just posted a free chapter from my book 'Beginning Game  
Development with Python and Pygame' on my blog.


http://www.willmcgugan.com/2007/10/04/free-chapter-of-beginning- 
game-development-with-python-and-pygame/


Thanks to Richard Jones for doing an excellent job as a technical  
reviewer!


Regards,

Will McGugan


On my wishlist, thanks Will! :)



[pygame] pygame.init before pygame.mixer.init?

2007-10-10 Thread Clare Richardson
I writing a program to simply play one sound (see below for the code),
and came across some interesting behavior.  If I call pygame.init()
before pygame.mixer.init(), I don't hear any sound playing.  However if
I call pygame.init *after* pygame.mixer.init (as below), the sound will
play.

Is this a known behavior?  What's causing the problem?  I understand
that I don't need pygame.init to just play a sound, but I don't think it
should matter if I call it.

Thanks!
Clare Richardson

---

import pygame

pygame.mixer.init()
pygame.init()

sound = pygame.mixer.Sound("bark.wav")
sound.play()

while pygame.mixer.get_busy():
pass

pygame.mixer.quit()


[pygame] Keyboard Events and Labels...

2007-10-10 Thread RR4CLB

To Blind/Sightless users:

I am doing this to learn but also to use the computer with sound in python 
and pygame. This is my latest version to capture key events and also say what I 
want for that key. The dictionary for this is ideal and will expand much more 
when this game gets into the game itself. 
I noticed that some people had mentioned something about capturing keys but 
not knowing the sequence, but when having the keydown you can place things into 
a stack, (list,) that pushes on and off in the sequence you received them. Or 
in other words a FIFO which is a first in and first out stack that keeps things 
in line if you so wish.
I have some labels now that will change later. The .wav files are my voice 
but those will change later.

So this is an example on how to capture key events using both the manager 
and key events inside the captured keydown event. A dictionary is perfect for 
this. Which will store many modules in the future.

# TREK.PY WRITTEN: 10/06/2007 LAST MODIFY: 10/010/2007
# THIS PYTHON SCRIPT TESTS KEYS BY DICTIONARY KEY LOOK-UP.
# THE DICTIONARY IS CALLED KEY_DIC!
# ALL KEYS IN UPPER OR LOWER CASE USE WAV FILES TO SAY KEY!
# IF NOT IN DICTIONARY IT FAILS AND DOES NOT SAY KEY!
# DEFAULTS TO ESCAPE KEY IN DICTIONARY AND DISPLAYS - NOT ASSIGNED!
# IT STARTS WITH BACKGROUND BRIDGE SOUND LOADED WITH SCREEN 
# AND EXITS WITH A FAIL SOUND!

# Import the necessary ocempgui parts.
from ocempgui.object import ActionListener
from ocempgui.widgets import *
from ocempgui.widgets.Constants import *
from pygame.locals import *
import os.path
import sys
import pygame.mixer, pygame.time, pygame.key

# ALL GLOBAL VARIABLES ARE IN CAPS!
Q_MIXER = pygame.mixer
Q_TIME = pygame.time
Q_Key = pygame.key


# QUADRANT OR GALAXY DISPLAY LIST!
#QUADRANT[9][9] = ""
def Q4Display():
"""FUNCTION Q4DISPLAY WILL DISPLAY QUADRANT ON CONSOLE SCREEN!
THE MATRIX WILL BE AN 8 X 8 GRID DISPLAYED.
AT THE MOMENT IT IS ONLY A TEST!"""
Sector_L = ""
for i in range (1, 9):
Sector_L += "   " + str(i) + "S   |"
for i in range (1, 9):
print str(i) + "|" + Sector_L


# DICTIONARY COMMANDS FOR KEYS PRESSED!
KEY_DIC = {chr(26):"- Not Assigned!", chr(K_ESCAPE):"Fail", 
"a":"LOC", "b":"BAS", "c":"COM", "d":"DIR", 
"e":"ENM", "f":"PRB", "g":"GAL", 
"k":"KLI", "l":"LRS", "n":"NAV", "p":"PHA", 
"r":"CAL", "s":"SRS", "t":"TOR", "w":"WARP"}

# choose a desired audio format
# (freq, size, stereo, buffersize)
# 1=mono, 2=stereo and 1024 buf size, 2050 for 16 bit
Q_MIXER.init(21024) #raises exception on fail

# playsound function
def play_sound (File4Sound, Repeats, Max4Time):
"""PLAY_SOUND IS THE AUDIO PLAY MIXER SOUND FUNCTION FOR ANY SOUND FILE.
This function plays one mixer channel from the games path VOICE folder.
It has 3 arguments: File Name, Repeats, and Milliseconds To Play."""
File4Sound = os.path.join("Voice", File4Sound) # PLACE IN VOICE FOLDER!
q_sound = Q_MIXER.Sound(File4Sound)
channel = q_sound.play (Repeats, Max4Time) #(loops+1, max ms-time)
# RETURN CHANNEL IN FUTURE FOR PAUSE/STOP!
#return (channel)


# Pressing a key will print the key its unicode representation to 
#the Pygame screen title bar.
# FUNCTION KEYDOWN_HANDLER CAPTURES ANY KEY PRESSED ON THE KEYBOARD AND 

PERFORMS PROGRAM!
def keydown_handler (keyevent):
"""KEYDOWN_HANDLER IS THE FUNCTION THAT CAPTURES THE EVENT OF ANY KEYS 

PRESSED.
It will say the voice of any key pressed! which is in the dictionary."""

# THIS DELAY IS NOT REALLY NEEDED.
Q_TIME.wait(200) # NEEDED FOR SCREEN READER AND TITLE BAR DISPLAY SOMETIMES!

# Initialise and Say voice of key pressed!
Ord4Key = 0
if len(keyevent.unicode) > 0: # IS THERE KEY CODE?
Ord4Key = ord(keyevent.unicode)
#else:
#re.title = "No Key Pressed!"

# TESTING FOR THE KEY CODE OF MULTIKEYS!
if Q_Key.get_pressed()[K_UP]:
re.title = "Up Arrow Key Pressed!"
play_sound("Pha.wav", 0, -1)
if Q_Key.get_pressed()[K_DOWN]:
re.title = "Down Arrow Key Pressed!"
play_sound("Tor.wav", 0, -1)

# CHECK FOR CAPS IF ALPHA KEY PRESSED! IS BUILT-IN FASTER?
if Ord4Key >= ord("A") and Ord4Key <= ord("Z"):
# CONVERT ALPHABET ORDINAL VALUE TO LOWER CASE!
Ord4Key = Ord4Key - ord("A") + K_a

# CONVERT ALPHABET ORDINAL VALUE TO CHARACTER!
Char4Key = chr( Ord4Key)

# DISPLAY GALAXY GRID ON CONSOLE!
if Char4Key == "x":
Q4Display()

# IDENTIFY DOCUMENT DESCRIPTION OF EACH FUNCTION!
if Char4Key == "i":
print play_sound.__doc__
print keydown_handler.__doc__
print object_focused.__doc__
print Q4Display.__doc__

# IS KEY PRESSED IN DICTIONARY?
if KEY_DIC.has_key( Char4Key):
# THEN FETCH KEY DICTIONARY VALUE, SOUND FILE AND PLAY IT!
Com4Key = KEY_DIC[ Char4Key]+ ".wav"
play_sound (Com4Key, 0, -1)
else:
Com4Key = KEY_DIC[ chr(26)] # FAILED, NOT ON LIST!

# Exit game command!
 

[pygame] Game templates wiki page

2007-10-10 Thread Clare Richardson
Thanks to everyone for your ideas on the game templates project!  I've
put together a description on the OLPC wiki to start collaborating:
http://wiki.laptop.org/go/Game_templates

There are definitely lots of ways to help!  Please add to any part of
the page (especially the ways to contribute section!).  For my part,
I'll start putting together simple games that can serve as a model for
each genre.

 

Thanks!

Clare Richardson
Technology and Program Coordinator
Girlstart
www.girlstart.org  

 



[pygame] pygamefont problem

2007-10-10 Thread vwf
Hello,

I have a rather old problem that fails to work after upgrading. The
problem is that font-rendering does not work correctly. The result looks
like the a television that lost horizontal sync.

I think I use old code, but I don't know what is wrong. I include a
small programme that works, but displays incorrectly (it is a Q&D cut
from my real programme). Any suggestions, or a pointer to an example I
can use?

Thanks,
F.




#!/usr/bin/env python2.4
# -*- coding: utf8 -*-

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from pygamefont import *

import sys

ESCAPE = '\033'

window = 0
n=0

def InitGL(Width, Height):
global v,l1
glShadeModel(GL_SMOOTH)
glClearColor(0.0, 0.0, 0.0, 0.5)
glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
v=PyGameBitmapFont('verdana.ttf',100)
l1=Line(v)
l1.build('1')

def ReSizeGLScene(Width, Height):
if Height == 0:
Height = 1
glViewport(0, 0, Width, Height)  
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

def DrawGLScene():
global n
n+=1
glColor3d(0,1,0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef (0.0, 0.0, -1.0)
glRasterPos2f(0,0)
l1.build(str(n))
atextLeft( l1, (-0.9,-0.4))
glutSwapBuffers()
return True

def keyPressed(*args):
global window
# If escape is pressed, kill everything.
if args[0] == ESCAPE:
sys.exit ()

def main():
global window
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
glutInitWindowSize(300, 100)
glutInitWindowPosition(0, 0)
window = glutCreateWindow("OpenGL PyGame font-tester")
glutDisplayFunc(DrawGLScene)
glutIdleFunc(DrawGLScene)
glutReshapeFunc(ReSizeGLScene)
glutKeyboardFunc(keyPressed)
InitGL(300, 100)
glutMainLoop()

print "Hit ESC key to quit."
main()