-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.py
48 lines (36 loc) · 1.19 KB
/
misc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from collections import namedtuple
import pygame
class Point(namedtuple('Point', 'x y')):
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y)
def __sub__(self, other):
return Point(self.x - other.x, self.y - other.y)
def __neg__(self):
return Point(0, 0) - self
class PygameSurfaceDecorator:
"""
A wrapper class around pygame surfaces that monkey patches differences
between pymlgame and pygame
"""
def __getattribute__(self, item):
"""
method that tries to first return method of decorator.
If that method is not present this methods tries to return
the property from the decorated object.
"""
try:
v = object.__getattribute__(self, item)
except AttributeError:
v = getattr(object.__getattribute__(self, 'surface'), item)
return v
def __init__(self, surface):
self.surface = surface
@property
def width(self):
return self.surface.get_width()
@property
def height(self):
return self.surface.get_height()
@property
def matrix(self):
return pygame.surfarray.array3d(self.surface)