problem with pygame

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dynamo
    New Member
    • Apr 2007
    • 51

    problem with pygame

    hi guy,when i run my program which contains the following portion of code in the mainloop
    Code:
    clock=pygame.time.Clock()
    while True:
        sound1.play()
        clock.tick(60)
        pKeys = pygame.key.get_pressed()
        Eves=pygame.event.get()
        villian.face()
        villian.hert()
        if Eves[KEYDOWN] and pKeys[K_UP]:
            hero.moveup()
        if Eves[KEYUP] and pKeys[K_UP]:
            hero.gravity()
        if Eves[KEYDOWN] and pKeys[K_DOWN]:
            hero.movedown()
        if Eves[KEYDOWN] and pKeys[K_RIGHT]:
            hero.forward()
        if Eves[KEYDOWN] and pKeys[K_LEFT]:
            hero.back()
        if Eves[KEYDOWN] and pKeys[97]:
            sound.play()
            hero.reShape()
        if Eves[KEYUP] and pKeys[97]:
            hero.Shape()
        if Eves[KEYDOWN] and pKeys[115]:
            hero.Kick()
        if Eves[0]:
            pygame.quit()
            raise SystemExit()
        allsprites.update()
        screen.blit(background,(0,0))
        allsprites.draw(screen)
        pygame.display.flip()
        time.sleep(1/30)
    i get this error
    Code:
    Traceback (most recent call last):
      File "C:\Python24\RealSuperDynamo.py", line 145, in ?
        if Eves[KEYDOWN] and pKeys[K_UP]:
    IndexError: list index out of range
    can anyone help?Thanks in advance
  • yoda
    Contributor
    • Dec 2006
    • 291

    #2
    I use this code

    Code:
    while keepGoing:
            clock.tick(30)
            for event in pygame.event.get():
                if event.type == pygame.QUIT: # if X box clicked, game closes
                    keepGoing = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE: #press escape the game closes
                        keepGoing = False
            
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    circle.moveLeft() # calls your methods to be ran if this key is pressed
                if event.key == pygame.K_RIGHT:
                    circle.moveRight()
                if event.key == pygame.K_SPACE:
                    circle.shoot()
    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
    Last edited by yoda; May 21 '09, 01:09 AM. Reason: Word Change

    Comment

    Working...