所以我收到一个错误,说super()接受1个参数,但它想要采取什么参数???我真的不知道它要求的是什么!有人可以帮我修理它,或者至少告诉我什么是错的吗?
import pygame
# Define some colors
BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
GREEN = ( 0, 255, 0)
RED = ( 255, 0, 0)
class Me(pygame.sprite.Sprite):
super().__init__()
def __init__(self, color, width, height):
self.image = pygame.Surface([width, height])
self.image.fill(color)
self.rect = self.image.get_rect()
you = pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()
player = Player(GREEN, 20, 15)
all_sprites_list.add(player)
pygame.init()
# Set the width and height of the screen [width, height]
size = (800, 600)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Karl's Game")
#Loop until the user clicks the close button.
done = False
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
#Loading pictures
background_image = pygame.image.load("back.jpg").convert()
#Variables
# Speed in pixels per frame
x_speed = 0
y_speed = 0
# Current position
x_coord = 10
y_coord = 10
# -------- Main Program Loop -----------
while not done:
# --- Main event loop
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
elif event.type == pygame.KEYDOWN:
# Figure out if it was an arrow key. If so
# adjust speed.
if event.key == pygame.K_LEFT:
x_speed = -3
elif event.key == pygame.K_RIGHT:
x_speed = 3
if x_coord > 200:
x_speed = 0
elif event.key == pygame.K_UP:
y_speed = -3
elif event.key == pygame.K_DOWN:
y_speed = 3
elif event.type == pygame.KEYUP:
# If it is an arrow key, reset vector back to zero
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_speed = 0
elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
y_speed = 0
x_coord = x_coord + x_speed
y_coord = y_coord + y_speed
player.rect.x = pos[x_coord]
player.rect.y = pos[y_coord]
# First, clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.
# --- Drawing code should go here
screen.blit(background_image, [0,0])
drawSquare(screen, x_coord, y_coord)
# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# --- Limit to 60 frames per second
clock.tick(45)
# Close the window and quit.
# If you forget this line, the program will 'hang'
# on exit if running from IDLE.
pygame.quit()
答案 0 :(得分:1)
你必须在课程 init (自我):function中移动你的super()调用。它应该是方法的第一行。
此外,超级电话应该阅读。
super(Me, self).__init__()