Mercurial > fife-parpg
changeset 452:f07d779362da
Added different enemy types which behave differently.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 03 Apr 2010 19:19:33 +0000 |
parents | f463ab431cc0 |
children | cf53848fb187 |
files | demos/shooter/scripts/scene.py demos/shooter/scripts/ships/enemies.py |
diffstat | 2 files changed, 90 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/shooter/scripts/scene.py Thu Apr 01 21:14:23 2010 +0000 +++ b/demos/shooter/scripts/scene.py Sat Apr 03 19:19:33 2010 +0000 @@ -24,6 +24,7 @@ from fife import fife from scripts.ships.shipbase import Ship from scripts.ships.player import Player +from scripts.ships.enemies import * from scripts.common.helpers import Rect @@ -73,11 +74,14 @@ objectName = instance.getObject().getId() print objectName - enemy = Ship(self._model, 'enemy', self._layer, False) + if objectName == "saucer1": + enemy = Saucer1(self._model, 'enemy', self._layer, False) + elif objectName == "saucer2": + enemy = Saucer2(self._model, 'enemy', self._layer, False) + else: + enemy = Ship(self._model, 'enemy', self._layer, False) + enemy.instance = instance - enemy.width = 0.075 - enemy.height = 0.075 - enemy.velocity.x = -0.13 enemy.start() loc = instance.getLocation().getExactLayerCoordinates()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/scripts/ships/enemies.py Sat Apr 03 19:19:33 2010 +0000 @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- + +# #################################################################### +# Copyright (C) 2005-2009 by the FIFE team +# http://www.fifengine.de +# This file is part of FIFE. +# +# FIFE is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# #################################################################### + +from fife import fife +from scripts.ships.shipbase import Ship +from scripts.common.helpers import Rect +from scripts.weapons import Weapon + + +class Saucer1(Ship): + def __init__(self, model, name, layer, findInstance=True): + super(Saucer1, self).__init__(model, name, layer, findInstance) + self._dir = 0 + self._time = 500 + self.width = 0.075 + self.height = 0.075 + self.velocity.x = -0.5 + + def update(self, timedelta): + if self._dir == 1: + self.applyThrust(fife.DoublePoint(0,-0.5), timedelta) + elif self._dir == 0: + self.applyThrust(fife.DoublePoint(0,0.5), timedelta) + + if self._time >= 1000: + if self._dir == 1: + self._dir = 0 + elif self._dir == 0: + self._dir = 1 + + self._time = 0 + + self._time += timedelta + + super(Saucer1, self).update(timedelta) + +class Saucer2(Ship): + def __init__(self, model, name, layer, findInstance=True): + super(Saucer2, self).__init__(model, name, layer, findInstance) + self._dir = 0 + self._time = 1000 + self.width = 0.2 + self.height = 0.2 + self.velocity.x = -0.1 + + def update(self, timedelta): + if self._dir == 1: + self.applyThrust(fife.DoublePoint(0,-0.25), timedelta) + elif self._dir == 0: + self.applyThrust(fife.DoublePoint(0,0.25), timedelta) + + if self._time >= 2000: + if self._dir == 1: + self._dir = 0 + elif self._dir == 0: + self._dir = 1 + + self._time = 0 + + self._time += timedelta + + super(Saucer2, self).update(timedelta) \ No newline at end of file