Mercurial > fife-parpg
comparison demos/shooter/scripts/ships/shipbase.py @ 459:302a69c5141d
Player death is now handled a bit nicer.
Added invulnerability.
Added 3 more enemy types.
Fixed a bug in the collision detection routine that caused some objects not to be updated when a collision is detected.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 09 Apr 2010 17:35:52 +0000 |
parents | bd7e8f708adf |
children | 5e1d6e40d19d |
comparison
equal
deleted
inserted
replaced
458:e77ebf128a74 | 459:302a69c5141d |
---|---|
31 class Ship(SpaceObject): | 31 class Ship(SpaceObject): |
32 def __init__(self, scene, name, findInstance=True): | 32 def __init__(self, scene, name, findInstance=True): |
33 super(Ship, self).__init__(scene, name, findInstance) | 33 super(Ship, self).__init__(scene, name, findInstance) |
34 | 34 |
35 self._weapon = None | 35 self._weapon = None |
36 self._flashrate = 0 | |
37 self._flashnumber = 0 | |
38 self._flashing = False | |
39 self._flashtime = 0 | |
40 | |
41 #1 = on, 0 = invisible (off) | |
42 self._flashstate = 1 | |
36 | 43 |
37 def _setWeapon(self, weapon): | 44 def _setWeapon(self, weapon): |
38 self._weapon = weapon | 45 self._weapon = weapon |
39 | 46 |
40 def _getWeapon(self): | 47 def _getWeapon(self): |
43 def fire(self, direction): | 50 def fire(self, direction): |
44 if self._weapon: | 51 if self._weapon: |
45 return self._weapon.fire(direction) | 52 return self._weapon.fire(direction) |
46 | 53 |
47 return None | 54 return None |
55 | |
56 def flash(self, rate, number): | |
57 """ | |
58 Flash rate is measured in flashes per second. A single flash | |
59 would be an off and on cycle. | |
60 """ | |
61 self._flashing = True | |
62 self._flashrate = rate * 2 | |
63 self._flashnumber = number * 2 | |
64 | |
65 | |
66 def update(self): | |
67 if self._flashing: | |
68 if self._flashnumber <= 0: | |
69 self._flashing = False | |
70 self._instance.get2dGfxVisual().setVisible(True) | |
71 else: | |
72 self._flashtime += self._scene.timedelta | |
73 if self._flashtime >= 1000/self._flashrate: | |
74 if self._flashstate == 1: | |
75 self._flashstate = 0 | |
76 self._instance.get2dGfxVisual().setVisible(False) | |
77 else: | |
78 self._flashstate = 1 | |
79 self._instance.get2dGfxVisual().setVisible(True) | |
80 | |
81 self._flashtime = 0 | |
82 self._flashnumber -= 1 | |
83 | |
84 super(Ship, self).update() | |
48 | 85 |
49 weapon = property(_getWeapon, _setWeapon) | 86 weapon = property(_getWeapon, _setWeapon) |
50 | 87 |