-
Notifications
You must be signed in to change notification settings - Fork 45
/
from hooman import Hooman.py
55 lines (40 loc) · 1.27 KB
/
from hooman import Hooman.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
from hooman import Hooman
import pygame
import random
# Initialize Hooman
window_width, window_height = 800, 600
hapi = Hooman(window_width, window_height)
bg_col = (0, 0, 0)
# Starfield
num_stars = 100
stars = []
for _ in range(num_stars):
star_x = random.randint(0, window_width)
star_y = random.randint(0, window_height)
star_speed = random.uniform(1, 5)
stars.append((star_x, star_y, star_speed))
fps = 60
def handle_events(event):
if event.type == pygame.QUIT:
hapi.is_running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
hapi.is_running = False
hapi.handle_events = handle_events
while hapi.is_running:
hapi.background(bg_col)
# Update and draw stars
for i, (x, y, speed) in enumerate(stars):
hapi.fill(255) # White stars
hapi.circle(int(x), int(y), 2)
# Move stars diagonally
stars[i] = (x + speed, y + speed, speed)
# Reset stars that go off-screen
if x > window_width or y > window_height:
stars[i] = (random.randint(0, window_width), random.randint(0, window_height), speed)
# Update display and handle events
hapi.flip_display()
hapi.event_loop()
# FPS limiter
hapi.clock.tick(fps)
pygame.quit()