comparison bGrease/component/__init__.py @ 65:e856b604b650

Changed "import bGrease" to "import parpg.bGrease".
author KarstenBock@gmx.net
date Wed, 21 Sep 2011 16:10:14 +0200
parents ff3e395abf91
children
comparison
equal deleted inserted replaced
64:b73050f98411 65:e856b604b650
28 """ 28 """
29 29
30 __version__ = '$Id$' 30 __version__ = '$Id$'
31 31
32 __all__ = ('Component', 'ComponentError', 'Position', 'Transform', 'Movement', 32 __all__ = ('Component', 'ComponentError', 'Position', 'Transform', 'Movement',
33 'Shape', 'Renderable', 'Collision') 33 'Shape', 'Renderable', 'Collision')
34 34
35 from bGrease.component.general import Component 35 from parpg.bGrease.component.general import Component
36 from bGrease.geometry import Vec2d, Vec2dArray, Rect 36 from parpg.bGrease.geometry import Vec2d, Vec2dArray, Rect
37 from bGrease import color 37 from parpg.bGrease import color
38 38
39 39
40 class ComponentError(Exception): 40 class ComponentError(Exception):
41 """General component error""" 41 """General component error"""
42 42
43 43
44 class Position(Component): 44 class Position(Component):
45 """Predefined component that stores position and orientation info for 45 """Predefined component that stores position and orientation info for
46 entities. 46 entities.
47 47
48 Fields: 48 Fields:
49 49
50 - **position** (Vec2d) -- Position vector 50 - **position** (Vec2d) -- Position vector
51 - **angle** (float) -- Angle, in degrees 51 - **angle** (float) -- Angle, in degrees
52 """ 52 """
53 53
54 def __init__(self): 54 def __init__(self):
55 Component.__init__(self, position=Vec2d, angle=float) 55 Component.__init__(self, position=Vec2d, angle=float)
56 56
57 57
58 class Transform(Component): 58 class Transform(Component):
59 """Predefined component that stores offset, shear, 59 """Predefined component that stores offset, shear,
60 rotation and scale info for entity shapes. 60 rotation and scale info for entity shapes.
61
62 Fields:
63 61
64 - **offset** (Vec2d) 62 Fields:
65 - **shear** (Vec2d)
66 - **rotation** (float)
67 - **scale** (float, default 1.0)
68 """
69 63
70 def __init__(self): 64 - **offset** (Vec2d)
71 Component.__init__(self, offset=Vec2d, shear=Vec2d, rotation=float, scale=float) 65 - **shear** (Vec2d)
72 self.fields['scale'].default = lambda: 1.0 66 - **rotation** (float)
67 - **scale** (float, default 1.0)
68 """
69
70 def __init__(self):
71 Component.__init__(self, offset=Vec2d, shear=Vec2d, rotation=float, scale=float)
72 self.fields['scale'].default = lambda: 1.0
73 73
74 74
75 class Movement(Component): 75 class Movement(Component):
76 """Predefined component that stores velocity, 76 """Predefined component that stores velocity,
77 acceleration and rotation info for entities. 77 acceleration and rotation info for entities.
78
79 Fields:
80 78
81 - **velocity** (Vec2d) -- Rate of change of entity position 79 Fields:
82 - **accel** (Vec2d) -- Rate of change of entity velocity
83 - **rotation** (Vec2d) -- Rate of change of entity angle, in degrees/time
84 """
85 80
86 def __init__(self): 81 - **velocity** (Vec2d) -- Rate of change of entity position
87 Component.__init__(self, velocity=Vec2d, accel=Vec2d, rotation=float) 82 - **accel** (Vec2d) -- Rate of change of entity velocity
83 - **rotation** (Vec2d) -- Rate of change of entity angle, in degrees/time
84 """
85
86 def __init__(self):
87 Component.__init__(self, velocity=Vec2d, accel=Vec2d, rotation=float)
88 88
89 89
90 class Shape(Component): 90 class Shape(Component):
91 """Predefined component that stores shape vertices for entities 91 """Predefined component that stores shape vertices for entities
92
93 - **closed** (bool) -- If the shapes is closed implying an edge between
94 last and first vertices.
95 - **verts** (Vec2dArray) -- Array of vertex points
96 """
97 92
98 def __init__(self): 93 - **closed** (bool) -- If the shapes is closed implying an edge between
99 Component.__init__(self, closed=int, verts=Vec2dArray) 94 last and first vertices.
100 self.fields['closed'].default = lambda: 1 95 - **verts** (Vec2dArray) -- Array of vertex points
96 """
97
98 def __init__(self):
99 Component.__init__(self, closed=int, verts=Vec2dArray)
100 self.fields['closed'].default = lambda: 1
101 101
102 102
103 class Renderable(Component): 103 class Renderable(Component):
104 """Predefined component that identifies entities to be 104 """Predefined component that identifies entities to be
105 rendered and provides their depth and color. 105 rendered and provides their depth and color.
106
107 - **depth** (float) -- Drawing depth, can be used to determine z-order
108 while rendering.
109 - **color** (color.RGBA) -- Color used for entity. The effect of this
110 field depends on the renderer.
111 """
112 106
113 def __init__(self): 107 - **depth** (float) -- Drawing depth, can be used to determine z-order
114 Component.__init__(self, depth=float, color=color.RGBA) 108 while rendering.
115 self.fields['color'].default = lambda: color.RGBA(1,1,1,1) 109 - **color** (color.RGBA) -- Color used for entity. The effect of this
110 field depends on the renderer.
111 """
112
113 def __init__(self):
114 Component.__init__(self, depth=float, color=color.RGBA)
115 self.fields['color'].default = lambda: color.RGBA(1,1,1,1)
116 116
117 117
118 class Collision(Component): 118 class Collision(Component):
119 """Predefined component that stores collision masks to determine 119 """Predefined component that stores collision masks to determine
120 which entities can collide. 120 which entities can collide.
121 121
122 Fields: 122 Fields:
123 123
124 - **aabb** (Rect) -- The axis-aligned bounding box for the entity. 124 - **aabb** (Rect) -- The axis-aligned bounding box for the entity.
125 This is used for broad-phase collision detection. 125 This is used for broad-phase collision detection.
126 126
127 - **radius** (float) -- The collision radius of the entity, used for narrow-phase 127 - **radius** (float) -- The collision radius of the entity, used for narrow-phase
128 collision detection. The exact meaning of this value depends on the collision 128 collision detection. The exact meaning of this value depends on the collision
129 system in use. 129 system in use.
130
131 - **from_mask** (int) -- A bitmask that determines what entities this object
132 can collide with.
133 130
134 - **into_mask** (int) -- A bitmask that determines what entities can collide 131 - **from_mask** (int) -- A bitmask that determines what entities this object
135 with this object. 132 can collide with.
136 133
137 When considering an entity A for collision with entity B, A's ``from_mask`` is 134 - **into_mask** (int) -- A bitmask that determines what entities can collide
138 bit ANDed with B's ``into_mask``. If the result is nonzero (meaning 1 or more 135 with this object.
139 bits is set the same for each) then the collision test is made. Otherwise,
140 the pair cannot collide.
141 136
142 The default value for both of these masks is ``0xffffffff``, which means that 137 When considering an entity A for collision with entity B, A's ``from_mask`` is
143 all entities will collide with each other by default. 138 bit ANDed with B's ``into_mask``. If the result is nonzero (meaning 1 or more
144 """ 139 bits is set the same for each) then the collision test is made. Otherwise,
145 def __init__(self): 140 the pair cannot collide.
146 Component.__init__(self, aabb=Rect, radius=float, from_mask=int, into_mask=int)
147 self.fields['into_mask'].default = lambda: 0xffffffff
148 self.fields['from_mask'].default = lambda: 0xffffffff
149 141
142 The default value for both of these masks is ``0xffffffff``, which means that
143 all entities will collide with each other by default.
144 """
145 def __init__(self):
146 Component.__init__(self, aabb=Rect, radius=float, from_mask=int, into_mask=int)
147 self.fields['into_mask'].default = lambda: 0xffffffff
148 self.fields['from_mask'].default = lambda: 0xffffffff