我想知道如何改变所使用的黑色块的颜色,这样玩家就不会摔倒在世界各地。
即时发布我认为与之相关的代码,如果您需要更多,请告诉我
我希望它们像我的背景颜色一样绿色只是有点暗我知道颜色怎么样,只是不知道改变它的位置,因为块是黑色的,我不认为它们定义为任何颜色
class Block:
def __init__ (self, x, y):
self.x = x
self.y = y
self.width = 32
self.height = 32
def render(self,screen):
pygame.draw.rect(screen,(0,0,0),(self.x, self.y, self.width, self.height))
gravity = -0.5
black = (0,0,0)
white = (255,255,255)
blue = (50,60,200)
clock = pygame.time.Clock()
player = player(0,0)
# 25 colums and 19 rows
level1 = [
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
]
blockList = []
for y in range (0,len(level1)):
for x in range (0,len(level1[y])):
if (level1[y][x] == 1):
blockList.append(Block(x*32, y*32))
答案 0 :(得分:1)
pygame.draw.rect
的参数(Surface, color, Rect, width=0)
,因此您需要调整第二个参数,以便在您当时绘制的任何矩形上获得所需的颜色。您可以像这样修改Block
类:
class Block:
def __init__ (self, x, y, color = (0,0,0)):
self.x = x
self.y = y
self.width = 32
self.height = 32
self.color = color
def render(self,screen):
pygame.draw.rect(screen,self.color,(self.x, self.y, self.width, self.height))
除非你传递任何其他颜色,否则默认为黑色。我不确定我知道你希望块在哪里是绿色的,但无论在哪种情况下,你只需要将你想要的颜色变量传递到你正在创建的块中。