Pygame won't draw any shapes!


jackmccarthy4

Still Fresh
Joined
May 6, 2013
Messages
1
I'm making a game that simply makes a square in the top left corner with random dimensions but it wont draw. The source code is below.

#START-UP imports pygame and random

import pygame

import random

pygame.init()

 

#PRESETS 

size = (700,500) #default window size

 

done = False #exit is 'false'

 

clock = pygame.time.Clock() #sets up a in-game 'clock'

 

black = (  0,  0,  0)

green = (  0,255,  0)

 

level_count = 1 #start on level 1

 

#RANDOM LEVEL GENERATION

random_list = []

for current_level in range(12): #picks 12 random numbers

random_numbers = random.randrange(20,51) #between 20 and 50

random_list.append(random_numbers) #and adds them to random_list

 

#CLASSES

 

#----------MAIN GAME LOOP----------

while done == False: #exit loop

clock.tick(30) #maximum 30 FPS

for event in pygame.event.get():

if event.type == pygame.QUIT:

done = True

 

from pygame.locals import * #screen resize code below

pygame.init()

screen=pygame.display.set_mode(size,HWSURFACE|DOUBLEBUF|RESIZABLE) #allows the game window to be changed in size

background = screen.fill(black) #black background

while True:

pygame.event.pump() #adds the resize to the event list

event=pygame.event.wait() 

if event.type==QUIT: pygame.display.quit()

elif event.type==VIDEORESIZE:

screen=pygame.display.set_mode(event.dict['size'],HWSURFACE|DOUBLEBUF|RESIZABLE)

screen.fill(black)

pygame.display.flip()

 

#All drawing and graphics below this comment

pygame.draw.rect(screen,green,[0,0,random_list[1],random_list[2]])

#All drawing and graphics above this comment

pygame.display.flip()

 

 

 

pygame.quit() #closes window
 
#START-UP imports pygame and random

import pygame

import random

from pygame.locals import *

 

pygame.init()

 

#PRESETS 

size = (700,500) #default window size

 

done = False #exit is 'false'

 

clock = pygame.time.Clock() #sets up a in-game 'clock'

 

black = (  0,  0,  0)

green = (  0,255,  0)

 

level_count = 1 #start on level 1

 

#RANDOM LEVEL GENERATION

random_list = []

for current_level in range(12): #picks 12 random numbers

    random_numbers = random.randrange(20,51) #between 20 and 50

    random_list.append(random_numbers) #and adds them to random_list

 

#CLASSES

 

#----------MAIN GAME LOOP----------

while done == False: #exit loop

    screen=pygame.display.set_mode(size,HWSURFACE|DOUBLEBUF|RESIZABLE) #allows the game window to be changed in size

    while True:

        pygame.event.pump() #adds the resize to the event list

        event=pygame.event.wait() 

        if event.type==QUIT:

            pygame.display.quit()

        elif event.type==VIDEORESIZE:

            screen=pygame.display.set_mode(event.dict['size'],HWSURFACE|DOUBLEBUF|RESIZABLE)

        screen.fill(black)

 

        #All drawing and graphics below this comment

        pygame.draw.rect(screen,green,[0,0,random.choice(random_list),random.choice(random_list)])

        #All drawing and graphics above this comment

        pygame.display.flip()

        clock.tick(30)

 

This should do the job
 
Back
Top