简体   繁体   English

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

[英]How to make a character move to the right automatically in pygame?

Hey guys so I am pretty new to coding and we need this tomorrow already I would love to get answers today already so uhmm here is our code I hope this can be answered as fast hehe.嘿伙计们,所以我对编码还很陌生,我们明天就需要这个了,我很想今天就得到答案,所以嗯,这是我们的代码,我希望这能尽快得到答复,呵呵。 I do not really know how to change it but I believe the code that will be changed is only in this part.`我真的不知道如何更改它,但我相信将要更改的代码仅在这一部分。`

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 = right = runnning = False

turn this into把这个变成

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM