Mercurial > parpg-source
annotate bGrease/__init__.py @ 177:62aed6388159
Fixed showing the console.
author | Beliar |
---|---|
date | Tue, 06 Mar 2012 15:15:18 +0100 |
parents | a6bbb732b27b |
children |
rev | line source |
---|---|
166
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
1 ############################################################################# |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
2 # |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
3 # Copyright (c) 2010 by Casey Duncan and contributors |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
4 # All Rights Reserved. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
5 # |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
6 # This software is subject to the provisions of the MIT License |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
7 # A copy of the license should accompany this distribution. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
11 # |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
12 ############################################################################# |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
13 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
14 __versioninfo__ = (0, 3, 0) |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
15 __version__ = '.'.join(str(n) for n in __versioninfo__) |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
16 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
17 __all__ = ('BaseWorld', 'Entity', 'System', 'Renderer') |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
18 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
19 import component |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
20 import geometry |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
21 import collision |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
22 from entity import Entity |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
23 from world import BaseWorld |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
24 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
25 import abc |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
26 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
27 class System(object): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
28 """Grease system abstract base class. Systems define behaviorial aspects |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
29 of a |World|. All systems must define a :meth:`step` |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
30 method that is invoked by the world each timestep. User-defined systems |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
31 are not required to subclass this class. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
32 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
33 See :ref:`an example system from the tutorial <tut-system-example>`. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
34 """ |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
35 __metaclass__ = abc.ABCMeta |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
36 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
37 world = None |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
38 """The |World| this system belongs to""" |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
39 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
40 def set_world(self, world): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
41 """Bind the system to a world""" |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
42 self.world = world |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
43 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
44 @abc.abstractmethod |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
45 def step(self, dt): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
46 """Execute a time step for the system. Must be defined |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
47 by all system classes. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
48 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
49 :param dt: Time since last step invocation |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
50 :type dt: float |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
51 """ |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
52 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
53 class Renderer(object): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
54 """Grease renderer abstract base class. Renderers define the presentation |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
55 of a |World|. All renderers must define a :meth:`draw` |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
56 method that is invoked by the world when the display needs to be redrawn. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
57 User-defined renderers are not required to subclass this class. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
58 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
59 See :ref:`an example renderer from the tutorial <tut-renderer-example>`. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
60 """ |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
61 __metaclass__ = abc.ABCMeta |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
62 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
63 world = None |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
64 """The |World| this renderer belongs to""" |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
65 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
66 def set_world(self, world): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
67 """Bind the system to a world""" |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
68 self.world = world |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
69 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
70 @abc.abstractmethod |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
71 def draw(self): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
72 """Issue drawing commands for this renderer. Must be defined |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
73 for all renderer classes. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
74 """ |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
75 |