-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbop_screensaver.py
66 lines (48 loc) · 1.57 KB
/
bop_screensaver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# This is a screen saver, you can use any png you'd like. 'QUIT' - "CMD-Q" to escape
import pygame
import random
# Initialize Pygame
pygame.init()
# Set the window size
window_size = (1920, 1080)
# Create the window
screen = pygame.display.set_mode(window_size, pygame.FULLSCREEN)
# Set the window title
pygame.display.set_caption("BOP Screensaver")
# Load the PNG image / # You will need to correct this reference,
# any image in your folder can be referenced directly, ie- "$/games/images/bop.png"
png = pygame.image.load("images/bop.png")
# Set the background color
bg_color = (0, 0, 0)
# Set the object size
obj_size = 10
# Set the falling speed
fall_speed = 1.2
# Create a list to store the falling objects
objects = []
# Set the game clock
clock = pygame.time.Clock()
# Start the game loop
while True:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Clear the screen
screen.fill(bg_color)
# Add a new object to the list if there are less than 14 objects
if len(objects) < 14:
objects.append([random.randint(0, window_size[0] - obj_size), 0, random.uniform(0.6, 3)])
# Update the position of each object and remove it if it goes off the screen
for i, obj in enumerate(objects):
obj[1] += obj[2]
if obj[1] > window_size[1]:
objects.pop(i)
# Draw each object
for obj in objects:
screen.blit(png, (obj[0], obj[1]))
# Update the display
pygame.display.flip()
# Set the frame rate
clock.tick(60)