def zip(self, *ignore):
"""
method to move sprite image along movedir, previously computed by prep_zip.
also checks for collision with objects
:return: none
"""
self.texture = self.animage['arrow']
self.consider_collide(self.movedir.x,self.movedir.y)
za_collide_point = Vector(self.plotrect.center) # Zero Aligned collide point
za_origin = Vector(self.new.center) # Zero Aligned origin
asa_collider = za_collide_point - za_origin # Need the length of the true vector before normalisation
sa_collider = asa_collider.normalize() # Now normalise for use in iteration later
#len_to_collide = int(round(asa_collider.length()))
len_to_collide = self.animlen # Arbitrary number TODO - implement a better method to decide the len of travel
if len_to_collide > 0: # added to ensure 0 length handling, as it's instantiated as zero
self.zipping = True
for index,coltick in enumerate(xrange(1, len_to_collide)):
lastRect = Rect(self.pos[0]+(self.width*.42)+(sa_collider[0]*index), self.pos[1]+(self.height*.35)
+(sa_collider[1]*index),(self.size[0]*.16), self.size[1]*.29)
# In brief :
# Rect with bottomleft x value of sprite x position, plus 42% of the image width (image is small within
# transparent larger image) plus sa_collider[0] - x value of normalised vector direction to collide
# point multiplied by index to ensure the 'lastRect' is always 1 iteration behind the 'newRect'
# Next values supplied to Rect are for y location, similar logic
# Further values relate to the height/width of the rect instance which should envelope the inner
# sprite drawing. For the purposes of this calculation that's not so important.
newRect = Rect(self.pos[0]+(self.width*.42)+(sa_collider[0]*coltick), self.pos[1]+(self.height*.35)
+(sa_collider[1]*coltick),(self.size[0]*.16), self.size[1]*.29)
# Multiply by coltick for newRect to ensure it's always 1 step ahead of lastRect
if self.move_or_collide(Rect1=newRect, Rect2=lastRect):
break
self.animcoords = newRect.bottomleft[0]-self.width*.42, newRect.bottomleft[1]-self.height*.35
anim = Animation(x = self.animcoords[0], y = self.animcoords[1], duration=self.animduration)
self.animlen = 0
anim.start(self)
Clock.schedule_once(self.notzipping,self.animduration) # schedule the logic updates after animation ends
评论列表
文章目录