Python 有人知道我如何在pygame中让我的精灵移动起来吗

Python 有人知道我如何在pygame中让我的精灵移动起来吗,python,pygame,Python,Pygame,我知道如何左右移动,但有人知道如何在pygame中上下移动吗 我用的是pygame本地人,pygame,sys,glob。如果您有任何帮助,我们将不胜感激,大部分代码都基于以下内容: 玩家的位置由2个坐标(x,y)定义。对于上下移动,您必须更改第二(y)坐标(例如,播放器位置[1]-=4): 为True时: 瓷砖(地图1) 如果向右移动=真: 玩家位置[0]+=4 如果向左移动=真: 播放器位置[0]-=4 如果上移=真: 播放器位置[1]-=4 如果向下移动=真: 玩家位置[1]+=4 上下移

我知道如何左右移动,但有人知道如何在pygame中上下移动吗 我用的是pygame本地人,pygame,sys,glob。如果您有任何帮助,我们将不胜感激,大部分代码都基于以下内容:


玩家的位置由2个坐标(x,y)定义。对于上下移动,您必须更改第二(y)坐标(例如,
播放器位置[1]-=4
):

为True时:
瓷砖(地图1)
如果向右移动=真:
玩家位置[0]+=4
如果向左移动=真:
播放器位置[0]-=4
如果上移=真:
播放器位置[1]-=4
如果向下移动=真:
玩家位置[1]+=4

上下移动时,必须更改第二个坐标。e、 g
player\u位置[1]+=4
from pygame.locals import *
import pygame
import sys
import glob
map1 = """wwwwwwwwwwwwwwwwwwwwwwwwwwwww
w                           w
w                           w
w                           w
w                           w
w                           
w                           d
w            p               
w                           
w                           w
w                           w
w                           w
w                           w
w                           w
w                           w
wwwwwwwwwwwwwwwwwwwwwwwwwwwww"""
pygame.display.set_icon(pygame.image.load("C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/favicon.ico"))
pygame.display.set_caption("Knock Knight")

screen = pygame.display.set_mode((480, 250))
moving_right = False
moving_left = False
moving_up = False
moving_down = False
player_location = [50,50]#remember its a fucking list

#-----------------------------

door = pygame.image.load("C:/Users/cuerv/Downloads/Door.png")
door_rect = door.get_rect(center=(100, 250))

tile = pygame.image.load("C:/Users/cuerv/Downloads/Wall.png")
tile_rect = tile.get_rect(center=(100, 256))

player = pygame.image.load("C:/Users/cuerv/Downloads/Player.png").convert()
player_rect = player.get_rect(center=(100, 256))



def init_display():
    global screen, tile, door, player


def tiles(map1):
    global tile, door, player
    for y, line in enumerate(map1):
        #counts lines
        for x, c in enumerate(line):
            #counts caracters
            if c == "w":
                #caracter is w
                screen.blit(tile, (x * 16.18, y * 15))
            if c == "d":
                screen.blit(door, (x * 16.2, y * 15))
            if c == "p":
                screen.blit(player, player_location)


map1 = map1.splitlines()
pygame.init()
init_display()
clock = pygame.time.Clock()
while True:
    tiles(map1)
    if moving_right == True:
        player_location[0] += 4
    if moving_left == True:
        player_location[0] -= 4
    if moving_up == True:
        player_location[0] +=8

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()



        if event.type == KEYDOWN:
            if event.key == K_RIGHT:
                moving_right = True
            if event.key == K_LEFT:
                moving_left = True
            if event.key == K_UP:
                moving_up = True
            if event.key == K_DOWN:
                moving_down = True
        if event.type == KEYUP:
            if event.key == K_RIGHT:
                moving_right = False
            if event.key == K_LEFT:
                moving_left = False
            if event.key == K_UP:
                moving_up = False
            if event.key == K_DOWN:
                moving_down = False





    pygame.display.update()
    clock.tick(60)