move float

This commit is contained in:
Frank DeMarco 2013-03-17 20:30:27 +09:00
parent f2de153016
commit a9fdb230c9
1 changed files with 16 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from pygame.image import load
from pygame.locals import *
from Animation import Animation
from Point import Point
class Sprite(Animation):
@ -14,6 +15,7 @@ class Sprite(Animation):
self.frames = []
self.frame_index = 0
self.rect = Rect((0, 0, 0, 0))
self.motion_overflow = Point()
self.deactivate()
def deactivate(self):
@ -61,7 +63,20 @@ class Sprite(Animation):
self.frame_index = index
def move(self, dx=0, dy=0):
self.rect.move_ip(dx, dy)
rect = self.rect
if isinstance(dx, float) or isinstance(dy, float):
excess = self.update_motion_overflow(dx, dy)
rect.move_ip(int(dx) + excess[0], int(dy) + excess[1])
else:
rect.move_ip(dx, dy)
def update_motion_overflow(self, dx, dy):
overflow = self.motion_overflow
overflow.move(dx - int(dx), dy - int(dy))
excess = map(int, overflow)
overflow[0] -= int(overflow[0])
overflow[1] -= int(overflow[1])
return excess
def update(self):
if self.active: