我需要帮助我的动画代码。到目前为止,我已经在球的三个边缘周围展示了球。但我不知道如何让它在最后一个屏幕上出现。如何让球在屏幕边缘连续走动? (Python 2.7)
#-------------------------------------------------------------------------------
# Name: U1A4.py
# Purpose: To animate the ball going around the edge of the screen
#-------------------------------------------------------------------------------
import pygame
import sys
pygame.init()
# Screen
screenSize = (800,600)
displayScreen = pygame.display.set_mode(screenSize,0)
pygame.display.set_caption("Animation Assignment 1")
# Colours
WHITE = (255,255,255)
GREEN = (0,255,0)
RED = (255,0,0)
BLUE = (0,0,255)
displayScreen.fill(WHITE)
pygame.display.update()
# ----------------- Leave animation code here ---------------------------------#
# THU/09/29
# Need to complete the last turn with the ball
x = 50
y = 50
dx = 0
dy = 2
stop = False
while not stop:
for event in pygame.event.get():
if event.type ==pygame.QUIT:
stop = True
displayScreen.fill(WHITE)
x = x + dx
y = y + dy
if (x>=750):
dx = 0
dy = -2
if (y>=550)and dy>0:
dy = 0
dx = 2
if (x>=750)and dy>0:
dy = 0
dx = 2
if (y>=550)and dy>0:
dx = 0
dy = -2
pygame.draw.circle(displayScreen, GREEN, (x,y),50, 0)
pygame.display.update()
pygame.quit()
sys.exit()
球需要绕屏幕边缘不断,任何提示或直接的答案是受欢迎的。谢谢。
什么是你的代码错误? –