Pygame Help


Geevowitz

Still Fresh
Joined
Nov 17, 2005
Messages
18
Age
34
Website
Visit site
Hey,
I just finished a small pygame game and I need to know how to make a .gpe file that will tell the gp2x to run my game. I have no clue how to do this, and any help would be greatly appreciated. Thanks.

-Gavin
 
Here is the .gpe script from pyTetris by Barnesy:

Code:
PYTHONHOME=/mnt/sd/python
export PYTHONHOME

PYTHONPATH=${PYTHONHOME}/lib/python2.4/site-packages:$PYTHONPATH
PYTHONPATH=${PYTHONHOME}/lib/python24.zip:$PYTHONPATH
PYTHONPATH=${PYTHONHOME}/lib/python2.4/lib-dynload:$PYTHONPATH
PYTHONPATH=${PYTHONHOME}/lib/python2.4:$PYTHONPATH
PYTHONPATH=${PYTHONHOME}:$PYTHONPATH
export PYTHONPATH

LD_LIBRARY_PATH=${PYTHONHOME}/extras:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH

cd /mnt/sd/pyTetris
/mnt/sd/python/python -v ./main.py

cd /usr/gp2x
./gp2xmenu
When I was getting a python program to work, I used this script but change the name of the .py file which here is called main.py. You want to have the directory where the .py file is here:

Code:
cd /mnt/sd/pyTetris
And the path to python followed by "-v" then "./<your .py file>", like here:

Code:
/mnt/sd/python/python -v ./main.py
Everything else is the same.

All of this is written in a text editor and saved as a plain text file. I believe you need to make sure that the text editor uses a Unix format; Notepad can't do that. I use Crimson Editor, which is a lightweight freeware program, to save those files.

To run it, you just select the file in the game menu on the GP2X.
 
That will work fine, but I use a different command to launch scripts I'm working on so I get useful error messages from the gp2x.

If you launch the script like this (with the rest of the .GPE as above)
Code:
/mnt/sd/python/python -v ./main.py /mnt/sd/tetris_output.txt 2>&1
You'lll get a text file called (in this case) tetris_output.txt in the root of your SD card. It will contain all the output from Python, the output of your print commands, and any warnings or error messages. Without it, you'd be flying blind whenever your script crashed!

A final warning: The way the SD card gets mounted means the text file won't get saved if you just turn the GP2X off! You'll be able to see it OK in the ebook reader though. There'll be a way of making that work properly by remounting the card from your .GPE file, but I quite like being able to read the output immediately so haven't tried to fix it!

Hope that helps. It's good to hear other people are working with pygame!
 
Thanks for the help, and I got it working, but now I need help with using the gp2x's buttons. I have been trying for a while now(Just got my 2x yesterday) and I cant get the buttons to work. I looked trought pyTetris, pySlide and other code for answers but I'm lost.
Here is some code.

Code:
import pygame, os, sys
import gp2x

pygame.init()

size = width, height = 320, 240
speed = [1, 1]
black = 0, 0, 0

screen = pygame.display.set_mode(size)
ball = pygame.image.load("Linux.bmp")
ballrect = ball.get_rect()


def main():
    global running
    pygame.init()
    pygame.mouse.set_visible(0)

    num_joysticks = pygame.joystick.get_count()
    if num_joysticks > 0:
        stick = pygame.joystick.Joystick(0)
        stick.init()


while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    ballrect = ballrect.move(speed)
    if event.button == gp2x.BUTTON_START:
	pygame.QUIT
    if ballrect.left < 0 or ballrect.right > width:
        speed[0] = -speed[0]* 1.01
    if ballrect.top < 0 or ballrect.bottom > height:
        speed[1] = -speed[1]* 1.01

    screen.fill(black)
    screen.blit(ball, ballrect)
    pygame.display.flip()

This is the error I get when I run it:
Traceback (most recent call last):
File "F:\ball\ball.py", line 31, in -toplevel-
if event.button == gp2x.BUTTON_START:
AttributeError: event member not defined


Could somebody tell me why this doesn't work?
Thanks

-Gavin
 
I assume the indentation has been lost in translation, as the button code doesn't seem to be within the 'for event' loop.

It looks like the problem is that you need to check if the event is a button press before checking what that button is. The way you have it, I think it'll be hitting an event, asking what the button is, then crashing because whichever event it is doesn't have a button property.

This code:
Code:
if event.type == pygame.JOYBUTTONDOWN:
will do that check. You can then put the 'if event.button...' stuff within that if statement.

You can also use pygame.JOYBUTTONUP to check for button releases. That's how the inertia in pytetris and pybrush works - you don't continue to get events for that button press while the button is held, so the program keeps moving stuff until it notices that the button isn't held down any more.
 
Back
Top