# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1271874013 0 # Node ID afde89c1d50b6867d06be7bd69dae96bdf3b7a53 # Parent 10aff123c62c45c4e30aad62ccca99a56e2000ed Switched to a damage system. Collisions with objects now cause 1 damage to the player. When the boss switches weapons it now waits for the weapons firerate value in time to pass before it fires its first burst with the new weapon. Fixed a little problem with the high score dialog as it operates in modal mode. It now waits for the entire frame to be complete before displaying the dialog box. diff -r 10aff123c62c -r afde89c1d50b demos/shooter/scripts/common/helpers.py --- a/demos/shooter/scripts/common/helpers.py Wed Apr 21 16:49:59 2010 +0000 +++ b/demos/shooter/scripts/common/helpers.py Wed Apr 21 18:20:13 2010 +0000 @@ -107,8 +107,14 @@ theta = (angle * math.pi)/180 - newp.x = math.cos(theta) * (point.x - origin.x) - math.sin(theta) * (point.y - origin.y) - newp.y = math.sin(theta) * (point.x - origin.x) + math.cos(theta) * (point.y - origin.y) + costheta = math.cos(theta) + sintheta = math.sin(theta) + + x = point.x - origin.x + y = point.y - origin.y + + newp.x = costheta * x - sintheta * y + newp.y = sintheta * x + costheta * y return newp \ No newline at end of file diff -r 10aff123c62c -r afde89c1d50b demos/shooter/scripts/scene.py --- a/demos/shooter/scripts/scene.py Wed Apr 21 16:49:59 2010 +0000 +++ b/demos/shooter/scripts/scene.py Wed Apr 21 18:20:13 2010 +0000 @@ -162,11 +162,12 @@ self._timemod += time - self._pausedtime self._paused = False - def playerHit(self): - self._player.applyHit(1) - if self._player.lives <= -1: - self._gameover = True - self._world.gameOver() + def playerHit(self, damage): + self._player.applyHit(damage) + + def gameOver(self): + self._gameover = True + self._world.gameOver() def endLevel(self): self._world.endLevel() @@ -276,9 +277,9 @@ #player touched an enemy. Destroy player and #re-initialize scene if not self._player.invulnerable: - self.playerHit() - if obj != self._boss: - obj.destroy() + #collision damage of 1 + self.playerHit(1) + obj.applyHit(1) # self._world.renderBoundingBox(obj) @@ -302,8 +303,8 @@ elif o == self._player: #player got hit by a projectile if not self._player.invulnerable: + self.playerHit(p.damage) p.destroy() - self.playerHit() # self._world.renderBoundingBox(p) diff -r 10aff123c62c -r afde89c1d50b demos/shooter/scripts/ships/enemies.py --- a/demos/shooter/scripts/ships/enemies.py Wed Apr 21 16:49:59 2010 +0000 +++ b/demos/shooter/scripts/ships/enemies.py Wed Apr 21 18:20:13 2010 +0000 @@ -226,7 +226,9 @@ if self.hitpoints == 20: self.weapon = FireBallBurst(self._scene, self, 2000, 100, 10) + self.weapon.lastfired = self._scene.time elif self.hitpoints == 10: self.weapon = FireBallSpread(self._scene, self, 2000) + self.weapon.lastfired = self._scene.time \ No newline at end of file diff -r 10aff123c62c -r afde89c1d50b demos/shooter/scripts/ships/player.py --- a/demos/shooter/scripts/ships/player.py Wed Apr 21 16:49:59 2010 +0000 +++ b/demos/shooter/scripts/ships/player.py Wed Apr 21 18:20:13 2010 +0000 @@ -85,6 +85,7 @@ else: self._instance.get2dGfxVisual().setVisible(False) + self._scene.gameOver() def setInvulnerable(self, milliseconds): #50 is defined in the players "flash" animation file diff -r 10aff123c62c -r afde89c1d50b demos/shooter/scripts/weapons.py --- a/demos/shooter/scripts/weapons.py Wed Apr 21 16:49:59 2010 +0000 +++ b/demos/shooter/scripts/weapons.py Wed Apr 21 18:20:13 2010 +0000 @@ -107,7 +107,14 @@ def _setProjectileVelocity(self, vel): self._projectileVelocity = vel + def _getLastFired(self): + return self._lastfired + + def _setLastFired(self, time): + self._lastfired = time + projectilevelocity = property(_getProjectileVelocity, _setProjectileVelocity) + lastfired = property(_getLastFired, _setLastFired) class Cannon(Weapon): def __init__(self, scene, ship, firerate): diff -r 10aff123c62c -r afde89c1d50b demos/shooter/scripts/world.py --- a/demos/shooter/scripts/world.py Wed Apr 21 16:49:59 2010 +0000 +++ b/demos/shooter/scripts/world.py Wed Apr 21 18:20:13 2010 +0000 @@ -205,7 +205,7 @@ self._gameover.show() self._hudwindow.hide() - self.saveScore() + self._gamecomplete = True def endLevel(self): self._paused = True @@ -315,10 +315,6 @@ Called every frame. """ - if self._gamecomplete: - self.saveScore() - self.reset() - if self._genericrenderer: self._genericrenderer.removeAll("quads") @@ -327,7 +323,7 @@ return #update the scene - if not self._paused: + if not self._paused and not self._gamecomplete: if self._scene.paused: self._scene.unpause(self._timemanager.getTime() - self._starttime) @@ -363,6 +359,9 @@ else: if not self._scene.paused: self._scene.pause(self._timemanager.getTime() - self._starttime) - + + if self._gamecomplete: + self.saveScore() + self.reset() self._pump_ctr += 1