Skip to content

Commit

Permalink
added shootingstar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagathi-kota authored and Abdur-rahmaanJ committed Nov 22, 2023
1 parent de1ac67 commit 7b528b9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 805 deletions.
55 changes: 55 additions & 0 deletions from hooman import Hooman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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()
10 changes: 7 additions & 3 deletions hooman/shootingstar.py → hooman/demos/shootingstar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# demo_starfield.py
from hooman import Hooman
import pygame
import random
Expand All @@ -19,6 +18,8 @@
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
Expand All @@ -29,7 +30,7 @@ def handle_events(event):
hapi.handle_events = handle_events

while hapi.is_running:

hapi.background(bg_col)

# Update and draw stars
Expand All @@ -42,10 +43,13 @@ def handle_events(event):

# Reset stars that go off-screen
if x > window_width or y > window_height:
stars[i] = (0, 0, speed)
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()

0 comments on commit 7b528b9

Please sign in to comment.