Mercurial > fife-parpg
changeset 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 | 41f7754f2a4b |
children | 85fa5fa486a8 |
files | demos/shooter/maps/shooter_map1.xml demos/shooter/objects/powerups/cannonspread5/cannon_spread.png demos/shooter/objects/powerups/cannonspread5/object.xml demos/shooter/objects/powerups/extralife/extralife.png demos/shooter/objects/powerups/extralife/object.xml demos/shooter/scripts/common/baseobject.py demos/shooter/scripts/gui/guis.py demos/shooter/scripts/powerups.py demos/shooter/scripts/scene.py demos/shooter/scripts/ships/enemies.py demos/shooter/scripts/ships/player.py demos/shooter/scripts/weapons.py |
diffstat | 12 files changed, 213 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/shooter/maps/shooter_map1.xml Thu Apr 22 21:04:13 2010 +0000 +++ b/demos/shooter/maps/shooter_map1.xml Fri Apr 23 17:17:02 2010 +0000 @@ -7,6 +7,8 @@ <import file="../objects/ships/boss1/object.xml"></import> <import file="../objects/projectiles/bullet1/object.xml"></import> <import file="../objects/projectiles/fireball/object.xml"></import> + <import file="../objects/powerups/cannonspread5/object.xml"></import> + <import file="../objects/powerups/extralife/object.xml"></import> <layer y_scale="1.0" y_offset="0.0" pathing="cell_edges_and_diagonals" grid_type="square" id="background" rotation="0.0" x_scale="1.0" x_offset="0.0" transparency="0"> <instances> <i o="starfield" ns="http://www.fifengine.de/xml/tutorial" x="-2.0" r="0" y="-1.0" z="0.0"></i> @@ -461,6 +463,8 @@ <i r="0" id="streaker" x="37.0" o="saucer2" z="0.0" y="4.0"></i> <i r="0" id="streaker" x="37.0" o="saucer2" z="0.0" y="-5.0"></i> + <i r="0" id="cannonspread5" x="39.0" o="cannonspread5" z="0.0" y="0.0"></i> + <i r="0" id="dodge1" x="40.0" o="saucer1" z="0.0" y="-2.0"></i> <i r="0" id="dodge1" x="40.0" o="saucer1" z="0.0" y="1.0"></i> <i r="0" id="dodge1" x="40.0" o="saucer1" z="0.0" y="4.0"></i> @@ -501,7 +505,9 @@ <i r="0" id="dodge2" x="77.0" o="saucer2" z="0.0" y="-2.0"></i> <i r="0" id="dodge2" x="77.0" o="saucer2" z="0.0" y="1.0"></i> <i r="0" id="streaker" x="77.0" o="saucer2" z="0.0" y="4.0"></i> - <i r="0" id="streaker" x="77.0" o="saucer2" z="0.0" y="-5.0"></i> + <i r="0" id="streaker" x="77.0" o="saucer2" z="0.0" y="-5.0"></i> + + <i r="0" id="extralife" x="79.0" o="extralife" z="0.0" y="0.0"></i> <i r="0" id="dodge1" x="80.0" o="saucer1" z="0.0" y="-2.0"></i> <i r="0" id="dodge1" x="80.0" o="saucer1" z="0.0" y="1.0"></i> @@ -561,6 +567,8 @@ <i r="0" id="diag_bottom_right" x="144.0" o="saucer1" z="0.0" y="8.0"></i> <i r="0" id="diag_bottom_right" x="145.0" o="saucer1" z="0.0" y="9.0"></i> + <i r="0" id="cannonspread5" x="145.0" o="cannonspread5" z="0.0" y="0.0"></i> + <i r="0" id="dodge2" x="147.0" o="saucer2" z="0.0" y="-2.0"></i> <i r="0" id="dodge2" x="147.0" o="saucer2" z="0.0" y="1.0"></i> <i r="0" id="streaker" x="147.0" o="saucer2" z="0.0" y="4.0"></i>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/powerups/cannonspread5/object.xml Fri Apr 23 17:17:02 2010 +0000 @@ -0,0 +1,4 @@ +<?fife type="object"?> +<object id="cannonspread5" namespace="http://www.fifengine.de/xml/tutorial" blocking="0" static="1"> + <image source="cannon_spread.png" direction="0" /> +</object>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/powerups/extralife/object.xml Fri Apr 23 17:17:02 2010 +0000 @@ -0,0 +1,4 @@ +<?fife type="object"?> +<object id="extralife" namespace="http://www.fifengine.de/xml/tutorial" blocking="0" static="1"> + <image source="extralife.png" direction="0" /> +</object>
--- a/demos/shooter/scripts/common/baseobject.py Thu Apr 22 21:04:13 2010 +0000 +++ b/demos/shooter/scripts/common/baseobject.py Fri Apr 23 17:17:02 2010 +0000 @@ -31,6 +31,7 @@ SHTR_LASTBOSS = 2 SHTR_PROJECTILE = 3 SHTR_ENEMYSHIP = 4 +SHTR_POWERUP = 5 class SpaceObject(object): @@ -143,6 +144,8 @@ def _setInstance(self, instance): self._instance = instance + if self._instance: + self._instance.thisown = 0 def _getVelocity(self): return self._velocity
--- a/demos/shooter/scripts/gui/guis.py Thu Apr 22 21:04:13 2010 +0000 +++ b/demos/shooter/scripts/gui/guis.py Fri Apr 23 17:17:02 2010 +0000 @@ -176,7 +176,6 @@ for highscore in self._scores: if score._score > highscore._score: element = i - print element break i += 1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/scripts/powerups.py Fri Apr 23 17:17:02 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 SpaceObject +from scripts.weapons import * + +class PowerUp(SpaceObject): + def __init__(self, scene, powerupName, instance, findInstance=True): + super(PowerUp, self).__init__(scene, powerupName, findInstance) + + self.instance = instance + self._type = SHTR_POWERUP + + self.width = 0.025 + self.height = 0.025 + + def applyPowerUp(self, ship): + self.destroy() + self._scene.queueObjectForRemoval(self) + +class CannonSpread5PU(PowerUp): + def __init__(self, scene, powerupName, instance, findInstance=True): + super(CannonSpread5PU, self).__init__(scene, powerupName, instance, findInstance) + + self._dir = 0 + self._time = 1500 + self._velocity.x = -0.25 + self._velocity.y = 0 + + def applyPowerUp(self, ship): + ship.weapon = CannonSpread5(self._scene, ship, 300) + self.destroy() + self._scene.queueObjectForRemoval(self) + + def update(self): + if self._dir == 1: + self._velocity.y = -0.25 + elif self._dir == 0: + self._velocity.y = 0.25 + + if self._time >= 3000: + if self._dir == 1: + self._dir = 0 + elif self._dir == 0: + self._dir = 1 + + self._time = 0 + + self._time += self._scene.timedelta + + super(CannonSpread5PU, self).update() + +class ExtraLifePU(PowerUp): + def __init__(self, scene, powerupName, instance, findInstance=True): + super(ExtraLifePU, self).__init__(scene, powerupName, instance, findInstance) + + def applyPowerUp(self, ship): + ship.lives += 1 + self.destroy() + self._scene.queueObjectForRemoval(self) + \ No newline at end of file
--- a/demos/shooter/scripts/scene.py Thu Apr 22 21:04:13 2010 +0000 +++ b/demos/shooter/scripts/scene.py Fri Apr 23 17:17:02 2010 +0000 @@ -25,6 +25,7 @@ from scripts.ships.shipbase import * from scripts.ships.player import Player from scripts.ships.enemies import * +from scripts.powerups import * from scripts.common.helpers import Rect class SceneNode(object): @@ -100,6 +101,7 @@ self._player.start() enemies = list() + powerups = list() temp = self._layer.getInstances('dodge1') enemies.extend(temp) @@ -118,10 +120,15 @@ temp = self._layer.getInstances("boss") enemies.extend(temp) + + temp = self._layer.getInstances("cannonspread5") + powerups.extend(temp) + + temp = self._layer.getInstances("extralife") + powerups.extend(temp) for instance in enemies: objectName = instance.getId() - print objectName if objectName == "dodge1": enemy = Saucer1(self, 'enemy', instance, False) @@ -145,6 +152,25 @@ enemy.scenenodeid = nodeindex self._nodes[nodeindex].spaceobjects.append(enemy) + for instance in powerups: + objectName = instance.getId() + + print objectName + + if objectName == "cannonspread5": + powerup = CannonSpread5PU(self, 'cannonspread5', instance, False) + elif objectName == "extralife": + powerup = ExtraLifePU(self, 'extralife', instance, False) + else: + powerup = PowerUp(self, 'powerup', instance, False) + + powerup.start() + + loc = instance.getLocation().getExactLayerCoordinates() + nodeindex = int(loc.x * self._xscale) + powerup.scenenodeid = nodeindex + self._nodes[nodeindex].spaceobjects.append(powerup) + #and finally add the player to the scene self.addObjectToScene(self._player) @@ -281,12 +307,15 @@ if obj.type != SHTR_PLAYER and obj.type != SHTR_PROJECTILE: 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: - #collision damage of 1 - self.playerHit(1) - obj.applyHit(1) + if obj.type == SHTR_ENEMYSHIP: + #player touched an enemy. Destroy player and + #re-initialize scene + if not self._player.invulnerable: + #collision damage of 1 + self.playerHit(1) + obj.applyHit(1) + elif obj.type == SHTR_POWERUP: + obj.applyPowerUp(self._player) elif obj.type == SHTR_PROJECTILE: @@ -301,7 +330,7 @@ for o in pcollide: #cant get hit by your own bullet - if obj.owner != o and o.type != SHTR_PROJECTILE: + if obj.owner != o and o.type != SHTR_PROJECTILE and o.type != SHTR_POWERUP: if o.running and obj.boundingbox.intersects(o.boundingbox): if o != self._player and obj.owner.type == SHTR_PLAYER: o.applyHit(obj.damage)
--- a/demos/shooter/scripts/ships/enemies.py Thu Apr 22 21:04:13 2010 +0000 +++ b/demos/shooter/scripts/ships/enemies.py Fri Apr 23 17:17:02 2010 +0000 @@ -50,7 +50,7 @@ class Saucer1(Ship): def __init__(self, scene, name, instance, findInstance=True): super(Saucer1, self).__init__(scene, name, findInstance) - self._instance = instance + self.instance = instance self._type = SHTR_ENEMYSHIP self._dir = 0 self._time = 500 @@ -90,7 +90,7 @@ class Saucer2(Ship): def __init__(self, scene, name, instance, findInstance=True): super(Saucer2, self).__init__(scene, name, findInstance) - self._instance = instance + self.instance = instance self._type = SHTR_ENEMYSHIP self._dir = 0 self._time = 1000 @@ -133,7 +133,7 @@ class DiagSaucer(Ship): def __init__(self, scene, name, direction, instance, findInstance=True): super(DiagSaucer, self).__init__(scene, name, findInstance) - self._instance = instance + self.instance = instance self._type = SHTR_ENEMYSHIP self.width = 0.2 self.height = 0.075 @@ -161,7 +161,7 @@ class Streaker(Ship): def __init__(self, scene, name, instance, findInstance=True): super(Streaker, self).__init__(scene, name, findInstance) - self._instance = instance + self.instance = instance self._type = SHTR_ENEMYSHIP self.width = 0.2 self.height = 0.2 @@ -196,7 +196,7 @@ class Boss(Ship): def __init__(self, scene, name, instance, findInstance=True): super(Boss, self).__init__(scene, name, findInstance) - self._instance = instance + self.instance = instance self._type = SHTR_LASTBOSS self.width = 0.85 self.height = 0.25
--- a/demos/shooter/scripts/ships/player.py Thu Apr 22 21:04:13 2010 +0000 +++ b/demos/shooter/scripts/ships/player.py Fri Apr 23 17:17:02 2010 +0000 @@ -65,7 +65,6 @@ #give player the default weapon (the cannon) self.weapon = Cannon(self._scene, self, 200) - def _getScore(self): return self._score @@ -92,7 +91,10 @@ #50 is defined in the players "flash" animation file #2 is the number of frames in the animation #TODO: read these values somehow from the animation - number = (milliseconds / 50) / 2 + number = int((milliseconds / 50) / 2) + + if number <= 0: + return self._invulnerable = True self.flash(number) @@ -178,28 +180,36 @@ if not self._boundingBox.intersects(camrect): if (self._boundingBox.x + self._boundingBox.w) < camrect.x: - self._velocity.x = 0 + if self._velocity.x < 0: + self._velocity.x = 0 pos.x += (camrect.x - (self._boundingBox.x + self._boundingBox.w))/self._xscale + 0.03 - pos.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale + + if not ((self._boundingBox.y + self._boundingBox.h) < camrect.y) and not (self._boundingBox.y > (camrect.y + camrect.h)): + pos.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale + oldpos.setExactLayerCoordinates(pos) - -# elif (bbox.y + bbox.h) < camrect.y or (bbox.y - bbox.h) > camrect.y: -# pos.x += self._velocity.x * (timedelta/1000.0) -# oldpos.setExactLayerCoordinates(pos) -# self._velocity.y = 0 - elif (self._boundingBox.y + self._boundingBox.h) < camrect.y or self._boundingBox.y > (camrect.y + camrect.h): + if self._boundingBox.x > ( camrect.x + camrect.w ): + self._velocity.x = 0 + + if (self._boundingBox.y + self._boundingBox.h) < camrect.y: + if self._velocity.y < 0: + self._velocity.y = 0 pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale - self._velocity.y = 0 + oldpos.setExactLayerCoordinates(pos) + if self._boundingBox.y > (camrect.y + camrect.h): + if self._velocity.y > 0: + self._velocity.y = 0 + pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale oldpos.setExactLayerCoordinates(pos) - else: - self._velocity.x = 0 - self._velocity.y = 0 self.location = oldpos def _getLives(self): return self._lives + def _setLives(self, lives): + self._lives = lives + def _getInvulnerable(self): return self._invulnerable @@ -207,5 +217,5 @@ self._invulnerable = inv score = property(_getScore) - lives = property(_getLives) + lives = property(_getLives, _setLives) invulnerable = property(_getInvulnerable, _setInvulnerable) \ No newline at end of file
--- a/demos/shooter/scripts/weapons.py Thu Apr 22 21:04:13 2010 +0000 +++ b/demos/shooter/scripts/weapons.py Fri Apr 23 17:17:02 2010 +0000 @@ -232,4 +232,48 @@ self._scene.addObjectToScene(pjctl7) self._lastfired = self._scene.time + +class CannonSpread5(Weapon): + def __init__(self, scene, ship, firerate): + super(CannonSpread5, self).__init__(scene, ship, firerate) + + self._projectileVelocity = 1 + + def fire(self, direction): + + if (self._scene.time - self._lastfired) > self._firerate: + velocity = normalize(direction) + velocity.x = velocity.x * self._projectileVelocity + velocity.y = velocity.y * self._projectileVelocity + origin = fife.DoublePoint(0,0) + + p2 = rotatePoint(origin, velocity, -10) + p3 = rotatePoint(origin, velocity, -5) + p4 = rotatePoint(origin, velocity, 0) + p5 = rotatePoint(origin, velocity, 5) + p6 = rotatePoint(origin, velocity, 10) + + pjctl2 = Projectile(self._scene, self._ship, "bullet1", 3000 ) + pjctl2.run(p2, self._ship.location) + self._scene.addObjectToScene(pjctl2) + + pjctl3 = Projectile(self._scene, self._ship, "bullet1", 3000 ) + pjctl3.run(p3, self._ship.location) + self._scene.addObjectToScene(pjctl3) + + pjctl4 = Projectile(self._scene, self._ship, "bullet1", 3000 ) + pjctl4.run(p4, self._ship.location) + self._scene.addObjectToScene(pjctl4) + + pjctl5 = Projectile(self._scene, self._ship, "bullet1", 3000 ) + pjctl5.run(p5, self._ship.location) + self._scene.addObjectToScene(pjctl5) + + pjctl6 = Projectile(self._scene, self._ship, "bullet1", 3000 ) + pjctl6.run(p6, self._ship.location) + self._scene.addObjectToScene(pjctl6) + + + self._lastfired = self._scene.time +