This commit is contained in:
Frank DeMarco 2013-04-04 23:35:41 +09:00
parent b586be3b3b
commit 2e4fd0b3df
3 changed files with 67 additions and 21 deletions

View File

@ -1,19 +0,0 @@
class Point(list):
def __init__(self, x=0, y=0):
list.__init__(self, (x, y))
def place(self, x=None, y=None):
if x is not None:
self[0] = x
if y is not None:
self[1] = y
def move(self, dx=0, dy=0):
if dx:
self[0] += dx
if dy:
self[1] += dy
def place_at_origin(self):
list.__init__(self, (0, 0))

View File

@ -7,7 +7,7 @@ from pygame.transform import flip
from pygame.locals import *
from Animation import Animation
from Point import Point
from Vector import Vector
class Sprite(Animation):
@ -17,7 +17,7 @@ class Sprite(Animation):
self.frame_index = 0
self.mirrored = False
self.rect = Rect((0, 0, 0, 0))
self.motion_overflow = Point()
self.motion_overflow = Vector()
self.display_surface = self.get_screen()
def set_framerate(self, framerate):

65
pgfw/Vector.py Normal file
View File

@ -0,0 +1,65 @@
class Vector(list):
def __init__(self, x=0, y=0):
list.__init__(self, (x, y))
def __getattr__(self, name):
if name == "x":
return self[0]
elif name == "y":
return self[1]
def __setattr__(self, name, value):
if name == "x":
self[0] = value
elif name == "y":
self[1] = value
else:
list.__setattr__(self, name, value)
def __add__(self, other):
return Vector(self.x + other[0], self.y + other[1])
__radd__ = __add__
def __iadd__(self, other):
self.x += other[0]
self.y += other[1]
return self
def __sub__(self, other):
return Vector(self.x - other[0], self.y - other[1])
def __rsub__(self, other):
return Vector(other[0] - self.x, other[1] - self.y)
def __isub__(self, other):
self.x -= other[0]
self.y -= other[1]
return self
def __mul__(self, other):
return Vector(self.x * other, self.y * other)
__rmul__ = __mul__
def __imul__(self, other):
self.x *= other
self.y *= other
return self
def place(self, x=None, y=None):
if x is not None:
self.x = x
if y is not None:
self.y = y
def move(self, dx=0, dy=0):
if dx:
self.x += dx
if dy:
self.y += dy
def place_at_origin(self):
self.x = 0
self.y = 0