【发布时间】:2020-05-03 23:07:55
【问题描述】:
试图为我的高中课程制作一个开始屏幕。图像应该在屏幕上移动,与每面墙碰撞并朝下一个方向移动。由于某种原因,图像不会与左墙发生碰撞,我不知道为什么。
class StartScreen:
def __init__(self):
screen.fill(WHITE)
self.fontTitle = pygame.font.SysFont("arial", 30) #
self.textTitle = self.fontTitle.render("Legend Of Zelda: ", True, WHITE)
self.textRect = self.textTitle.get_rect(center=(displayWidth / 2, 50))
self.moveImage = pygame.image.load("images/link_down1.png")
self.moveImageRect = self.moveImage.get_rect()
self.dx = 3
self.dy = 0
self.moveImageRect.x = 1
self.moveImageRect.y = 11
def update(self):
if self.moveImageRect.right >= displayWidth:
self.dy = 3
self.dx = 0
if self.moveImageRect.left <= 0:
self.dy = -1
self.dx = 0
if self.moveImageRect.top <= 0:
self.dy = 0
self.dx = -3
elif self.moveImageRect.bottom >= displayHeight:
self.dx = -3
self.dy = 0
self.moveImageRect.move_ip(self.dx, self.dy)
def draw(self, surf):
screen.blit(backgroundImage, (backgroundRect))
screen.blit(self.textTitle, self.textRect)
screen.blit(backgroundImage, (backgroundRect))
screen.blit(self.moveImage, self.moveImageRect)
【问题讨论】:
-
嗯,唯一的区别是,对于左侧,
self.dy = -1而不是 3。您还可以将dy更改为向上、向左和向右,但将dx更改为向下。您是否想追求弹跳 dvd 播放器效果? -
不要试图在屏幕上顺时针移动它。
标签: python pygame collision-detection