Python: Collisions with Ovals -
i've never written in python before i'm trying collision detection when 2 ovals collide, 1 of ovals (the bubble/mine) deleted.
def delete_bubble(k): bubble_id[k].remove bubble_r[k].remove def get_dist(mine,sub): x = c.coords(mine) = c.coords(sub) #compare coordinates , if same, return 0 def collide(): k in range(len(bubble_id)): x = get_dist(bubble_id[k],ship_c) if x == 0: delete_bubble(k)
how calculate distance between 2 ovals, mine , sub? if x == return 0? or need write distance formula calculate, or need find center of each oval , compare? have radius of each oval i'm confused how write this. since part of interactive game, need continuously check collisions, how implement in main:
#main game loop x in range(10): create_mines(c) window.after(40, move_mines, c) window.after(10, collide) #does work? window.mainloop()
i made program can sense collision detection in python, here is:
if oval 1 x < oval 2 x + oval 1 width , oval 1 x + oval 2 width > oval 2 x , oval 1 y < oval 2 y + oval 1 height , oval 2 height + oval 1 y > oval 2 y: #put code deletes oval here
this works putting ovals in "imaginary box" , senses if of edges of first "imaginary box" touching of edges of second "imaginary box". hope helped.
Comments
Post a Comment