Mercurial > fife-parpg
diff demos/shooter/scripts/ships/shipbase.py @ 462:c4f745a566d6
Added player ship animations including flash and explode.
Removed the old flashing routine.
The player now gets moved to the left side of the screen after dying and is invulnerable for a short period of time.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 12 Apr 2010 19:01:41 +0000 |
parents | f87f686b5b59 |
children | ac0f62a07a3e |
line wrap: on
line diff
--- a/demos/shooter/scripts/ships/shipbase.py Mon Apr 12 12:21:27 2010 +0000 +++ b/demos/shooter/scripts/ships/shipbase.py Mon Apr 12 19:01:41 2010 +0000 @@ -28,18 +28,24 @@ from scripts.weapons import Weapon +class ShipActionListener(fife.InstanceActionListener): + def __init__(self, ship): + fife.InstanceActionListener.__init__(self) + + self._ship = ship + self._ship.instance.addActionListener(self) + + def onInstanceActionFinished(self, instance, action): + pass + class Ship(SpaceObject): def __init__(self, scene, name, findInstance=True): 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 self._isplayer = False @@ -48,46 +54,22 @@ def _getWeapon(self): return self._weapon - + + def flash(self, number): + self._instance.act('flash', self._instance.getFacingLocation()) + self._flashnumber = number + self._flashing = True + def fire(self, direction): if self._weapon: 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 destroy(self): self._scene.removeObjectFromScene(self) super(Ship, self).destroy() - 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() - def _isPlayer(self): return self._isplayer