I'm trying to make a shoot 'em up-like game in Python with pygame. I'm pretty new to Python and I'm not sure how do I make objects fall from the top of my screen, anyway, here's my code (I'm using Python 3.6):
import pygame
import random
pygame.init()
BLACK=(0,0,0)
WHITE=(255,255,255)
RED=(255,0,0)
GREEN=(0,255,0)
BLUE=(0,0,255)
width=600
height=650
screen=pygame.display.set_mode((width,height))
pygame.display.set_caption('Videojuego')
done=False
screen.fill(WHITE)
pygame.display.flip()
background_image=pygame.image.load('fondo.jpg').convert()
screen.blit(background_image,[0,0])
player_image=pygame.image.load('rocket.png').convert()
player_image=pygame.transform.scale(player_image,(50,75))
pygame.display.flip()
pygame.mouse.set_visible(False)
count=0
clock=pygame.time.Clock()
rect_x=random.randrange(0,580)
rect_y=random.randrange(0,2)
rect_chx=5
size1=random.randrange(10,70)
size2=random.randrange(15,84)
while(not done):
for event in pygame.event.get():
if(event.type==pygame.QUIT):
print('Quit')
done=True
else:
done=False
screen.blit(background_image,[0,0])
player_position=pygame.mouse.get_pos()
x=player_position[0]
y=player_position[1]
screen.blit(player_image,(x,y))
fig=pygame.draw.rect(screen,RED,[rect_x,rect_y,size1,size2])
if(rect_y>550 or rect_y<5):
rect_chx=rect_chx*1
rect_y+=rect_chx
pygame.display.flip()
clock.tick(60)
pygame.quit()
This code only makes one rectangle fall, and I don't know how to make more do so.