所以我开始用 Python/Pygame 编写一个小方块放置游戏。我写了代码,理论上它看起来很完美。它应该能够在按下鼠标时放置多个块。这是代码:
import pygame
from pygame.locals import *
pygame.init()
screen=pygame.display.set_mode((640,480),0)
blocklistDIRT=[]
class block(object):
sprite = None
def __init__(self, x, y):
if not block.sprite:
block.sprite = pygame.image.load("dirt.png").convert_alpha()
self.rect = block.sprite.get_rect(top=y, left=x)
blocklist = []
while True:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
mse=pygame.mouse.get_pos()
blocklist.append(block(mse[0],mse[1]))
if event.type == QUIT:
exit()
for block in blocklist:
screen.blit(block.sprite, block.rect)
pygame.display.update()
每次我去放置第二个块..我得到这个错误:
回溯(最近一次调用):文件“C:\Users\samis_000\Desktop\blockgame.pyw”,第 20 行,在 blocklist.append(block(mse[0],mse[1])) 类型错误:'block'对象不可调用
有人告诉我我做错了什么:(