Jul-25-2024, 04:16 PM
(This post was last modified: Jul-25-2024, 04:44 PM by Gribouillis.)
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()
Gribouillis write Jul-25-2024, 04:44 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
