Mercurial > parpg-source
annotate bGrease/controller/integrator.py @ 178:c706963ed0c3
Made the entities of the current map available in the console.
author | Beliar <KarstenBock@gmx.net> |
---|---|
date | Tue, 06 Mar 2012 15:39:14 +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 __version__ = '$Id$' |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
15 |
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 class EulerMovement(object): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
18 """System that applies entity movement to position using Euler's method |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
19 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
20 :param position_component: Name of :class:`grease.component.Position` |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
21 component to update. |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
22 :param movement_component: Name of :class:`grease.component.Movement` |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
23 component used to update position. |
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 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
26 def __init__(self, position_component='position', movement_component='movement'): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
27 self.position_component = position_component |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
28 self.movement_component = movement_component |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
29 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
30 def set_world(self, world): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
31 """Bind the system to a world""" |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
32 self.world = world |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
33 |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
34 def step(self, dt): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
35 """Apply movement to position""" |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
36 assert self.world is not None, "Cannot run with no world set" |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
37 for position, movement in self.world.components.join( |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
38 self.position_component, self.movement_component): |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
39 movement.velocity += movement.accel * dt |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
40 position.position += movement.velocity * dt |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
41 position.angle += movement.rotation * dt |
a6bbb732b27b
Added .hgeol file to automatically convert line endings.
KarstenBock@gmx.net
parents:
41
diff
changeset
|
42 |