Wie man zufällige Zahlen in Pygame einfügtPython

Python-Programme
Anonymous
 Wie man zufällige Zahlen in Pygame einfügt

Post by Anonymous »

import sys, pygame
import random
pygame.init()

x=0.5
speed = [x, x]
size = width, height = 800, 600
black = 0, 0, 0

screen = pygame.display.set_mode(size)

ball = pygame.image.load("intro_ball.gif")
ballrect = ball.get_rect()

Sair = True

while Sair:

for event in pygame.event.get():
if event.type == pygame.QUIT: Sair=False
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
x=random.uniform(0, 1)
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
x=random.uniform(0, 1)

screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()

sys.exit()
< /code>

Ich habe erwartet, dass sich der Ball bewegen wird, und jedes Mal, wenn er die Eckwechsel -Geschwindigkeit wechselt. < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post