comparison demos/shooter/scripts/powerups.py @ 479:ab28994820dd

Added some powerups including a spread weapon and an extra life. Fixed the problem where the player could fly off the screen.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 23 Apr 2010 17:17:02 +0000
parents
children 82d44c471959
comparison
equal deleted inserted replaced
478:41f7754f2a4b 479:ab28994820dd
1 # -*- coding: utf-8 -*-
2
3 # ####################################################################
4 # Copyright (C) 2005-2009 by the FIFE team
5 # http://www.fifengine.de
6 # This file is part of FIFE.
7 #
8 # FIFE is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # ####################################################################
23
24 from fife import fife
25 from scripts.ships.shipbase import SpaceObject
26 from scripts.weapons import *
27
28 class PowerUp(SpaceObject):
29 def __init__(self, scene, powerupName, instance, findInstance=True):
30 super(PowerUp, self).__init__(scene, powerupName, findInstance)
31
32 self.instance = instance
33 self._type = SHTR_POWERUP
34
35 self.width = 0.025
36 self.height = 0.025
37
38 def applyPowerUp(self, ship):
39 self.destroy()
40 self._scene.queueObjectForRemoval(self)
41
42 class CannonSpread5PU(PowerUp):
43 def __init__(self, scene, powerupName, instance, findInstance=True):
44 super(CannonSpread5PU, self).__init__(scene, powerupName, instance, findInstance)
45
46 self._dir = 0
47 self._time = 1500
48 self._velocity.x = -0.25
49 self._velocity.y = 0
50
51 def applyPowerUp(self, ship):
52 ship.weapon = CannonSpread5(self._scene, ship, 300)
53 self.destroy()
54 self._scene.queueObjectForRemoval(self)
55
56 def update(self):
57 if self._dir == 1:
58 self._velocity.y = -0.25
59 elif self._dir == 0:
60 self._velocity.y = 0.25
61
62 if self._time >= 3000:
63 if self._dir == 1:
64 self._dir = 0
65 elif self._dir == 0:
66 self._dir = 1
67
68 self._time = 0
69
70 self._time += self._scene.timedelta
71
72 super(CannonSpread5PU, self).update()
73
74 class ExtraLifePU(PowerUp):
75 def __init__(self, scene, powerupName, instance, findInstance=True):
76 super(ExtraLifePU, self).__init__(scene, powerupName, instance, findInstance)
77
78 def applyPowerUp(self, ship):
79 ship.lives += 1
80 self.destroy()
81 self._scene.queueObjectForRemoval(self)
82