Mercurial > fife-parpg
annotate demos/shooter/scripts/ships/shipbase.py @ 460:5e1d6e40d19d
Fixed bounding boxes.
Added bounding box renderer.
The player is now better confined to the screen.
Added more enemies to the map.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 09 Apr 2010 21:42:28 +0000 |
parents | 302a69c5141d |
children | f87f686b5b59 |
rev | line source |
---|---|
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # #################################################################### |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # Copyright (C) 2005-2009 by the FIFE team |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # http://www.fifengine.de |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # This file is part of FIFE. |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # Lesser General Public License for more details. |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # License along with this library; if not, write to the |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # Free Software Foundation, Inc., |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # #################################################################### |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
447
64676ea55472
Added the ability to set the scale of the object layer. Tweaked the player controls a little bit. A little more work needs to be done to keep the player within the bounds of the camera.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
24 from math import sqrt |
64676ea55472
Added the ability to set the scale of the object layer. Tweaked the player controls a little bit. A little more work needs to be done to keep the player within the bounds of the camera.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
25 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 from fife import fife |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
27 from scripts.common.baseobject import SpaceObject |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 from scripts.weapons import Weapon |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
447
64676ea55472
Added the ability to set the scale of the object layer. Tweaked the player controls a little bit. A little more work needs to be done to keep the player within the bounds of the camera.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
446
diff
changeset
|
30 |
448
5e2ec84902a7
Did a little re-factoring.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
447
diff
changeset
|
31 class Ship(SpaceObject): |
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
|
32 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
|
33 super(Ship, self).__init__(scene, name, findInstance) |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
34 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 self._weapon = None |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
36 self._flashrate = 0 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
37 self._flashnumber = 0 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
38 self._flashing = False |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
39 self._flashtime = 0 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
40 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
41 #1 = on, 0 = invisible (off) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
42 self._flashstate = 1 |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 def _setWeapon(self, weapon): |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 self._weapon = weapon |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
47 def _getWeapon(self): |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 return self._weapon |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
50 def fire(self, direction): |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 if self._weapon: |
454
bd7e8f708adf
Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
453
diff
changeset
|
52 return self._weapon.fire(direction) |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 return None |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
55 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
56 def flash(self, rate, number): |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
57 """ |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
58 Flash rate is measured in flashes per second. A single flash |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
59 would be an off and on cycle. |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
60 """ |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
61 self._flashing = True |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
62 self._flashrate = rate * 2 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
63 self._flashnumber = number * 2 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
64 |
460
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
65 def destroy(self): |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
66 self._scene.removeObjectFromScene(self) |
5e1d6e40d19d
Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
459
diff
changeset
|
67 super(Ship, self).destroy() |
459
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
68 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
69 def update(self): |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
70 if self._flashing: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
71 if self._flashnumber <= 0: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
72 self._flashing = False |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
73 self._instance.get2dGfxVisual().setVisible(True) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
74 else: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
75 self._flashtime += self._scene.timedelta |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
76 if self._flashtime >= 1000/self._flashrate: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
77 if self._flashstate == 1: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
78 self._flashstate = 0 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
79 self._instance.get2dGfxVisual().setVisible(False) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
80 else: |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
81 self._flashstate = 1 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
82 self._instance.get2dGfxVisual().setVisible(True) |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
83 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
84 self._flashtime = 0 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
85 self._flashnumber -= 1 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
86 |
302a69c5141d
Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
454
diff
changeset
|
87 super(Ship, self).update() |
446
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 weapon = property(_getWeapon, _setWeapon) |
2046a1f2f5f2
Adding the shooter demo. This is still a work in progress.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 |