Ive been trying to add levels for a while and this is what ive gotten so far. I have tried to make it so when you click the level 1 button it displays the level 1 tilemap and same for level 2. Right now it says tilemap not defined (i tried saying tilemap = [] but that didnt work either.
play_button = Button(10, 50, 100, 50, WHITE, BLACK, 'Play', 30)
level1 = Button(10, 130, 100, 50, WHITE, BLACK, 'Level 1', 18)
level2 = Button(120, 130, 100, 50, WHITE, BLACK, 'Level 2', 18)
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
intro = False
self.running = False
mouse_pos = pygame.mouse.get_pos()
mouse_pressed = pygame.mouse.get_pressed()
if play_button.is_pressed(mouse_pos, mouse_pressed):
intro = False
if level1.is_pressed(mouse_pos, mouse_pressed):
level1TILEMAP()
intro = False
if level2.is_pressed(mouse_pos, mouse_pressed):
level2TILEMAP()
intro = False
self.screen.blit(self.intro_background, (0,0))
self.screen.blit(play_button.image, play_button.rect)
self.screen.blit(title, title_rect)
self.screen.blit(level1.image, level1.rect)
self.screen.blit(level2.image, level2.rect)
self.clock.tick(FPS)
pygame.display.update()
'''
and these are the 2 tilemap levels:
'''
def level1TILEMAP():
tilemap = [
'BBBBBBBBBBBBBBBBBBBB',
'BP.......B....P....B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'B..BB....B...BB....B',
'B........B.........B',
'B........B.........B',
'B..BB....B...BB....B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'BBBBBBBBBBBBBBBBBBBB',
]
def level2TILEMAP():
tilemap = [
'BBBBBBBBBBBBBBBBBBBB',
'BP.......B....P....B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'B..BB....B....BB...B',
'B........B.........B',
'B........B.........B',
'B........B.........B',
'B....E...B..E......B',
'B........B.........B',
'B........B.........B',
'BBBBBBBBBBBBBBBBBBBB',
]