如何使用非整数移动创建基于图块的移动?
我知道如何创建基于图块的移动并创建非整数移动,但不能同时创建两者。
以下是我已经完成的事情:
self.acc = vec(0 ,0)
keystate = pygame.key.get_pressed()
if keystate[pygame.K_UP]:
self.acc.y = -PLAYER_ACC
if keystate[pygame.K_DOWN]:
self.acc.y = PLAYER_ACC
if keystate[pygame.K_LEFT]:
self.acc.x = -PLAYER_ACC
if keystate[pygame.K_RIGHT]:
self.acc.x = PLAYER_ACC
self.acc += self.vel * PLAYER_FRICTION
self.vel += self.acc
if abs(self.vel.x) < 0.1:
self.vel.x = 0
if abs(self.vel.y) < 0.1:
self.vel.y = 0
self.pos += self.vel * self.game.dt
self.rect.center = self.pos
答案 0 :(得分:0)
谢谢@Blckknght,我改变了我的算法并且它有效:
self.acc = vec(0 ,0)
keystate = pygame.key.get_pressed()
if keystate[pygame.K_UP]:
self.acc.y = -PLAYER_ACC
if keystate[pygame.K_DOWN]:
self.acc.y = PLAYER_ACC
if keystate[pygame.K_LEFT]:
self.acc.x = -PLAYER_ACC
if keystate[pygame.K_RIGHT]:
self.acc.x = PLAYER_ACC
self.acc += self.vel * PLAYER_FRICTION
self.vel += self.acc * self.game.dt
if abs(self.vel.x) < 0.1:
self.vel.x = 0
if abs(self.vel.y) < 0.1:
self.vel.y = 0
self.pos += self.vel
self.rect.center = self.pos
12号线和17号线改变了。