私はpygameを使って、ビーチボールの画像をランダムにラップまたはバウンスするプログラムを作ろうとしています。バウンスは動作しますが、ボールをラップしようとすると、ボールがエッジに沿ってグリッチして消えます。私はそれが消えてまだ動いている後にxとyの位置を調べました。 if movement == "wrap"
ブロック内Pygame ball wrapping glitch
import pygame, sys, random
pygame.init()
screen = pygame.display.set_mode([640, 480])
screen.fill([255,255,255])
ball = pygame.image.load('beach_ball.png')
x = 50
y = 50
xspeed = 10
yspeed = 10
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
movement = random.choice(["wrap", "bounce"])
pygame.time.delay(20)
pygame.draw.rect(screen, [255,255,255], [x, y, 90, 90], 0)
x = x + xspeed
y = y + yspeed
if movement == "bounce":
if x > screen.get_width() - 90 or x < 0:
xspeed = -xspeed
if y > screen.get_height() - 90 or y <0:
yspeed = -yspeed
if movement == "wrap":
if x > screen.get_width():
x = -90
if x < 0:
x = screen.get_width()
if y > screen.get_height():
y = -90
if y < 0:
y = screen.get_width()
screen.blit(ball, [x, y])
pygame.display.flip()
pygame.quit()