我需要幫助我的動畫代碼。到目前爲止,我已經在球的三個邊緣周圍展示了球。但我不知道如何讓它在最後一個屏幕上出現。如何讓球在屏幕邊緣連續走動? (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()
球需要繞屏幕邊緣不斷,任何提示或直接的答案是受歡迎的。謝謝。
什麼是你的代碼錯誤? –