so i made a python game well making and i am making a list/ array of squares for my map as a tile map, but i wanna know how to detect all of them without having to type in all the variables for that if theres another way to make a tilemap or a way to make a colision between these then tell me
import pygame
# initialize
px = 150
py = 150
pygame.init()
# vars
white = (255, 255, 255)
size = (800, 600)
# create the screen
window = pygame.display.set_mode(size)
pygame.display.set_caption("3d raycaster")
clock = pygame.time.Clock()
done = False
while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
window.fill(white)
player = pygame.draw.rect(window, (255, 0, 0), pygame.Rect(px, py, 60, 60))
# tilemap
tilemap = [
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 0, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 60, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 120, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 180, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 240, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 300, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 360, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 420, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 480, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(0, 540, 60, 60)),
pygame.draw.rect(window, (255, 0, 0), pygame.Rect(60, 540, 60, 60)),
]
pygame.display.flip()
clock.tick(60)
# movement
key = pygame.key.get_pressed()
speed = 2.5
if key[pygame.K_LEFT]:
px -= speed
if key[pygame.K_RIGHT]:
px += speed
if key[pygame.K_UP]:
py -= speed
if key[pygame.K_DOWN]:
py += speed
# collision detection
pygame.Rect.colliderect(tilemap, player)
pygame.quit()
so i tried
# colision detection
pygame.Rect.colliderect(tilemap, player)
hoping it will work but i got the error and i expected that it will collide with all the squares in the array/list