annotate demos/shooter/scripts/common/baseobject.py @ 523:d01eb65b2726

Enabling the FloatingTextRenderer for the RPG demo. The NPC now complains at you if he doesn't have a quest to give you.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 27 May 2010 18:29:20 +0000
parents e241d7553496
children c0c3f64bfc2d
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 # ####################################################################
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
4 # Copyright (C) 2005-2010 by the FIFE team
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
5 # http://www.fifengine.net
448
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
492
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 491
diff changeset
25 from fife.extensions.fife_math import normalize
16ceb3228324 Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 491
diff changeset
26 from fife.extensions.fife_math 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
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
34 SHTR_POWERUP = 5
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
35
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
36
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 class SpaceObject(object):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
38 """
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
39 Space Object is the base class for all game objects.
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
40 """
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
41 def __init__(self, scene, name, findInstance=True):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
42 """
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
43 @param scene: A reference to the Scene
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
44 @type scene: L{Scene}
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
45 @param name: The name of the space object
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
46 @type name: C{string}
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
47 @param findInstance: True if the instance you are looking for is already loaded
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
48 False if you want to load the instance yourself
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
49 @type findInstance: C{boolean}
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
50
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
51 """
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
52 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
53 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
54 self._layer = self._scene.objectlayer
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 self._name = name
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self._xscale = self._layer.getCellGrid().getXScale()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 self._yscale = self._layer.getCellGrid().getYScale()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 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
59 self._maxvelocity = 1.25
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
60 self._boundingBox = Rect(0,0,0,0)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
61 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
62 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
63 self._scenenodeid = -1
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
64 self._type = SHTR_DEFAULT
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
65
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 if findInstance:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 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
68 self._instance.thisown = 0
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 else:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 self._instnace = None
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 def start(self):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
73 """
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
74 You must execute this function for the object to be updated
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
75 """
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
76 if self._instance:
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
77 self._running = True
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 update(self):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
80 """
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
81 If the object is running this updates the FIFE instance location based on
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
82 the objects current velocity and time since last frame
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
83 """
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
84 if self._running:
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
85 shiploc = self.location
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
86 exactloc = shiploc.getExactLayerCoordinates()
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 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
89 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
90
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
91 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
92 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
93
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
94 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
95
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 451
diff changeset
96 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
97 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
98 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
99 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
100
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
101 self.location = shiploc
448
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 def stop(self):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
104 """
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
105 Stops the object from being updated.
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
106 """
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
107 self._running = False
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 def destroy(self):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
110 """
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
111 You are meant to override this function to specify what happens when the object
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
112 gets destroyed
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
113 """
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
114 self._running = False
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
116 def applyThrust(self, vector):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
117 """
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
118 Applies a thrust vector to the object.
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
119
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
120 @note: Objects do not have mass and therefore no inertia.
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
121
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
122 @param vector A vector specifying the direction and intensity of thrust.
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
123 @type vector: L{fife.DoublePoint}
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
124 """
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
125 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
126 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
127
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128 if self._velocity.length() > self._maxvelocity:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 norm = normalize(self._velocity)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 self._velocity.x = norm.x * self._maxvelocity
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 self._velocity.y = norm.y * self._maxvelocity
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
134 def applyBrake(self, brakingForce):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
135 """
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
136 Applies a braking thrust in the opposite direction of the current velocity
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
137
494
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
138 @param brakingForce: a floating point value specifying how fast the object should decelerate
e241d7553496 Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 492
diff changeset
139 @type brakingForce: C{float}
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
140 """
451
f463ab431cc0 Movement shouldn't be dependent on framerate anymore.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 450
diff changeset
141 if self._velocity.length() <= .01:
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 self._velocity.x = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 self._velocity.y = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 return
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 #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
147 norm = normalize(self._velocity)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 if norm.length() == 0:
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 self._velocity.x = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 self._velocity.y = 0
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 return
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 #negate to get opposite direction
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 norm.x = norm.x * -1
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 norm.y = norm.y * -1
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 #apply braking deceleration
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 norm.x *= brakingForce
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 norm.y *= brakingForce
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
161 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
162 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
163
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
164 def removeFromScene(self):
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
165 """
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
166 Queues this object to be removed from the scene. The scene will remove the object
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
167 next time the garbage collection routines are called.
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
168 """
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
169 self._scene.queueObjectForRemoval(self)
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 def _isRunning(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
172 return self._running
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 def _getMaxVelocity(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 return self._maxvelocity
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 def _setMaxVelocity(self, maxvel):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 self._maxvelocity = maxvel/sqrt(self._xscale * self._yscale)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 def _getLocation(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181 return self._instance.getLocation()
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 def _setLocation(self, loc):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 self._instance.setLocation(loc)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 def _getInstance(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187 return self._instance
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
189 def _setInstance(self, instance):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
190 self._instance = instance
479
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
191 if self._instance:
ab28994820dd Added some powerups including a spread weapon and an extra life.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 477
diff changeset
192 self._instance.thisown = 0
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194 def _getVelocity(self):
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195 return self._velocity
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
196
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
197 def _setVelocity(self, velocity):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
198 self._velocity = velocity
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
200 def _getBoundingBox(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
201 return self._boundingBox
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
202
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
203 def _getW(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
204 return self._boundingBox.w
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
205
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
206 def _getH(self):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
207 return self._boundingBox.h
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
208
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
209 def _setW(self, w):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
210 self._boundingBox.w = w
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
211
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
212 def _setH(self, h):
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
213 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
214
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 451
diff changeset
215 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
216 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
217
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 451
diff changeset
218 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
219 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
220
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 451
diff changeset
221 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
222 self._scenenodeid = id
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
223
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
224 def _getType(self):
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
225 return self._type
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
226
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
227 def _setType(self, objtype):
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
228 self._type = objtype
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
229
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 476
diff changeset
230 type = property(_getType, _setType)
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
231 width = property(_getW, _setW)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
232 height = property(_getH, _setH)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
233 boundingbox = property(_getBoundingBox)
448
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
234 location = property(_getLocation,_setLocation)
5e2ec84902a7 Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
235 instance = property(_getInstance, _setInstance)
449
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
236 velocity = property(_getVelocity, _setVelocity)
1cf56403347a Added object bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 448
diff changeset
237 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
238 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
239 changedposition = property(_changedPosition)
491
c4168eb47a44 Adding some comments to the shooter demo. Updated the copyright date and FIFE URL as well.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 479
diff changeset
240 scenenodeid = property(_getNodeId, _setNodeId)