def main(): pygame.init() screen = pygame.display.set_mode((920, 640)) pygame.display.set_caption("Stars") galaxy = Group() star = Star(screen) for star_x in range(star.per_row): for star_y in range(star.per_col): star = Star(screen) star.x = star.width * star_x star.y = star.width * star_y star.rect.x = star.x star.rect.y = star.y galaxy.add(star) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_q: sys.exit() screen.fill((0, 20, 137)) for star in galaxy: star.blitme() pygame.display.flip()
def run_game(): pygame.init() screen = pygame.display.set_mode((1200, 800)) pygame.display.set_caption('narue game') bg_color = (30, 30, 30) COUNT = pygame.USEREVENT + 1 pygame.time.set_timer(COUNT, 1000) star = Star(screen) rains = Group() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == COUNT: new_rain = Rain(screen, star.rect.centerx, star.rect.centery) rains.add(new_rain) screen.fill(bg_color) star.blitme() star.update() for rain in rains: rain.update() rain.draw() pygame.display.flip()
def run_game(): pygame.init() screen = pygame.display.set_mode((800, 800)) pygame.display.set_caption('Star') bg_color = (246, 246, 246) stars = Group() star = Star(screen) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() screen.fill(bg_color) for i in range(3): for j in range(star.x_num): new_star = Star(screen) new_star.rect.x += new_star.rect.width stars.add(new_star) new_star.blitme() pygame.display.flip() print(star.x_num)