我有一個應該允許兩個玩家玩的遊戲。但是,當用戶按下按鍵時,第二個玩家不會移動。 (平面2是第二個玩家)Python精靈播放器控制問題
class Plane(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("plane.gif")
self.image = self.image.convert()
self.rect = self.image.get_rect()
if not pygame.mixer:
print "problem with sound"
else:
pygame.mixer.init()
self.sndDing = pygame.mixer.Sound("ding.ogg")
self.sndCrash = pygame.mixer.Sound("planeCrash.ogg")
def update(self):
mousex, mousey = pygame.mouse.get_pos()
self.rect.center = (mousex, mousey)
class Plane2(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("plane2.gif")
self.image = self.image.convert()
self.rect = self.image.get_rect()
self.rect.centerx = 320
self.rect.centery = 240
def update(self):
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
self.rect.centerx -= 8
if event.key == pygame.K_RIGHT:
self.rect.centerx += 8
if event.key == pygame.K_UP:
self.rect.centery += 8
if event.key == pygame.K_DOWN:
self.rect.centery -= 8
我試圖爲移動的平面2更新功能進入遊戲圈,但沒有解決問題。
def gameEndless():
pygame.display.set_caption("Mail Pilot!")
background = pygame.Surface(screen.get_size())
background.fill((0, 0, 0))
screen.blit(background, (0, 0))
plane = Plane()
island = Island()
ocean = Ocean()
scoreboard = Scoreboard()
oceanSprites = pygame.sprite.Group(ocean)
islandSprites = pygame.sprite.Group(island)
planeSprite = pygame.sprite.Group(plane)
scoreSprite = pygame.sprite.Group(scoreboard)
bulletSprites = pygame.sprite.Group()
enemySprites = pygame.sprite.Group()
bossSprite = pygame.sprite.Group()
bossWeaponSprites = pygame.sprite.Group()
if gameType == "coop":
scoreboard.lives = 10
player2 = Plane2()
planeSprite.add(player2)
我也嘗試讓第二個玩家成爲自己的精靈羣,但那也沒有幫助。