pygame中的移动问题

时间:2015-05-19 20:46:51

标签: python pygame

当我输入输入时,我的图像正确移动,但是因为当我放开键时我需要图像退出移动,我自然使用pygame.KEYUP来停止所有移动。然而,这会导致不稳定的游戏玩法,因为如果你在放下你所持有的按钮之前甚至按下一个按钮只有一秒钟,你的角色会停在一起,有时即使我放开按钮也会感觉到它发生了及时,虽然我想这可能只是在我身上。有没有其他方法可以编码运动,这不是一个问题?

2 个答案:

答案 0 :(得分:0)

我用:

if event.type == KEYDOWN:
    if event.key == ord('d'):
        Right = True
if event.type == KEYUP:
    if event.key == ord('d'):
        Right = False

(代码中的其他地方......)

if Right == True:

PlayerX += 10

(然后)

screen.blit(PlayerImage,(PlayerX,PlayerY))

答案 1 :(得分:0)

停止使用活动进行移动。

只需使用pygame.key.get_pressed()检查按下了哪些键,然后相应地改变游戏对象的位置。

这是一只移动猴子的最小例子:

import base64, pygame, math
from pygame.locals import *

def magnitude(v):
    return math.sqrt(sum(v[i]*v[i] for i in range(len(v))))

def add(u, v):
    return [ u[i]+v[i] for i in range(len(u)) ]

def normalize(v):
    vmag = magnitude(v)
    return [ v[i]/vmag  for i in range(len(v)) ]

pygame.init()
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
img = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAgFRg8JRdZOyQYVj4lGSkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArKysGPCMWiTwkFTg9JBfsPCQX4DwkFT07JBe9OiQWIwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAgFQA8JRcAAAAAAAAAAA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AAAAAAAAAALONaZbU0J7TTtCeTTnMmTUifl1HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPCQXAF9EMABnTDYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKqFZQD1yJgAAAAAAAAAAAAAAAAAsItniT7QnvTU0J7T98qZT6uFY3cAAAAAAAAAAAAAAAAAAAAAAAAAALiSba3U0J7TTtCeTT7QnvU6k2UxAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlHFTAP7QngDswJIAp4RkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALONaQDU0J4AAAAAAAAAAAAAAAAAqINhYf7QnvTU0J7TTtCeT7yWcLgAAAAAAAAAAAAAAAAAAAAAAAAAALSMaJX8zp3T7cCSTLmSbqukgFsOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsItnAP7QngDU0J4A98qZAKuFYwAAAAAAAAAAAAAAAAAAAAAAAAAAALiSbQDU0J4AAAAAAAAAAAAAAAAApoVZFTbJmfT0yJfUwp12zQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACZc1kUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqINhAP7QngDU0J4ATtCeALyWcAAAAAAAAAAAAAAAAAAAAAAAAAAAALSMaAD8zp0AAAAAAAAAAAAAAAAAAAAAAKOAX06ogF4mAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApoVZAPbJmQD0yJcAwp12AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACZc1kA'

player = pygame.image.fromstring(base64.b64decode(img, 'UTF-8'), (36, 56), 'RGBA')
player_rect = player.get_rect()

# define which keys move the monkey in which direction
move_map = {pygame.K_w: ( 0, -1),
            pygame.K_s: ( 0,  1),
            pygame.K_a: (-1,  0),
            pygame.K_d: ( 1,  0)}

def main():
    running = True
    clock = pygame.time.Clock()
    while running:
        screen.fill(pygame.Color("darkgreen"))

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        # get all pressed keys
        pressed = pygame.key.get_pressed()

        # get all directions the monkey should move
        move = [move_map[key] for key in move_map if pressed[key]]

        # add all directions together to get the final direction
        reduced = reduce(add, move, (0, 0))
        if reduced != (0, 0):
            # normalize the target direction and apply a speed
            move_vector = [c * 5 for c in normalize(reduced)]

            # move the monkey...
            player_rect.move_ip(*move_vector)

            # ...but keep it inside the screen
            player_rect.clamp_ip(screen.get_rect())

        screen.blit(player, player_rect)
        pygame.display.flip()
        clock.tick(60)

if __name__ == '__main__':
    main()

enter image description here