Jul-25-2024, 04:16 PM
So I'm trying to make a spaceship fly around on the screen with stars twinkling in the backround. When I went to test the stars, I was told that I did not define "randint" any idea what I could do?
import pygame from pathlib import Path import random pygame.init() WINDOW_WIDTH, WINDOW_HEIGHT = 1280, 720 pygame.display.set_caption("Space Shooter") display_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) running = True surf = pygame.Surface((100, 200)) surf.fill('orange') x = 100 path = Path("/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/video /17021362771.png").parent player_surf = pygame.image.load(f'{path}/17021362771.png') path = Path("/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/video /star.png").parent star_surf = pygame.image.load(f'{path}/star.png') while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False display_surface.fill('darkgray') x += 0.1 display_surface.blit(player_surf, (x, 150)) for i in range(20): display_surface.blit(star_surf, (randint(0, WINDOW_WIDTH), randint(0, WINDOW-HEIGHT))) pygame.display.update() pygame.quit()