473,320 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

problem with pygame

51
hi guy,when i run my program which contains the following portion of code in the mainloop
Expand|Select|Wrap|Line Numbers
  1. clock=pygame.time.Clock()
  2. while True:
  3.     sound1.play()
  4.     clock.tick(60)
  5.     pKeys = pygame.key.get_pressed()
  6.     Eves=pygame.event.get()
  7.     villian.face()
  8.     villian.hert()
  9.     if Eves[KEYDOWN] and pKeys[K_UP]:
  10.         hero.moveup()
  11.     if Eves[KEYUP] and pKeys[K_UP]:
  12.         hero.gravity()
  13.     if Eves[KEYDOWN] and pKeys[K_DOWN]:
  14.         hero.movedown()
  15.     if Eves[KEYDOWN] and pKeys[K_RIGHT]:
  16.         hero.forward()
  17.     if Eves[KEYDOWN] and pKeys[K_LEFT]:
  18.         hero.back()
  19.     if Eves[KEYDOWN] and pKeys[97]:
  20.         sound.play()
  21.         hero.reShape()
  22.     if Eves[KEYUP] and pKeys[97]:
  23.         hero.Shape()
  24.     if Eves[KEYDOWN] and pKeys[115]:
  25.         hero.Kick()
  26.     if Eves[0]:
  27.         pygame.quit()
  28.         raise SystemExit()
  29.     allsprites.update()
  30.     screen.blit(background,(0,0))
  31.     allsprites.draw(screen)
  32.     pygame.display.flip()
  33.     time.sleep(1/30)
i get this error
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Python24\RealSuperDynamo.py", line 145, in ?
  3.     if Eves[KEYDOWN] and pKeys[K_UP]:
  4. IndexError: list index out of range
can anyone help?Thanks in advance
Jul 3 '08 #1
1 1501
yoda
291 100+
I use this code

Expand|Select|Wrap|Line Numbers
  1. while keepGoing:
  2.         clock.tick(30)
  3.         for event in pygame.event.get():
  4.             if event.type == pygame.QUIT: # if X box clicked, game closes
  5.                 keepGoing = False
  6.             if event.type == pygame.KEYDOWN:
  7.                 if event.key == pygame.K_ESCAPE: #press escape the game closes
  8.                     keepGoing = False
  9.  
  10.         if event.type == pygame.KEYDOWN:
  11.             if event.key == pygame.K_LEFT:
  12.                 circle.moveLeft() # calls your methods to be ran if this key is pressed
  13.             if event.key == pygame.K_RIGHT:
  14.                 circle.moveRight()
  15.             if event.key == pygame.K_SPACE:
  16.                 circle.shoot()
  17.  
This code works well, but i don't know if this is what you are looking for. I'm using Python 2.5.4, wxPython 2.8 , and Pygame 1.8
May 21 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AnsNum | last post by:
hello, when I start this program, the movie doesn't play smoothly, anybody has an idea ? (I use windowsXP) import pygame from pygame.display import flip from pygame.locals import * ...
3
by: Tim Knauf | last post by:
Hi everyone, I'm glad to have found this list. I've written a small script for my own use which, amongst other things, captures mouse click information from a window containing an image. I used...
1
by: kjm | last post by:
Hi everyone, I have recently acquired a Logitech Rumble pad to use as an input device. I have been having trouble getting the event que to respond that a button or hat arrow has been pressed. ...
1
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image...
11
by: dynamo | last post by:
Hi guys i have come again with more problems.This time it has to do with pygame.The following code does not give any error messages but it does not do what it is supposed to do either.the code is a...
1
by: koolest1 | last post by:
Im working in red hat linux 9.0. I've downloaded the pygame package but there is some problem while installing it. For the tar version, initial steps execute OK, namely, # tar xzvf...
0
by: Grant Edwards | last post by:
I've got a system where I try to install extensions using /usr/local/bin/python setup.py install But, it fails when it tries to use a non-existant compiler path and specs file. I suspect it's...
1
by: joshuabraham | last post by:
os version =windows xp hi guys i'm having problems using pygame the following code just does not seem to work. clock=pygame.time.Clock() while True: sound1.play() clock.tick(60) ...
4
kaarthikeyapreyan
by: kaarthikeyapreyan | last post by:
I have installed pygame v 1.8.0 The installation was sucessful, but the optional packages were not included like the font,movie etc When i was trying to run the sample script that was given it...
3
by: globalrev | last post by:
im doing this : http://www.learningpython.com/2006/03/12/creating-a-game-in-python-using-pygame-part-one/ and when closing the program the window stays up and doesnt respond. i tried adding...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.