0
import sys, time, decimal, random, pygame
from pygame.locals import *
pygame.init()
pbif = "pongbackground.jpg"                #my image of the backdrop 1024x576
ppif = "pongpaddle.png"                    #my image of the paddle 33x103

screen = pygame.display.set_mode((1024, 576), 0, 32)        #(16:9)
backdrop = pygame.image.load(pbif).convert() #sets variable 'backdrop' as my image
paddle = pygame.image.load(ppif).convert()   #sets variable 'paddle' as my image

py = 288                                 #initial y co-ordinate for paddle
pmovey = 0                               #SOLVED this was the missing line.

while True:
    for event in pygame.event.get():        #should enable quitting through red x
        if event.type == QUIT:              #this doesn't work either, except when I
            pygame.quit()                   #temporarily remove the drawing block
            sys.exit()                      #from the bottom
        if event.type == KEYDOWN:
            if event.key == K_UP:
                pmovey = -1
            elif event.key == K_DOWN:
                pmovey = 1
        if event.type == KEYUP:
            if event.key == K_UP:
                pmovey = 0
            elif event.key == K_DOWN:
                pmovey = 0

    py += pmovey
    screen.blit(backdrop, (0, 0))           #SHOULD draw background but doesnt
    screen.blit(paddle, (100, py))          #same problem
    pygame.display.update()

Ah, just solved it myself. Needs a line:

pmovey = 0

underneath

py = 288

I don't know why though?! I suppose it has something to do with the scope of the loop? Will leave here for anyone with a similar problem.

  • Is your code showing up correctly here? The most obvious problem with the code as I'm seeing it now is that everything below `while True:` should be indented 4 spaces, but I can't tell if that's just due to a copy-paste error. – Marius Mar 09 '14 at 23:07
  • You should include a small description of the issue in the question body rather than just use the title. Also, if you've answered your own question, please post it as an answer rather than a question edit. – domdomcodecode Mar 09 '14 at 23:26

0 Answers0