annotate demos/shooter/scripts/ships/enemies.py @ 477:6b33d80b468b

Projectiles are now part of the scene. Cleaned up the scene update() function. Moved garbage collection to the beginning of the frame. Introduced global object types. Projectiles now only check for collisions in a limited number of scene nodes rather than the entire screen.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 22 Apr 2010 19:52:34 +0000
parents afde89c1d50b
children ab28994820dd
rev   line source
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # ####################################################################
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 # Copyright (C) 2005-2009 by the FIFE team
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # http://www.fifengine.de
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # This file is part of FIFE.
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 #
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 # FIFE is free software; you can redistribute it and/or
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 # modify it under the terms of the GNU Lesser General Public
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # License as published by the Free Software Foundation; either
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # version 2.1 of the License, or (at your option) any later version.
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 #
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 # This library is distributed in the hope that it will be useful,
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # Lesser General Public License for more details.
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 #
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 # License along with this library; if not, write to the
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # Free Software Foundation, Inc.,
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # ####################################################################
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 from fife import fife
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
25 from scripts.ships.shipbase import *
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
26 from scripts.common.baseobject import *
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 from scripts.common.helpers import Rect
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
28 from scripts.weapons import *
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
31 class EnemyActionListener(ShipActionListener):
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
32 def __init__(self, ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
33 super(EnemyActionListener, self).__init__(ship)
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
34
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
35 def onInstanceActionFinished(self, instance, action):
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
36 super(EnemyActionListener, self).onInstanceActionFinished(instance, action)
462
c4f745a566d6 Added player ship animations including flash and explode.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 460
diff changeset
37
474
10aff123c62c Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 472
diff changeset
38
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
39 class BossActionListener(ShipActionListener):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
40 def __init__(self, ship):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
41 super(BossActionListener, self).__init__(ship)
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
42
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
43 def onInstanceActionFinished(self, instance, action):
474
10aff123c62c Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 472
diff changeset
44 super(BossActionListener, self).onInstanceActionFinished(instance, action)
10aff123c62c Some minor code cleanups.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 472
diff changeset
45
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
46 if action.getId() == 'explode':
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
47 self._ship.endLevel()
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
48
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
49
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 class Saucer1(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
51 def __init__(self, scene, name, instance, findInstance=True):
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
52 super(Saucer1, self).__init__(scene, name, findInstance)
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
53 self._instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
54 self._type = SHTR_ENEMYSHIP
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self._time = 500
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
57 self.width = 0.2
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 self.height = 0.075
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 self.velocity.x = -0.5
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
60
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
61 self.weapon = Cannon(self._scene, self, 1000)
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
62 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
63
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
64 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
65
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
66 self.hitpoints = 1
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
67 self.scorevalue = 50
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
69 def update(self):
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 if self._dir == 1:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
71 self.applyThrust(fife.DoublePoint(0,-0.5))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 elif self._dir == 0:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
73 self.applyThrust(fife.DoublePoint(0,0.5))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 if self._time >= 1000:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 if self._dir == 1:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 elif self._dir == 0:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 self._dir = 1
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 self._time = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
83 self._time += self._scene.timedelta
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
85 super(Saucer1, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
86
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
87 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
88
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90 class Saucer2(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
91 def __init__(self, scene, name, instance, findInstance=True):
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
92 super(Saucer2, self).__init__(scene, name, findInstance)
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
93 self._instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
94 self._type = SHTR_ENEMYSHIP
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 self._time = 1000
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 self.width = 0.2
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 self.height = 0.2
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 self.velocity.x = -0.1
453
cf53848fb187 Scene now gets updated when an object moves from one node to another.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 452
diff changeset
100
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
101 self.weapon = Cannon(self._scene, self, 2000)
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
102 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
103
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
104 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
105
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
106 self.hitpoints = 2
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
107 self.scorevalue = 100
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
108
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
109 def applyHit(self, hp):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
110 self.flash(1)
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
111 super(Saucer2, self).applyHit(hp)
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
112
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
113 def update(self):
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 if self._dir == 1:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
115 self.applyThrust(fife.DoublePoint(0,-0.25))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 elif self._dir == 0:
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
117 self.applyThrust(fife.DoublePoint(0,0.25))
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 if self._time >= 2000:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 if self._dir == 1:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 self._dir = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122 elif self._dir == 0:
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 self._dir = 1
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 self._time = 0
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126
454
bd7e8f708adf Time is now managed by the Scene object.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 453
diff changeset
127 self._time += self._scene.timedelta
452
f07d779362da Added different enemy types which behave differently.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
129 super(Saucer2, self).update()
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
130
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
131 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
132
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
133 class DiagSaucer(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
134 def __init__(self, scene, name, direction, instance, findInstance=True):
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
135 super(DiagSaucer, self).__init__(scene, name, findInstance)
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
136 self._instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
137 self._type = SHTR_ENEMYSHIP
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
138 self.width = 0.2
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
139 self.height = 0.075
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
140
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
141 if direction == 0:
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
142 self._ythrust = 0.25
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
143 else:
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
144 self._ythrust = -0.25
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
145
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
146 self.weapon = Cannon(self._scene, self, 2000)
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
147 self.weapon.projectilevelocity = 0.4
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
148
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
149 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
150
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
151 self.hitpoints = 1
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
152 self.scorevalue = 50
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
153
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
154 def update(self):
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
155 self.applyThrust(fife.DoublePoint(-0.25,self._ythrust))
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
156 super(DiagSaucer, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
157
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
158 self.fire(fife.DoublePoint(-1,0))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
159
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
160
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
161 class Streaker(Ship):
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
162 def __init__(self, scene, name, instance, findInstance=True):
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
163 super(Streaker, self).__init__(scene, name, findInstance)
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
164 self._instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
165 self._type = SHTR_ENEMYSHIP
460
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
166 self.width = 0.2
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
167 self.height = 0.2
5e1d6e40d19d Fixed bounding boxes.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 459
diff changeset
168
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
169 self._maxvelocity = 2.0
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
170
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
171 self.weapon = FireBall(self._scene, self, 2000)
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
172 self.weapon.projectilevelocity = 0.25
463
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
173
ac0f62a07a3e Added enemy explosions and other animations.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 462
diff changeset
174 self._actionlistener = EnemyActionListener(self)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
175
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
176 self.hitpoints = 2
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
177 self.scorevalue = 150
471
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
178
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
179 def applyHit(self, hp):
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
180 self.flash(1)
7a79dc2a0592 Adding the credits window (still needs to be written)
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 470
diff changeset
181 super(Streaker, self).applyHit(hp)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
182
459
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
183 def update(self):
302a69c5141d Player death is now handled a bit nicer.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 454
diff changeset
184 self.applyThrust(fife.DoublePoint(-0.40,0))
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
185 super(Streaker, self).update()
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
186
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
187 playerloc = self._scene.player.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
188 enemyloc = self.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
189
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
190 playerloc.x -= enemyloc.x
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
191 playerloc.y -= enemyloc.y
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
192
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
193 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
194
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
195
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
196 class Boss(Ship):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
197 def __init__(self, scene, name, instance, findInstance=True):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
198 super(Boss, self).__init__(scene, name, findInstance)
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
199 self._instance = instance
477
6b33d80b468b Projectiles are now part of the scene.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 475
diff changeset
200 self._type = SHTR_LASTBOSS
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
201 self.width = 0.85
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
202 self.height = 0.25
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
203
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
204 self._maxvelocity = 2.0
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
205
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
206 self.weapon = FireBall(self._scene, self, 1000)
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
207 self.weapon.projectilevelocity = 0.5
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
208
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
209 self._actionlistener = BossActionListener(self)
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
210
472
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
211 self.hitpoints = 30
467
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
212 self.scorevalue = 1000
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
213
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
214 def endLevel(self):
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
215 self._scene.endLevel()
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
216
4d0aa75a82f1 Added damage so some enemies take more than one hit to destroy.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 463
diff changeset
217 def update(self):
470
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
218 super(Boss, self).update()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
219
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
220 playerloc = self._scene.player.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
221 bossloc = self.location.getExactLayerCoordinates()
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
222
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
223 playerloc.x -= bossloc.x
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
224 playerloc.y -= bossloc.y
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
225
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
226 self.fire(fife.DoublePoint(playerloc.x,playerloc.y))
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
227
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
228
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
229 def applyHit(self, hp):
3b04e921c93d Added the fireball projectile.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 467
diff changeset
230 self.flash(2)
472
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
231 super(Boss, self).applyHit(hp)
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
232
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
233 if self.hitpoints == 20:
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
234 self.weapon = FireBallBurst(self._scene, self, 2000, 100, 10)
475
afde89c1d50b Switched to a damage system. Collisions with objects now cause 1 damage to the player.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 474
diff changeset
235 self.weapon.lastfired = self._scene.time
472
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
236
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
237 elif self.hitpoints == 10:
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
238 self.weapon = FireBallSpread(self._scene, self, 2000)
475
afde89c1d50b Switched to a damage system. Collisions with objects now cause 1 damage to the player.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 474
diff changeset
239 self.weapon.lastfired = self._scene.time
472
3164715a0621 Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 471
diff changeset
240