I am looking for a different way to create collision detection using Zelle Graphics and find_overlapping. I believe the overlapping shows where the bounding box of an object has come in contact with the bounding box of another object (the tuple)? I was hoping for some feedback on this code. Presently, the object goes through the rectangle before it breaks, but I think the idea has merit. This is just a test and need much more fine tuning.
from graphics import *
win = GraphWin("game loop", 500, 500, autoflush=False)
win.master.attributes('-topmost', True)
x=20
y=20
dx=20
play=0
cir1=Circle(Point(x,y),10)
cir1.setFill("red")
cir1.draw(win)
x1=300
x2=310
y1=0
y2=50
rect1=Rectangle(Point(x1,y1),Point(x2,y2))
rect1.setFill("blue")
rect1.draw(win)
xwidth=win.getWidth()
while play==0:
for i in range(100):
xposition = cir1.getCenter().getX()
test1=win.find_overlapping(x1,y1,x2,y2)
print("This is the length of test1:",len(test1))
print(test1)
if xposition+1>=xwidth or xposition-1<=0:
dx=-dx
cir1.move(dx, 0)
update(15)
if len(test1)==2:
print("overlap")
play=1
break
print("game over")
win.mainloop()