#Need help with collision in pygame

5 messages · Page 1 of 1 (latest)

solid silo
#

I need help with creating a collision between enemy,player and walls in a maze game.

ocean steeple
# solid silo

well you need to create a new rect for each of them(each class)
using this: pygame.Rect(x,y,width,height) and changing the rect every iteration the x,y are changing

you will be able to do: rect1.colliderect(rect2) to get True/False depend on collide or not

#

for example

x1,y1,w,h = 100,100,100,100
rect1 = pygame.Rect(x1,y1,w,h)
rect2 = pygame.Rect(x1,y1+500,w,h)

while True:
if rect1.colliderect(rect2):
print("collide")
y1 += 100
rect1 = pygame.Rect(x1,y1,w,h)

#

in this one the collision will be in the 5 iteration and will be detected in the colliderect if