dimanche 14 août 2022

Randint and random not generating a num in python

I have random and randint imported and did what is shown in a small tutorial i read but it still says it is not working anyone knows what is the issue. I am sorry if the code is a little messy but i am kinda new to pygame

import pygame
import math
import random
from random import randint
import sys
pygame.init()
fps = 30
fpsclock=pygame.time.Clock()
window = pygame.display.set_mode((600, 600))

x = 275
y = 275
xr = randint(30,270)
yr = randint(30,270)
color = (255,0,0)
color2 = (0,0,255)

# main application loop
run = True
while run:
    # limit frames per second
    # event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    # clear the display
    window.fill(0)

    # draw the scene
    key_input = pygame.key.get_pressed() #key imputs
    pygame.draw.rect(window, color, pygame.Rect(x,y,30,30))
    pygame.draw.rect(window, color2,pygame.Rext(xr,yr,30,30))
    pygame.display.flip()
    if key_input[pygame.K_LEFT]:
        x -= 5
    if key_input[pygame.K_RIGHT]:
        x += 5
    if key_input[pygame.K_DOWN]:
        y += 5
    if key_input[pygame.K_UP]:
        y -= 5
    pygame.display.update()
    fpsclock.tick(fps)

    # update the display
    pygame.display.flip()

pygame.quit()
exit()



Aucun commentaire:

Enregistrer un commentaire