initial commit
This commit is contained in:
commit
39f56a3b10
83 files changed
+3583
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import random
|
||||
import time
|
||||
|
||||
import pygame
|
||||
|
||||
|
||||
class Star:
|
||||
def __init__(self,visible,pos):
|
||||
self.visible = visible
|
||||
self.pos = pos
|
||||
self.size = random.randint(1,3)
|
||||
def set_visible(self):
|
||||
self.visible = True
|
||||
def star_appear(self,screen):
|
||||
pygame.draw.circle(screen, WHITE, self.pos, self.size)
|
||||
|
||||
stars = []
|
||||
width = 640
|
||||
height = 600
|
||||
SIZE = (width, height)
|
||||
WHITE = (255, 255, 255)
|
||||
BLACK = (0, 0, 0)
|
||||
|
||||
def main():
|
||||
screen = init_game()
|
||||
game_loop(screen)
|
||||
exit_game()
|
||||
|
||||
def init_game():
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode(SIZE)
|
||||
return screen
|
||||
|
||||
def game_loop(screen):
|
||||
while True:
|
||||
if not event_handling():
|
||||
break
|
||||
if not update_game(screen):
|
||||
break
|
||||
event = event_handling()
|
||||
update_game(screen)
|
||||
draw_screen(screen)
|
||||
time.sleep(0.5)
|
||||
|
||||
def event_handling():
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
return False
|
||||
return True
|
||||
|
||||
def update_game(screen):
|
||||
for _ in range (2):
|
||||
night_sky(screen)
|
||||
random.choice(stars).set_visible()
|
||||
return True
|
||||
|
||||
def draw_screen(screen):
|
||||
screen.fill(BLACK)
|
||||
x = 0
|
||||
for _ in stars:
|
||||
if stars[x].visible:
|
||||
stars[x].star_appear(screen)
|
||||
x+=1
|
||||
pygame.display.flip()
|
||||
|
||||
def night_sky(screen):
|
||||
pos = (random.randint(0, SIZE[0]), random.randint(0, SIZE[1]))
|
||||
stars.append(Star(False, pos))
|
||||
|
||||
def exit_game():
|
||||
pygame.quit()
|
||||
|
||||
main()
|
||||
Reference in new issue
Block a user