annotate demos/shooter/scripts/common/baseobject.py @ 477:6b33d80b468b

Projectiles are now part of the scene. Cleaned up the scene update() function. Moved garbage collection to the beginning of the frame. Introduced global object types. Projectiles now only check for collisions in a limited number of scene nodes rather than the entire screen.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 22 Apr 2010 19:52:34 +0000
parents 78a1eb57c074
children ab28994820dd
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
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
28
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
29 SHTR_DEFAULT = 0
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
30 SHTR_PLAYER = 1
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
31 SHTR_LASTBOSS = 2
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
32 SHTR_PROJECTILE = 3
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
33 SHTR_ENEMYSHIP = 4
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
34
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
35
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 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
37 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
38 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
39 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
40 self._layer = self._scene.objectlayer
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 self._name = name
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 self._xscale = self._layer.getCellGrid().getXScale()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 self._yscale = self._layer.getCellGrid().getYScale()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 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
45 self._maxvelocity = 1.25
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
46 self._boundingBox = Rect(0,0,0,0)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
47 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
48 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
49 self._scenenodeid = -1
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
50 self._type = SHTR_DEFAULT
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
51
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 if findInstance:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 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
54 self._instance.thisown = 0
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 else:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self._instnace = None
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 def start(self):
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
59 if self._instance:
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
60 self._running = True
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
62 def update(self):
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
63 if self._running:
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
64 shiploc = self.location
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
65 exactloc = shiploc.getExactLayerCoordinates()
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
67 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
68 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
69
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
70 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
71 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
72
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
73 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
74
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 451
diff changeset
75 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
76 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
77 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
78 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
79
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
80 self.location = shiploc
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 def stop(self):
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
83 self._running = False
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 def destroy(self):
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
86 self._running = False
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
88 def applyThrust(self, vector):
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
89 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
90 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
91
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 if self._velocity.length() > self._maxvelocity:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 norm = normalize(self._velocity)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 self._velocity.x = norm.x * self._maxvelocity
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 self._velocity.y = norm.y * self._maxvelocity
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
98 def applyBrake(self, brakingForce):
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99
451
f463ab431cc0 Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 450
diff changeset
100 if self._velocity.length() <= .01:
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 self._velocity.x = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 self._velocity.y = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 return
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 #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
106 norm = normalize(self._velocity)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 if norm.length() == 0:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 self._velocity.x = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 self._velocity.y = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 return
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 #negate to get opposite direction
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 norm.x = norm.x * -1
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 norm.y = norm.y * -1
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 #apply braking deceleration
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 norm.x *= brakingForce
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 norm.y *= brakingForce
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
120 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
121 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
122
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
123 def removeFromScene(self):
476
78a1eb57c074 Changed the way instances get deleted from the scene. Instances now get removed at the end of the frame as opposed to after their explosion action is complete. The old way was causing the odd segfault because the instance was being removed before FIFE was finished with it.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 473
diff changeset
124 self._scene.queueObjectForRemoval(self)
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
125
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
126 def _isRunning(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
127 return self._running
448
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 _getMaxVelocity(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 return self._maxvelocity
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 _setMaxVelocity(self, maxvel):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 self._maxvelocity = maxvel/sqrt(self._xscale * self._yscale)
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 _getLocation(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 return self._instance.getLocation()
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 _setLocation(self, loc):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 self._instance.setLocation(loc)
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 _getInstance(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 return self._instance
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 def _setInstance(self, instance):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145 self._instance = instance
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 def _getVelocity(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 return self._velocity
449
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 _setVelocity(self, velocity):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
151 self._velocity = velocity
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
153 def _getBoundingBox(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
154 return self._boundingBox
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 _getW(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
157 return self._boundingBox.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 _getH(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
160 return self._boundingBox.h
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
161
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
162 def _setW(self, w):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
163 self._boundingBox.w = w
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
164
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
165 def _setH(self, h):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
166 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
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 _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
169 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
170
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 451
diff changeset
171 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
172 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
173
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 451
diff changeset
174 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
175 self._scenenodeid = id
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
176
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
177 def _getType(self):
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
178 return self._type
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
179
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
180 def _setType(self, objtype):
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
181 self._type = objtype
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
182
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
183 type = property(_getType, _setType)
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
184 width = property(_getW, _setW)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
185 height = property(_getH, _setH)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
186 boundingbox = property(_getBoundingBox)
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187 location = property(_getLocation,_setLocation)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 instance = property(_getInstance, _setInstance)
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
189 velocity = property(_getVelocity, _setVelocity)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
190 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
191 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
192 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
193 scenenodeid = property(_getNodeId, _setNodeId)