I'm trying to create a two-player game in which each player is the object of a class. However, when I run my code, the command prompt gives me an error in line 43, saying that update() is missing a positional argument: "function"
class player(pygame.sprite.Sprite):
lives = 5
def __init__(self, left, right, img):
super(player, self).__init__()
self.surface = pygame.image.load(img).convert_alpha()
self.rect = self.surface.get_rect()
self.left = left
self.left = right
def update(self, function):
if function[self.left]:
self.rect.move_ip(-5, 0)
if function[self.right]:
self.rect.move_ip(5, 0)
player1 = player(K_LEFT, K_RIGHT, "jet1.png")
player2 = player(K_a, K_d, "jet2.png")
open = True
while open:
for event in pygame.event.get():
if pygame.key.get_pressed()[K_ESCAPE]:
open = False
elif event.type == QUIT:
open = False
pressed = pygame.key.get_pressed()
player.update(pressed)
display.blit(player1.surface, (width/4, height/4))
display.blit(player2.surface, (.75 * width, .75 * height))
Also, when I take off the "function" argument in the update function, I get another error that says: 'pygame.key.ScancodeWrapper' object has no attribute 'left'
I'm relatively new to Python and Pygame, so any help would be greatly appreciated!