Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使角色在pygame中自动向右移动?_Python_Pygame - Fatal编程技术网

Python 如何使角色在pygame中自动向右移动?

Python 如何使角色在pygame中自动向右移动?,python,pygame,Python,Pygame,嘿,伙计们,我对编码还很陌生,我们明天就需要这个,我很想今天就得到答案,所以,嗯,这是我们的代码,我希望这能尽快得到答案,呵呵。我真的不知道如何改变它,但我相信将要改变的代码只是在这一部分` def main(): global cameraX, cameraY pygame.init() pygame.mixer.init() screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH) pygame.display.set_caption("

嘿,伙计们,我对编码还很陌生,我们明天就需要这个,我很想今天就得到答案,所以,嗯,这是我们的代码,我希望这能尽快得到答案,呵呵。我真的不知道如何改变它,但我相信将要改变的代码只是在这一部分`

def main():
global cameraX, cameraY
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH)
pygame.display.set_caption("JCLT Game")
Timer = pygame.time.Clock()
pygame.display.set_mode(size, FULLSCREEN)
bg = Surface((32, 32))
up = down = left = right = runnning = False
bg = Surface((WIN_WIDTH,WIN_HEIGHT)).convert_alpha()
bg.fill(Color("skyblue"))
screen.blit(bg, [0,0])
entities = pygame.sprite.Group()
player = Player(16*3,16*3)
platforms = []
# build the level
for row in level:
    for col in row:
        if col == "P":
            p = Platform(x, y)
            platforms.append(p)
            entities.add(p)
        if col == "E":
            e = ExitBlock(x, y)
            platforms.append(e)
            entities.add(e)
        if col == "R":
            r = Rgspikes(x, y)
            platforms.append(r)
            entities.add(r)
        if col == "L":
            l = Lgspikes(x, y)
            platforms.append(l)
            entities.add(l)
        if col == "U":
            u = Upleftspikes(x, y)
            platforms.append(u)
            entities.add(u)
        if col == "I":
            i = Uprightspikes(x, y)
            platforms.append(i)
            entities.add(i)
        if col == "D":
            d = Downallaroundspikes(x, y)
            platforms.append(d)
            entities.add(d)
        if col == "T":
            t = Leftspikes(x, y)
            platforms.append(t)
            entities.add(t)
        if col == "Z":
            z = Rightspikes(x, y)
            platforms.append(z)
            entities.add(z)
        if col == "G":
            g = Groundspikes(x, y)
            platforms.append(p)
            entities.add(p)
        if col == "S":
            s = SpecialBlock(x, y)
            platforms.append(s)
            entities.add(s)
        if col == "J":
            j = Downaroundspikesl(x, y)
            platforms.append(j)
            entities.add(j)
        if col == "K":
            k = Downaroundspikesr(x, y)
            platforms.append(k)
            entities.add(k)
        if col == "M":
            m = Allaroundspikes(x, y)
            platforms.append(m)
            entities.add(m)
        if col == "N":
            n = Downspikes(x, y)
            platforms.append(n)
            entities.add(n)

        x += 16*3
    y += 16*3
    x = 0



total_level_width  = len(level[0])*32*3
total_level_height = len(level)*32*3
camera = Camera(complex_camera, total_level_width, total_level_height)
entities.add(player)




while 1:
    Timer.tick(60)


    for e in pygame.event.get():
        if e.type == KEYDOWN and e.key == K_ESCAPE:
            pygame.quit()
            sys.exit()
        if e.type == KEYDOWN and e.key == K_UP:
            up = True
        if e.type == KEYDOWN and e.key == K_LEFT:
            left = True
        if e.type == KEYDOWN and e.key == K_RIGHT:
            right = True
        if e.type == KEYUP and e.key == K_UP:
            up = False
        if e.type == KEYUP and e.key == K_DOWN:
            down = False
        if e.type == KEYUP and e.key == K_RIGHT:
            right = False
        if e.type == KEYUP and e.key == K_LEFT:
            left = False

        if e.type == KEYDOWN and e.key == K_w:
            up = True
        if e.type == KEYDOWN and e.key == K_s:
            down = True
        if e.type == KEYDOWN and e.key == K_a:
            left = True
        if e.type == KEYDOWN and e.key == K_d:
            right = True
        if e.type == KEYUP and e.key == K_w:
            up = False
        if e.type == KEYUP and e.key == K_s:
            down = False
        if e.type == KEYUP and e.key == K_d:
            right = False
        if e.type == KEYUP and e.key == K_a:
            left = False




    screen.blit(bg,(0,0))
把这个变成

up = down = left = False
right = running = True

你认为你可以通过让别人完成作业来学习编程??可以在正确的位置尝试右=真…从技术上讲,作业只是演示文稿,但当然这需要首先完成。我已经尝试过使keypup和keypdown都为真,但你仍然需要至少按一次d或arrow right。可以在启动时设置吗?我会尝试这样做。请不要忘记解释/评论您的代码,并提供相关文档[来自评论]@blag:他回答了自己的问题,为他感到骄傲;)对不起,伙计们,我对所有这些编程都很陌生,去年才用c sharp开始,还没有真正开始使用python,但是的,谢谢大家!
up = down = left = False
right = running = True