Mercurial > fife-parpg
changeset 463:ac0f62a07a3e
Added enemy explosions and other animations.
Remove the enemies from the scene after the explosion animation is complete.
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer1/explode/animation.xml Mon Apr 12 20:41:24 2010 +0000 @@ -0,0 +1,9 @@ +<animation delay="100" namespace="http://www.fifengine.de/xml/tutorial" id="saucer1:explode" x_offset="0" y_offset="0"> + <frame source="saucer1_0.png" /> + <frame source="saucer1_1.png" /> + <frame source="saucer1_2.png" /> + <frame source="saucer1_3.png" /> + <frame source="saucer1_4.png" /> + <frame source="saucer1_5.png" /> +</animation> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer1/flash/animation.xml Mon Apr 12 20:41:24 2010 +0000 @@ -0,0 +1,5 @@ +<animation delay="50" namespace="http://www.fifengine.de/xml/tutorial" id="saucer1:flash" x_offset="0" y_offset="0"> + <frame source="saucer1_0.png" /> + <frame source="saucer1_1.png" /> +</animation> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer1/fly/animation.xml Mon Apr 12 20:41:24 2010 +0000 @@ -0,0 +1,3 @@ +<animation delay="2000" namespace="http://www.fifengine.de/xml/tutorial" id="saucer1:fly" x_offset="0" y_offset="0"> + <frame source="saucer1.png" /> +</animation>
--- a/demos/shooter/objects/ships/saucer1/object.xml Mon Apr 12 19:01:41 2010 +0000 +++ b/demos/shooter/objects/ships/saucer1/object.xml Mon Apr 12 20:41:24 2010 +0000 @@ -1,4 +1,12 @@ <?fife type="object"?> -<object id="saucer1" namespace="http://www.fifengine.de/xml/tutorial" blocking="0" static="1"> - <image source="saucer1.png" direction="0" /> +<object id="saucer1" namespace="http://www.fifengine.de/xml/tutorial" blocking="0" static="0"> + <action id="fly"> + <animation source="fly/animation.xml" direction="0" /> + </action> + <action id="explode"> + <animation source="explode/animation.xml" direction="0" /> + </action> + <action id="flash"> + <animation source="flash/animation.xml" direction="0" /> + </action> </object>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer2/explode/animation.xml Mon Apr 12 20:41:24 2010 +0000 @@ -0,0 +1,9 @@ +<animation delay="100" namespace="http://www.fifengine.de/xml/tutorial" id="saucer2:explode" x_offset="0" y_offset="0"> + <frame source="saucer2_0.png" /> + <frame source="saucer2_1.png" /> + <frame source="saucer2_2.png" /> + <frame source="saucer2_3.png" /> + <frame source="saucer2_4.png" /> + <frame source="saucer2_5.png" /> +</animation> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer2/flash/animation.xml Mon Apr 12 20:41:24 2010 +0000 @@ -0,0 +1,5 @@ +<animation delay="50" namespace="http://www.fifengine.de/xml/tutorial" id="saucer2:flash" x_offset="0" y_offset="0"> + <frame source="saucer2_0.png" /> + <frame source="saucer2_1.png" /> +</animation> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer2/fly/animation.xml Mon Apr 12 20:41:24 2010 +0000 @@ -0,0 +1,3 @@ +<animation delay="2000" namespace="http://www.fifengine.de/xml/tutorial" id="saucer2:fly" x_offset="0" y_offset="0"> + <frame source="saucer2.png" /> +</animation>
--- a/demos/shooter/objects/ships/saucer2/object.xml Mon Apr 12 19:01:41 2010 +0000 +++ b/demos/shooter/objects/ships/saucer2/object.xml Mon Apr 12 20:41:24 2010 +0000 @@ -1,4 +1,12 @@ <?fife type="object"?> -<object id="saucer2" namespace="http://www.fifengine.de/xml/tutorial" blocking="0" static="1"> - <image source="saucer2.png" direction="0" /> +<object id="saucer2" namespace="http://www.fifengine.de/xml/tutorial" blocking="0" static="0"> + <action id="fly"> + <animation source="fly/animation.xml" direction="0" /> + </action> + <action id="explode"> + <animation source="explode/animation.xml" direction="0" /> + </action> + <action id="flash"> + <animation source="flash/animation.xml" direction="0" /> + </action> </object>
--- a/demos/shooter/scripts/common/baseobject.py Mon Apr 12 19:01:41 2010 +0000 +++ b/demos/shooter/scripts/common/baseobject.py Mon Apr 12 20:41:24 2010 +0000 @@ -74,7 +74,6 @@ def destroy(self): self._running = False - self._layer.deleteInstance(self._instance) def applyThrust(self, vector): self._velocity.x += (vector.x * (self._scene.timedelta/1000.0))/self._xscale @@ -110,6 +109,10 @@ self._velocity.x += (norm.x * (self._scene.timedelta/1000.0))/self._xscale self._velocity.y += (norm.y * (self._scene.timedelta/1000.0))/self._yscale + + def removeFromScene(self): + self._scene.removeObjectFromScene(self) + self._layer.deleteInstance(self._instance) def _isRunning(self): return self._running
--- a/demos/shooter/scripts/scene.py Mon Apr 12 19:01:41 2010 +0000 +++ b/demos/shooter/scripts/scene.py Mon Apr 12 20:41:24 2010 +0000 @@ -99,19 +99,18 @@ print objectName if objectName == "dodge1": - enemy = Saucer1(self, 'enemy', False) + enemy = Saucer1(self, 'enemy', instance, False) elif objectName == "dodge2": - enemy = Saucer2(self, 'enemy', False) + enemy = Saucer2(self, 'enemy', instance, False) elif objectName == "diag_top_right": - enemy = DiagSaucer(self, 'enemy', 0, False) + enemy = DiagSaucer(self, 'enemy', 0, instance, False) elif objectName == "diag_bottom_right": - enemy = DiagSaucer(self, 'enemy', 1, False) + enemy = DiagSaucer(self, 'enemy', 1, instance, False) elif objectName == "streaker": - enemy = Streaker(self, 'enemy', False) + enemy = Streaker(self, 'enemy', instance, False) else: - enemy = Ship(self, 'enemy', False) + enemy = Ship(self, 'enemy', instance, False) - enemy.instance = instance enemy.start() loc = instance.getLocation().getExactLayerCoordinates() @@ -231,16 +230,17 @@ if obj != self._player: #TODO: enemy should fire weapon in their update function - obj.fire(fife.DoublePoint(-1,0)) + if obj.running: + obj.fire(fife.DoublePoint(-1,0)) - if obj.boundingbox.intersects(self._player.boundingbox): + if obj.running and obj.boundingbox.intersects(self._player.boundingbox): #player touched an enemy. Destroy player and #re-initialize scene if not self._player.invulnerable: self.playerHit() obj.destroy() - self._world.renderBoundingBox(obj) +# self._world.renderBoundingBox(obj) @@ -252,7 +252,7 @@ for o in screenlist: #cant get hit by your own bullet if p.owner != o: - if p.boundingbox.intersects(o.boundingbox): + if o.running and p.boundingbox.intersects(o.boundingbox): if o != self._player and p.owner.isplayer: self._player.applyScore(100) p.destroy() @@ -266,7 +266,7 @@ p.destroy() self.playerHit() - self._world.renderBoundingBox(p) +# self._world.renderBoundingBox(p) #build a list of projectiles to remove (ttl expired)
--- a/demos/shooter/scripts/ships/enemies.py Mon Apr 12 19:01:41 2010 +0000 +++ b/demos/shooter/scripts/ships/enemies.py Mon Apr 12 20:41:24 2010 +0000 @@ -29,14 +29,16 @@ class EnemyActionListener(ShipActionListener): def __init__(self, ship): - super(PlayerActionListener, self).__init__(ship) + super(EnemyActionListener, self).__init__(ship) def onInstanceActionFinished(self, instance, action): - pass + if action.getId() == 'explode': + self._ship.removeFromScene() class Saucer1(Ship): - def __init__(self, scene, name, findInstance=True): + def __init__(self, scene, name, instance, findInstance=True): super(Saucer1, self).__init__(scene, name, findInstance) + self._instance = instance self._dir = 0 self._time = 500 self.width = 0.2 @@ -45,6 +47,8 @@ self.weapon = Cannon(self._scene, self, 1000) self.weapon.projectilevelocity = 0.4 + + self._actionlistener = EnemyActionListener(self) def update(self): if self._dir == 1: @@ -65,8 +69,9 @@ super(Saucer1, self).update() class Saucer2(Ship): - def __init__(self, scene, name, findInstance=True): + def __init__(self, scene, name, instance, findInstance=True): super(Saucer2, self).__init__(scene, name, findInstance) + self._instance = instance self._dir = 0 self._time = 1000 self.width = 0.2 @@ -75,6 +80,8 @@ self.weapon = Cannon(self._scene, self, 2000) self.weapon.projectilevelocity = 0.4 + + self._actionlistener = EnemyActionListener(self) def update(self): if self._dir == 1: @@ -95,8 +102,9 @@ super(Saucer2, self).update() class DiagSaucer(Ship): - def __init__(self, scene, name, direction, findInstance=True): + def __init__(self, scene, name, direction, instance, findInstance=True): super(DiagSaucer, self).__init__(scene, name, findInstance) + self._instance = instance self.width = 0.2 self.height = 0.075 @@ -107,15 +115,17 @@ self.weapon = Cannon(self._scene, self, 2000) self.weapon.projectilevelocity = 0.4 + + self._actionlistener = EnemyActionListener(self) def update(self): self.applyThrust(fife.DoublePoint(-0.25,self._ythrust)) super(DiagSaucer, self).update() class Streaker(Ship): - def __init__(self, scene, name, findInstance=True): + def __init__(self, scene, name, instance, findInstance=True): super(Streaker, self).__init__(scene, name, findInstance) - + self._instance = instance self.width = 0.2 self.height = 0.2 @@ -123,6 +133,8 @@ self.weapon = Cannon(self._scene, self, 2000) self.weapon.projectilevelocity = 1.0 + + self._actionlistener = EnemyActionListener(self) def update(self): self.applyThrust(fife.DoublePoint(-0.40,0))
--- a/demos/shooter/scripts/ships/shipbase.py Mon Apr 12 19:01:41 2010 +0000 +++ b/demos/shooter/scripts/ships/shipbase.py Mon Apr 12 20:41:24 2010 +0000 @@ -67,8 +67,9 @@ return None def destroy(self): - self._scene.removeObjectFromScene(self) - super(Ship, self).destroy() + if self._running: + self._instance.act('explode', self._instance.getFacingLocation()) + super(Ship, self).destroy() def _isPlayer(self): return self._isplayer