I've never written in python before but I'm trying to do collision detection for when two ovals collide, one of the ovals (the bubble/mine) will be deleted.
def delete_bubble(k):
bubble_id[k].remove
bubble_r[k].remove
def get_dist(mine,sub):
x = c.coords(mine)
a = c.coords(sub)
#compare coordinates and if same, return 0
def collide():
for k in range(len(bubble_id)):
x = get_dist(bubble_id[k],ship_c)
if x == 0:
delete_bubble(k)
How do I calculate the distance between the two ovals, mine and sub? if x == a then return 0? Or do I need to write a distance formula to calculate, or do I need to find the center of each oval and compare? I have the radius of each oval as well but I'm confused as to how to write this. Since this is part of an interactive game, I need to continuously check for collisions, how would I implement that in main:
#main game loop
for x in range(10):
create_mines(c)
window.after(40, move_mines, c)
window.after(10, collide) #does this work?
window.mainloop()