【发布时间】:2016-09-29 15:15:30
【问题描述】:
我的动画代码需要帮助。到目前为止,我让球绕着屏幕的 3 个边缘移动。但我不知道如何让它绕过最后一个屏幕。
#-------------------------------------------------------------------------------
# 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()
小球需要连续绕屏幕边界,欢迎任何提示或直接答案。谢谢。
【问题讨论】:
-
你的代码有什么问题?
标签: python python-2.7 pygame