Mercurial > fife-parpg
diff 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 |
line wrap: on
line diff
--- a/demos/shooter/scripts/ships/shipbase.py Thu Apr 08 21:26:46 2010 +0000 +++ b/demos/shooter/scripts/ships/shipbase.py Fri Apr 09 17:35:52 2010 +0000 @@ -33,6 +33,13 @@ super(Ship, self).__init__(scene, name, findInstance) self._weapon = None + self._flashrate = 0 + self._flashnumber = 0 + self._flashing = False + self._flashtime = 0 + + #1 = on, 0 = invisible (off) + self._flashstate = 1 def _setWeapon(self, weapon): self._weapon = weapon @@ -45,6 +52,36 @@ return self._weapon.fire(direction) return None + + def flash(self, rate, number): + """ + Flash rate is measured in flashes per second. A single flash + would be an off and on cycle. + """ + self._flashing = True + self._flashrate = rate * 2 + self._flashnumber = number * 2 + + + def update(self): + if self._flashing: + if self._flashnumber <= 0: + self._flashing = False + self._instance.get2dGfxVisual().setVisible(True) + else: + self._flashtime += self._scene.timedelta + if self._flashtime >= 1000/self._flashrate: + if self._flashstate == 1: + self._flashstate = 0 + self._instance.get2dGfxVisual().setVisible(False) + else: + self._flashstate = 1 + self._instance.get2dGfxVisual().setVisible(True) + + self._flashtime = 0 + self._flashnumber -= 1 + + super(Ship, self).update() weapon = property(_getWeapon, _setWeapon) \ No newline at end of file