How to check collision between objects of same class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to check collision between objects of same class

I have class Block which creates rectangle and makes it fall. But when i try to check for collision between multiple blocks, they either collide with itself or freeze after first collision. Full code which can be run online: https://replit.com/@artur10563/sololearn?v=1

8th Aug 2022, 1:51 PM
Artur
Artur - avatar
2 Answers
+ 1
Fake girl , i already made it work ( kind of ) but yeah, that's what i mean. Is there any way to check for collision between objects of same class using method
8th Aug 2022, 4:21 PM
Artur
Artur - avatar
0
Mirielle, i tried this and it`s getting stuck on "if b is not self" def fall(self, blocks): for block in blocks: if block is not self: if self.rect.colliderect(block): self.rect.move_ip(0,1) done = False while not done: for event in pygame.event.get(): if event.type == QUIT: done = True if event.type == fall_delay_event: for block in blocks: block.fall(blocks)
13th Aug 2022, 1:04 PM
Artur
Artur - avatar