# Collision Detection without Coordinates in Tilemaps in Pygame

So if I wan’t to make a collision detection with rectangles, than I can just do this as I have the coordinates of the rectangle:

``rcx = 200 rcy = 200 rcw = 200 rch = 100 plx = 500 ply = 450 plw = 50 plh = 50 rectcolor = (100, 150, 200)  testobj = pygame.draw.rect(win, rectcolor, (rcx, rcy, rcw, rch)) player = pygame.draw.rect(win, (150, 200, 100), (plx, ply, plw, plh))     if plx <= rcx + rcw and plx + plw >= rcx and ply <= rcy + rch and ply + plh >= rcy:     rectcolor = (50, 100, 50) else:     rectcolor = (100, 150, 200) ``

Ok, good! I made a collision detection with rectangles because I know the coordinates of the rectangles. (I don’t think this is the most efficient way but it works) Anyways I am programming a Bomberman game, right now I don’t have any sprites but I use rectangles for it. This is my code:

``import pygame  pygame.init()  WinWidth = 800 WinHeight = 608 p1x = 32 p1y = 32 vel = 1 clock = pygame.time.Clock()  win = pygame.display.set_mode((WinWidth, WinHeight))  def player():     pygame.draw.rect(win, (0, 200, 200), (p1x, p1y, 32, 32))  class invi:     def __init__(self, x, y):         self.x = x         self.y = y         pygame.draw.rect(win, (0, 255, 200), (x, y, 32, 32))   class Wall:     def __init__(self, x, y):         self.x = x         self.y = y         pygame.draw.rect(win, (50, 50, 50), (x, y, 32, 32))   class Breakable:     def __init__(self, x, y):         self.x = x         self.y = y         pygame.draw.rect(win, (200, 150, 100), (x, y, 32, 32))   game_map1 = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],              [0, 10, 10, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 10, 10, 0],              [0, 10, 0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 2, 0, 2, 0, 10, 0],              [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0],              [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0],              [0, 2, 2, 2, 2, 10, 10, 2, 2, 10, 2, 2, 10, 10, 2, 2, 2, 2, 0],              [0, 2, 0, 2, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 2, 0, 2, 0],              [0, 2, 2, 2, 2, 2, 0, 2, 2, 10, 2, 2, 0, 2, 2, 2, 2, 2, 0],              [0, 2, 0, 2, 0, 2, 0, 2, 10, 10, 10, 2, 0, 2, 0, 2, 0, 2, 0],              [0, 0, 0, 2, 2, 10, 10, 10, 10, 10, 10, 10, 10, 10, 2, 2, 0, 0, 0],              [0, 2, 0, 2, 0, 2, 0, 2, 10, 10, 10, 2, 0, 2, 0, 2, 0, 2, 0],              [0, 2, 2, 2, 2, 2, 0, 2, 2, 10, 2, 2, 0, 2, 2, 2, 2, 2, 0],              [0, 2, 0, 2, 0, 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 2, 0, 2, 0],              [0, 2, 2, 2, 2, 10, 10, 2, 2, 10, 2, 2, 10, 10, 2, 2, 2, 2, 0],              [0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0],              [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0],              [0, 10, 0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 2, 0, 2, 0, 10, 0],              [0, 10, 10, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 10, 10, 0],              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]  run = True while run:      pygame.init()      clock.tick(100)     win.fill((0, 255, 200))     y = 0     for layer in game_map1:         x = 0         for tile in layer:             if tile == 0:                 Wall(x * 32, y * 32)             if tile == 10:                 invi(x * 32, y * 32)             if tile == 2:                 Breakable(x * 32, y * 32)             x += 1         y += 1      player()      for event in pygame.event.get():         if event.type == pygame.QUIT:             pygame.quit()             run = False     if event.type == pygame.KEYDOWN:         if event.key == pygame.K_d:             p1x += vel         elif event.key == pygame.K_a:             p1x -= vel      pygame.display.update() ``

sooo… I watched a tutorial and even tried to make a collision detection on my own. But I just can’t do it. I don’t have coordinates for the rectangles in the tilemap and there are very much rectangles in the tilemap, too. How could you make a collision detection with a tilemap with no coordinates and many rectangles? And yeah, the game doesn’t have much stuff going un ’til now… oh and I deleted the parts where I tried to make a collision detection as they all were bad, didn’t work, took up much of the place and just made the whole code more confusing.

Btw if this is not a good question to ask in this StackExchange Q&A Website, sorry, im new to this Website. But I would still be happy to get an answer on this question! ðŸ™‚