如何在python游戏中展示宇航员

2024-09-26 17:39:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为Python游戏编写代码,我有以下内容

WIDTH = 600
HEIGHT = 800
player_x = 600
player_y = 350
def draw():
    screen.blit(images.backdrop, (0, 0))
    screen.blit(images.mars, (50, 50))
    screen.blit(images.astronaut, (player_x, player_y))
    screen.blit(images.ship, (550, 300))
def game_loop():
    global player_x, player_y
    if keyboard.right:
        player_x += 5
    elif keyboard.left:
        player_x -= 5
    elif keyboard.up:
        player_y -= 5
    elif keyboard.down:
        player_y += 5
    clock.schedule_interval(game_loop, 0.03)

然而,当我运行它时,它不会显示宇航员。我有宇航员的形象,但无论我做什么,它都不会起作用。有人能告诉我问题出在哪里吗


Tags: 代码loopgame游戏defwidthscreenplayer
1条回答
网友
1楼 · 发布于 2024-09-26 17:39:08

传递给^{}的坐标是曲面左上角的位置。由于曲面的宽度为600,x坐标为600,因此窗口外的曲面位于右侧。
您可以切换宇航员的x坐标,但最有可能切换窗口的WIDTHHEIGHT

WIDTH = 600
HEIGHT = 800

WIDTH = 800
HEIGHT = 600

相关问题 更多 >

    热门问题