(尝试制作打地鼠游戏)每当我移动鼠标时,地鼠图像的位置似乎比我不移动鼠标时移动的速度慢 3-5 倍,我不确定是什么导致它,因为位置应该根据经过的时间进行更新。
游戏的屏幕为 500x500 像素,图像为 50x50 像素,还有一个 10x10 的阵列作为地图来决定允许痣出现的位置
编码:
从 10x10 地图中获取随机位置
每 30 个刻度更新痣图的位置一个像素
获取鼠标的位置(一个500x500像素的屏幕)
获得鼹鼠应该去的方块的位置(在 10x10 地图上)
图像在屏幕上绘制的顺序:
地图
移动时的锤子
鼹鼠上方的方块
痣(上升 1 个像素)
鼹鼠原始位置的方块
锤子不动
问题是,当我移动鼠标时,痣的上升速度要慢得多,我不确定是什么问题。我还使用打印语句进行检查。
def moleGoUp(self):
nbPixel = 0
#returns a random position
initialPos = self.returnRandPosition()
while nbPixel < 50:
tickCounter = pygame.time.get_ticks() % 30
if tickCounter == 0:
nbPixel += 1
#gets position of mouse
mousePos = pygame.mouse.get_pos()
#blits the background block that the mole is supposed to go to
blockAbovePos = [initialPos[1] * 50, initialPos[0] * 50 - 50]
#blits the mole at position (goes up by one pixel every 20 ticks)
newPos = [initialPos[1] * 50, (initialPos[0]*50 - nbPixel)]
initPosToBlit = [initialPos[1] * 50, initialPos[0] * 50]
for event in pygame.event.get():
mousePos = pygame.mouse.get_pos()
if event.type == pygame.QUIT:
sys.exit()
#draws the map
self.drawMap()
# blits the hammer
display_surf.blit(imagePlayer, tuple(mousePos))
# counts how many ticks has passed
tickCounter = pygame.time.get_ticks() % 30
print("in event loop")
display_surf.blit(imageWall, tuple(blockAbovePos))
display_surf.blit(imageTarget, tuple(newPos))
#blits the background at the original position of the mole
display_surf.blit(imageWall,tuple(initPosToBlit))
#blits the hammer
display_surf.blit(imagePlayer, tuple(mousePos))
print("out of event loop")
慕莱坞森
相关分类