Pygame problem ,PLEASE HELP

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
YenTex
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 31
Joined: Sun Mar 01, 2009 9:38 pm

Pygame problem ,PLEASE HELP

Post by YenTex »

I'm reading a pygame tutorial, and when I type this code (below), I get a black screen, when I try to quit, I see the box with the background, and then my program freezes.
I'm running a mac, with Python 2.5

Code: Select all

#Initilize
import pygame
pygame.init()

#Display
screen = pygame.display.set_mode((640,480))
pygame.display.set_caption("move a box")

#Entities
#yellow background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((255, 255, 0))

#make a red 25 x 25 box
box = pygame.Surface((25, 25))
box = box.convert()
box.fill((255, 0, 0))

# set up some box variables
box_x = 0
box_y = 200

#ACTION

    #Assign
clock = pygame.time.Clock()
keepGoing = True

    #Loop
while keepGoing:

    #Time
    clock.tick(30)

    #Events
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keepGoing = False

#modify box value
box_x += 5
#check boundries
if box_x > screen.get_width():
    box_x = 0
    
#Refresh screen
screen.blit(background, (0, 0))
screen.blit(box, (box_x, box_y))
pygame.display.flip()
fantastico
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Fri Mar 20, 2009 4:37 am
Location: Germany

Re: Pygame problem ,PLEASE HELP

Post by fantastico »

The lines starting with #modify box value aren't in the scope of the while loop, since they aren't indented. So what happens at the moment is that they are only executed once after the loop exits.
Post Reply