Implement interaction between squares of different sizes
This commit is contained in:
@ -348,8 +348,14 @@ class Painter(Widget):
|
||||
def check_interaction_unselected_element(self,element,offset):
|
||||
for particle in self.unselected:
|
||||
for square in particle.squares:
|
||||
if square.check_interaction(element.pos+offset):
|
||||
# add offset
|
||||
element.pos+=offset
|
||||
if square.check_interaction(element):
|
||||
# reset offset
|
||||
element.pos-=offset
|
||||
return True
|
||||
# reset offset
|
||||
element.pos-=offset
|
||||
return False
|
||||
|
||||
|
||||
@ -387,16 +393,21 @@ class Painter(Widget):
|
||||
for other in self.unselected:
|
||||
for obstacle in other.squares:
|
||||
# move would make element overlap with obstacle
|
||||
if obstacle.check_interaction(element.pos+delta):
|
||||
element.pos+=delta
|
||||
if obstacle.check_interaction(element):
|
||||
element.pos-=delta
|
||||
accept_newpos=False
|
||||
# check if particle already touches obstacle
|
||||
if obstacle.check_touch(element.pos):
|
||||
if obstacle.check_touch(element):
|
||||
# move along obstacle while remaining stuck
|
||||
newdelta=obstacle.move_along(delta,element.pos)
|
||||
newdelta=obstacle.move_along(delta,element)
|
||||
else:
|
||||
newdelta=obstacle.move_on_line_to_stick(element.pos,delta)
|
||||
newdelta=obstacle.move_on_line_to_stick(element,delta)
|
||||
if not self.check_interaction_unselected_element(element,newdelta):
|
||||
return newdelta
|
||||
else:
|
||||
# reset offset
|
||||
element.pos-=delta
|
||||
if accept_newpos:
|
||||
return delta
|
||||
else:
|
||||
|
Reference in New Issue
Block a user