Soooo我正在编写游戏。我遇到了问题,现在无法找到答案两三天:/
我的问题是我尝试应用动画但是我无法获得我的Player类的坐标或位置(x,y)...
我的播放器代码:(因为空格不好,直接粘贴在我的.py文件中:/)
class Entity(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
class Player(Entity):
def __init__(self, x, y):
Entity.__init__(self)
self.xvel = 0
self.yvel = 0
self.onGround = False
self.image = Surface = pygame.image.load("PlayerModels\Sprites\PlayerStill.gif")
self.rect = Rect(x, y, 32, 55)
def update(self, up, down, left, right, running, platforms):
if up:
# Pasokti tik ant zemes
if self.onGround: self.yvel -= 10
if down:
pass
if running:
self.xvel = 12
if left:
self.xvel = -5
if right:
self.xvel = 5
BegimoAnim.play()
if not self.onGround:
# gravitacija + acceleracija
self.yvel += 0.3
# Max kritimo greitis
if self.yvel > 100: self.yvel = 100
if not(left or right):
self.xvel = 0
# Prieaugis X direkcijoje
self.rect.left += self.xvel
# daryti X axis collision
self.collide(self.xvel, 0, platforms)
# Prieaugis Y direkcijoje
self.rect.top += self.yvel
# Ar ore?
self.onGround = False;
# daryti Y axis collision
self.collide(0, self.yvel, platforms)
def collide(self, xvel, yvel, platforms):
for p in platforms:
if pygame.sprite.collide_rect(self, p):
if isinstance(p, ExitBlock):
pygame.event.post(pygame.event.Event(QUIT))
if xvel > 0:
self.rect.right = p.rect.left
if xvel < 0:
self.rect.left = p.rect.right
if yvel > 0:
self.rect.bottom = p.rect.top
self.onGround = True
self.yvel = 0
if yvel < 0:
self.rect.top = p.rect.bottom
我在blitting需要帮助(BTW我应该blit?):
for y in range(32):
for x in range(32):
screen.blit(bg, (x * 32, y * 32))
camera.update(player)
player.update(up, down, left, right, running, platforms)
for e in entities:
screen.blit(e.image, camera.apply(e))
BegimoAnim.blit(screen, (xPlayer, yPlayer)) #help in here, how to?? (BegimoAnim means RunningAnim)
pygame.display.update()
编辑:告诉我你是否需要我添加我的代码的其他部分......
答案 0 :(得分:0)
在更多地探索我的代码并尝试使用各种编码来找到我的问题的修复后,我发现我已经创建了一个有位置的pygame播放器值...