|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 67193114 于 2022-5-16 10:50 编辑
import pygame
import sys
pygame.init()
size = width, height = 600, 400
speed = [5, 0]
bg = (255, 255, 255)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('FishC Demo')
fish = pygame.image.load('fish2.png')
position = fish_rect = fish.get_rect()
clock = pygame.time.Clock()
fish_R = pygame.transform.rotate(fish, -90)
fish_B = pygame.transform.flip(fish, True, False)
fish_L = pygame.transform.rotate(fish, 90)
fish_T = fish
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
position = position.move(speed)
print(position)
if position.right > width:
fish = fish_R
speed = [0, 5]
if position.bottom > height:
fish = fish_B
speed = [-5, 0]
if position.left < 0:
fish = fish_L
speed = [0, -5]
if position.top < 0:
fish = fish_T
speed = [5, 0]
screen.fill('cornflowerblue')
screen.blit(fish, position)
pygame.display.flip()
#pygame.time.delay(10)
clock.tick(50)
请问上述代码去掉了每个if中的重定义position,为什么小鱼跑到第二圈右边框就出去了?没想明白!从打印position信息上看position.right一直累加下去肯定大于600了啊?
请大佬指点!
<rect(5, 0, 100, 78)>
<rect(10, 0, 100, 78)>
<rect(15, 0, 100, 78)>
<rect(20, 0, 100, 78)>
<rect(25, 0, 100, 78)>
<rect(30, 0, 100, 78)>
另外还请大佬指点一下,为什么打印出来的position(小鱼水平向右),right和bottom两个坐标不变?明明是矩形整体移动啊?求解!
|
|