Mercurial > fife-parpg
annotate demos/shooter/scripts/common/baseobject.py @ 473:b78020d31186
Small update to ensure python doesn't try to delete objects that FIFE owns.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 20 Apr 2010 20:36:58 +0000 |
parents | ac0f62a07a3e |
children | 78a1eb57c074 |
rev | line source |
---|---|
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # #################################################################### |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # Copyright (C) 2005-2009 by the FIFE team |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # http://www.fifengine.de |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # This file is part of FIFE. |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # Lesser General Public License for more details. |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # License along with this library; if not, write to the |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # Free Software Foundation, Inc., |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # #################################################################### |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 from fife import fife |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 from scripts.common.helpers import normalize |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
26 from scripts.common.helpers import Rect |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 class SpaceObject(object): |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
29 def __init__(self, scene, name, findInstance=True): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
30 self._scene = scene |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
31 self._model = self._scene.model |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
32 self._layer = self._scene.objectlayer |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 self._name = name |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 self._xscale = self._layer.getCellGrid().getXScale() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 self._yscale = self._layer.getCellGrid().getYScale() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 self._velocity = fife.DoublePoint(0,0) |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
37 self._maxvelocity = 1.25 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
38 self._boundingBox = Rect(0,0,0,0) |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
39 self._running = False |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
40 self._changedPosition = False |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
41 self._scenenodeid = -1 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
42 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 if findInstance: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 self._instance = self._layer.getInstance(self._name) |
473
b78020d31186
Small update to ensure python doesn't try to delete objects that FIFE owns.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
45 self._instance.thisown = 0 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 else: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 self._instnace = None |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 def start(self): |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
50 if self._instance: |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
51 self._running = True |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
53 def update(self): |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
54 if self._running: |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
55 shiploc = self.location |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
56 exactloc = shiploc.getExactLayerCoordinates() |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
58 exactloc.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
59 exactloc.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
60 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
61 self._boundingBox.x = (exactloc.x * self._xscale - self._boundingBox.w/2) |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
62 self._boundingBox.y = (exactloc.y * self._yscale - self._boundingBox.h/2) |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
64 shiploc.setExactLayerCoordinates(exactloc) |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
65 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
66 if shiploc == self.location: |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
67 self._changePosition = False |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
68 else: |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
69 self._changedPosition = True |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
70 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
71 self.location = shiploc |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 def stop(self): |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
74 self._running = False |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 def destroy(self): |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
77 self._running = False |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
79 def applyThrust(self, vector): |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
80 self._velocity.x += (vector.x * (self._scene.timedelta/1000.0))/self._xscale |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
81 self._velocity.y += (vector.y * (self._scene.timedelta/1000.0))/self._yscale |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 if self._velocity.length() > self._maxvelocity: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 norm = normalize(self._velocity) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 self._velocity.x = norm.x * self._maxvelocity |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 self._velocity.y = norm.y * self._maxvelocity |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
89 def applyBrake(self, brakingForce): |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 |
451
f463ab431cc0
Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
450
diff
changeset
|
91 if self._velocity.length() <= .01: |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 self._velocity.x = 0 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 self._velocity.y = 0 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 return |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 #first normalize to get a unit vector of the direction we are traveling |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 norm = normalize(self._velocity) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 if norm.length() == 0: |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 self._velocity.x = 0 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 self._velocity.y = 0 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 return |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 #negate to get opposite direction |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 norm.x = norm.x * -1 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 norm.y = norm.y * -1 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 #apply braking deceleration |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 norm.x *= brakingForce |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 norm.y *= brakingForce |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
111 self._velocity.x += (norm.x * (self._scene.timedelta/1000.0))/self._xscale |
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
112 self._velocity.y += (norm.y * (self._scene.timedelta/1000.0))/self._yscale |
463
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
460
diff
changeset
|
113 |
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
460
diff
changeset
|
114 def removeFromScene(self): |
ac0f62a07a3e
Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
460
diff
changeset
|
115 self._scene.removeObjectFromScene(self) |
473
b78020d31186
Small update to ensure python doesn't try to delete objects that FIFE owns.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
116 if self._instance: |
b78020d31186
Small update to ensure python doesn't try to delete objects that FIFE owns.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
117 self._layer.deleteInstance(self._instance) |
b78020d31186
Small update to ensure python doesn't try to delete objects that FIFE owns.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
463
diff
changeset
|
118 self._instance = None |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
119 |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
120 def _isRunning(self): |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
121 return self._running |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 def _getMaxVelocity(self): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 return self._maxvelocity |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 def _setMaxVelocity(self, maxvel): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 self._maxvelocity = maxvel/sqrt(self._xscale * self._yscale) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 def _getLocation(self): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 return self._instance.getLocation() |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 def _setLocation(self, loc): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 self._instance.setLocation(loc) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 def _getInstance(self): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 return self._instance |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 def _setInstance(self, instance): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 self._instance = instance |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
141 def _getVelocity(self): |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 return self._velocity |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
143 |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
144 def _setVelocity(self, velocity): |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
145 self._velocity = velocity |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
147 def _getBoundingBox(self): |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
148 return self._boundingBox |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
149 |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
150 def _getW(self): |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
151 return self._boundingBox.w |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
152 |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
153 def _getH(self): |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
154 return self._boundingBox.h |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
155 |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
156 def _setW(self, w): |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
157 self._boundingBox.w = w |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
158 |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
159 def _setH(self, h): |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
160 self._boundingBox.h = h |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
161 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
162 def _changedPosition(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
163 return self._changedPosition |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
164 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
165 def _getNodeId(self): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
166 return self._scenenodeid |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
167 |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
168 def _setNodeId(self, id): |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
169 self._scenenodeid = id |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
170 |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
171 width = property(_getW, _setW) |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
172 height = property(_getH, _setH) |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
173 boundingbox = property(_getBoundingBox) |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 location = property(_getLocation,_setLocation) |
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 instance = property(_getInstance, _setInstance) |
449
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
176 velocity = property(_getVelocity, _setVelocity) |
1cf56403347a
Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
448
diff
changeset
|
177 maxvelocity = property(_getMaxVelocity, _setMaxVelocity) |
453
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
178 running = property(_isRunning) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
179 changedposition = property(_changedPosition) |
cf53848fb187
Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
451
diff
changeset
|
180 scenenodeid = property(_getNodeId, _setNodeId) |