我基本上才刚开始使用PyGame进行开发,而整个Sprite概念都遇到了麻烦。我一直在到处寻找有关如何使用它的指南,但似乎找不到任何指南。我想知道所有工作原理的基本概念。这是我一直在努力的代码:#!/usr/bin/pythonimport pygame, sysfrom pygame.locals import *size = width, height = 320, 320clock = pygame.time.Clock()xDirection = 0yDirection = 0xPosition = 32yPosition = 256blockAmount = width/32pygame.init()screen = pygame.display.set_mode(size)screen.fill([0, 155, 255])pygame.display.set_caption("Mario Test")background = pygame.Surface(screen.get_size())mainCharacter = pygame.sprite.Sprite()mainCharacter.image = pygame.image.load("data/character.png").convert()mainCharacter.rect = mainCharacter.image.get_rect()mainCharacter.rect.topleft = [xPosition, yPosition]screen.blit(mainCharacter.image, mainCharacter.rect)grass = pygame.sprite.Sprite()grass.image = pygame.image.load("data/grass.png").convert()grass.rect = grass.image.get_rect()for i in range(blockAmount): blockX = i * 32 blockY = 288 grass.rect.topleft = [blockX, blockY] screen.blit(grass.image, grass.rect)grass.rect.topleft = [64, 256] screen.blit(grass.image, grass.rect.topleft )running = Falsejumping = False falling = Falsestanding = Truejumpvel = 22gravity = -1while True: for event in pygame.event.get(): if event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit() elif event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_LEFT: running = True xRun = -5 elif event.key == K_RIGHT: running = True xRun = 5 elif event.key == K_UP or event.key == K_SPACE: jumping = True elif event.type == KEYUP: if event.key == K_LEFT or event.key == K_RIGHT: running = False基本上,我只是想知道如何将这些草块组合成一个精灵,这样当我添加播放器(也是精灵)时,我可以通过碰撞系统确定他是否在空中。有人可以向我解释我将如何做。我所寻找的基本上只是一个启动器,因为我认为某些文档非常糟糕,因为它不能完全告诉您如何使用它。任何帮助是极大的赞赏 :)
添加回答
举报
0/150
提交
取消