import sys
import pygame
from pygame.sprite import Sprite,Group
from random import randint
class Star(Sprite):
def __init__(self):
super().__init__()
self.image=pygame.image.load('images/star.bmp')
self.rect=self.image.get_rect()
self.rect.x=self.rect.width
self.rect.y=self.rect.height
def create_star(stars,star_x,randint_x,star_y,randint_y):
star=Star()
star.rect.x=star_x+randint_x
star.rect.y=star_y+randint_y
stars.add(star)
def create_fleet(stars):
star=Star()
star_x=0
star_y=0
randint_x=randint(50,100)
randint_y=randint(50,100)
while star_y+randint_y+star.rect.height<600:
while star_x+randint_x+star.rect.width<1200:
create_star(stars,star_x,randint_x,star_y,randint_y)
star_x=star_x+randint_x
randint_x=randint(50,100)
star_x=0
star_y=star_y+randint_y
randint_y=randint(50,100)
def run_game():
pygame.init()
screen=pygame.display.set_mode((1200,600))
stars=Group()
create_fleet(stars)
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
screen.fill((255,255,255))
stars.draw(screen)
pygame.display.flip()
run_game()