From 3668911125ab163efcd8a2b1da5391ba4384e9f9 Mon Sep 17 00:00:00 2001 From: Abdur-RahmaanJ Date: Wed, 22 Nov 2023 23:32:59 +0400 Subject: [PATCH] chore: fix demo shooting star file setup --- hooman/demos/shooting_star.py | 55 +++++++++++++++++++++++++++++++++++ hooman/hooman.py | 2 -- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 hooman/demos/shooting_star.py diff --git a/hooman/demos/shooting_star.py b/hooman/demos/shooting_star.py new file mode 100644 index 0000000..c759cda --- /dev/null +++ b/hooman/demos/shooting_star.py @@ -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() \ No newline at end of file diff --git a/hooman/hooman.py b/hooman/hooman.py index c03cd0a..9221af6 100644 --- a/hooman/hooman.py +++ b/hooman/hooman.py @@ -814,5 +814,3 @@ def noCursor(self): def frameCount(self): return self._frame_count - -