I am trying to make a simple 2d game map in Pygame but have run into a problem with the tile layout. I tried to make the map with a 2d array but it is not working. They are all appearing on one line. My goal is to make a simple 2d map via an array with just the rects. Here is the code.
import pygame
pygame.init()
root = pygame.display.set_mode((500,500))
pygame.display.set_caption("Game")
surface = pygame.Surface((60, 60), pygame.SRCALPHA)
rect = pygame.draw.rect(surface, (255, 0, 0), (50, 50, 50, 50)) , (50, 50)
surface_one = pygame.Surface((60, 60), pygame.SRCALPHA)
rect_one = pygame.draw.rect(surface_one, (0, 255, 0), (50, 50, 50, 50)) , (50, 50)
def main():
tileX = 0
tileY = 0
map = [[0,0,0,0],
[1,1,1,1],
[1,0,1,0]]
for x in map:
for x in x:
if x == 0:
root.blit(surface, [tileX, tileY])
tileX = tileX+16
if x == 1:
root.blit(surface_one, [tileX, tileY])
tileX = tileX+16
tileX = 0
tileY += 30
pygame.display.update()
run = True
while run:
pygame.time.delay(100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
main()