annotate src/parpg/bGrease/controller/integrator.py @ 165:6d07093e9d51

Added context menu to the inventory.
author KarstenBock@gmx.net
date Sat, 08 Oct 2011 14:25:48 +0200
parents 96af64cf3b81
children
rev   line source
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
1 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
2 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
3 # Copyright (c) 2010 by Casey Duncan and contributors
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
4 # All Rights Reserved.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
5 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
6 # This software is subject to the provisions of the MIT License
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
7 # A copy of the license should accompany this distribution.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
11 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
12 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
13
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
14 __version__ = '$Id$'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
15
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
16
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
17 class EulerMovement(object):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
18 """System that applies entity movement to position using Euler's method
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
19
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
20 :param position_component: Name of :class:`grease.component.Position`
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
21 component to update.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
22 :param movement_component: Name of :class:`grease.component.Movement`
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
23 component used to update position.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
24 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
25
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
26 def __init__(self, position_component='position', movement_component='movement'):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
27 self.position_component = position_component
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
28 self.movement_component = movement_component
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
29
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
30 def set_world(self, world):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
31 """Bind the system to a world"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
32 self.world = world
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
33
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
34 def step(self, dt):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
35 """Apply movement to position"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
36 assert self.world is not None, "Cannot run with no world set"
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
37 for position, movement in self.world.components.join(
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
38 self.position_component, self.movement_component):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
39 movement.velocity += movement.accel * dt
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
40 position.position += movement.velocity * dt
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
41 position.angle += movement.rotation * dt
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
42