嘿伙计们,我一直在尝试使用 pygame 在屏幕上以方形方式移动球图像。我已经尝试了很多次,但它不起作用。请在下面查看我的代码。
import time
import pygame, sys
from pygame.locals import *
pygame.init()
clocks = pygame.time.Clock()
surfaceObject = pygame.display.set_mode((640, 480))
pygame.display.set_caption('Bounce')
mousey,mousex = 0,0
imgx = 10
imgy = 10
pixmove = 60
tiger = [2,2]
movement = 'down'
background = pygame.image.load('bg.jpg').convert()
ball = pygame.image.load('ball.jpg').convert_alpha()
pygame.mixer.music.load('yeah.mp3')
while True:
time.sleep(1)
if movement == 'down':
imgx += pixmove
if imgx < 640:
tiger[0] - tiger[1]
elif movement == 'right':
imgx += pixmove
if imgx < 0:
movement = 'up'
elif movement == 'up':
imgy -= pixmove
if imgy < 0:
movement = 'left'
elif movement == 'left':
imgx -= pixmove
if imgx < 0:
movement = 'down'
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
surfaceObject.blit(background,(mousex,mousey))
surfaceObject.blit(ball,(imgx,imgy))
pygame.mixer.music.play()
pygame.display.update()
clocks.tick(50)
当我运行此代码时,球以直线方式移动,并且球在接触末端时不会弹回。
我的目标是在屏幕上以方形方式旋转球。我尝试更改 pixmove 变量,但它没有解决我的问题。
希望你们能帮助我..Thanx提前