Mercurial > fife-parpg
changeset 472:3164715a0621
Added the FireBallBurst and FireBallSpread weapons which are now used by the boss.
Added rotatePoint function.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 16 Apr 2010 21:44:18 +0000 |
parents | 7a79dc2a0592 |
children | b78020d31186 |
files | demos/shooter/gui/highscores.xml demos/shooter/run.py demos/shooter/scripts/common/helpers.py demos/shooter/scripts/ships/enemies.py demos/shooter/scripts/weapons.py demos/shooter/scripts/world.py |
diffstat | 6 files changed, 203 insertions(+), 99 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/shooter/gui/highscores.xml Thu Apr 15 15:53:06 2010 +0000 +++ b/demos/shooter/gui/highscores.xml Fri Apr 16 21:44:18 2010 +0000 @@ -8,81 +8,81 @@ <HBox> <Label name="1" border_size="5" text="1" min_size="20,0"> </Label> - <Label name="1name" border_size="5" text="player" min_size="50,0"> + <Label name="1name" border_size="5" text="WAY" min_size="50,0"> </Label> - <Label name="1score" border_size="5" text="1200" min_size="150,0"> + <Label name="1score" border_size="5" text="6900" min_size="150,0"> </Label> </HBox> <HBox> <Label name="2" border_size="5" text="2" min_size="20,0"> </Label> - <Label name="2name" border_size="5" text="aaa" min_size="50,0"> + <Label name="2name" border_size="5" text="way" min_size="50,0"> </Label> - <Label name="2score" border_size="5" text="1000" min_size="150,0"> + <Label name="2score" border_size="5" text="5650" min_size="150,0"> </Label> </HBox> <HBox> <Label name="3" border_size="5" text="3" min_size="20,0"> </Label> - <Label name="3name" border_size="5" text="bbb" min_size="50,0"> + <Label name="3name" border_size="5" text="dfd" min_size="50,0"> </Label> - <Label name="3score" border_size="5" text="1000" min_size="150,0"> + <Label name="3score" border_size="5" text="4750" min_size="150,0"> </Label> </HBox> <HBox> <Label name="4" border_size="5" text="4" min_size="20,0"> </Label> - <Label name="4name" border_size="5" text="ccc" min_size="50,0"> + <Label name="4name" border_size="5" text="d" min_size="50,0"> </Label> - <Label name="4score" border_size="5" text="1000" min_size="150,0"> + <Label name="4score" border_size="5" text="4450" min_size="150,0"> </Label> </HBox> <HBox> <Label name="5" border_size="5" text="5" min_size="20,0"> </Label> - <Label name="5name" border_size="5" text="ddd" min_size="50,0"> + <Label name="5name" border_size="5" text="t" min_size="50,0"> </Label> - <Label name="5score" border_size="5" text="1000" min_size="150,0"> + <Label name="5score" border_size="5" text="4150" min_size="150,0"> </Label> </HBox> <HBox> <Label name="6" border_size="5" text="6" min_size="20,0"> </Label> - <Label name="6name" border_size="5" text="eee" min_size="50,0"> + <Label name="6name" border_size="5" text="df" min_size="50,0"> </Label> - <Label name="6score" border_size="5" text="1000" min_size="150,0"> + <Label name="6score" border_size="5" text="3650" min_size="150,0"> </Label> </HBox> <HBox> <Label name="7" border_size="5" text="7" min_size="20,0"> </Label> - <Label name="7name" border_size="5" text="fff" min_size="50,0"> + <Label name="7name" border_size="5" text="gs" min_size="50,0"> </Label> - <Label name="7score" border_size="5" text="1000" min_size="150,0"> + <Label name="7score" border_size="5" text="2600" min_size="150,0"> </Label> </HBox> <HBox> <Label name="8" border_size="5" text="8" min_size="20,0"> </Label> - <Label name="8name" border_size="5" text="ggg" min_size="50,0"> + <Label name="8name" border_size="5" text="boo" min_size="50,0"> </Label> - <Label name="8score" border_size="5" text="1000" min_size="150,0"> + <Label name="8score" border_size="5" text="2150" min_size="150,0"> </Label> </HBox> <HBox> <Label name="9" border_size="5" text="9" min_size="20,0"> </Label> - <Label name="9name" border_size="5" text="hhh" min_size="50,0"> + <Label name="9name" border_size="5" text="way" min_size="50,0"> </Label> - <Label name="9score" border_size="5" text="1000" min_size="150,0"> + <Label name="9score" border_size="5" text="1850" min_size="150,0"> </Label> </HBox> <HBox> <Label name="10" border_size="5" text="10" min_size="20,0"> </Label> - <Label name="10name" border_size="5" text="iii" min_size="50,0"> + <Label name="10name" border_size="5" text="df" min_size="50,0"> </Label> - <Label name="10score" border_size="5" text="1000" min_size="150,0"> + <Label name="10score" border_size="5" text="1500" min_size="150,0"> </Label> </HBox> <Button name="close" border_size="0" text="Close" min_size="100,0">
--- a/demos/shooter/run.py Thu Apr 15 15:53:06 2010 +0000 +++ b/demos/shooter/run.py Fri Apr 16 21:44:18 2010 +0000 @@ -43,25 +43,25 @@ class ApplicationListener(eventlistenerbase.EventListenerBase): def __init__(self, engine, world): super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True) - self.engine = engine - self.world = world + self._engine = engine + self._world = world engine.getEventManager().setNonConsumableKeys([ fife.Key.ESCAPE,]) - self.quit = False + self._quit = False def keyPressed(self, evt): keyval = evt.getKey().getValue() keystr = evt.getKey().getAsString().lower() consumed = False if keyval == fife.Key.ESCAPE: - #self.quit = True - self.world.showMainMenu() + #self._quit = True + self._world.showMainMenu() evt.consume() def onCommand(self, command): - self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) - if self.quit: + self._quit = (command.getCommandType() == fife.CMD_QUIT_GAME) + if self._quit: command.consume() class Shooter(ApplicationBase): @@ -70,8 +70,8 @@ pychan.init(self.engine, debug=False) pychan.setupModalExecution(self.mainLoop,self.breakFromMainLoop) - self.world = world.World(self, self.engine) - self.listener = ApplicationListener(self.engine, self.world) + self._world = world.World(self, self.engine) + self._listener = ApplicationListener(self.engine, self._world) def requestQuit(self): cmd = fife.Command() @@ -111,18 +111,18 @@ #LogModules = list() #LogModules.append("controller") LogModules = ["controller",] - self.log = fifelog.LogManager(self.engine, 1, 0) + self._log = fifelog.LogManager(self.engine, 1, 0) if LogModules: - self.log.setVisibleModules(*LogModules) + self._log.setVisibleModules(*LogModules) def createListener(self): pass # already created in constructor def _pump(self): - if self.listener.quit: + if self._listener._quit: self.breakRequested = True else: - self.world.pump() + self._world.pump() def main(): app = Shooter()
--- a/demos/shooter/scripts/common/helpers.py Thu Apr 15 15:53:06 2010 +0000 +++ b/demos/shooter/scripts/common/helpers.py Fri Apr 16 21:44:18 2010 +0000 @@ -22,6 +22,7 @@ # #################################################################### from fife import fife +import math def normalize(vector): @@ -99,4 +100,15 @@ x = property(_getX, _setX) y = property(_getY, _setY) w = property(_getW, _setW) - h = property(_getH, _setH) \ No newline at end of file + h = property(_getH, _setH) + +def rotatePoint(origin, point, angle): + newp = fife.DoublePoint(0,0) + + 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) + + return newp + \ No newline at end of file
--- a/demos/shooter/scripts/ships/enemies.py Thu Apr 15 15:53:06 2010 +0000 +++ b/demos/shooter/scripts/ships/enemies.py Fri Apr 16 21:44:18 2010 +0000 @@ -205,7 +205,7 @@ self._actionlistener = BossActionListener(self) - self.hitpoints = 20 + self.hitpoints = 30 self.scorevalue = 1000 def endLevel(self): @@ -225,4 +225,11 @@ def applyHit(self, hp): self.flash(2) - super(Boss, self).applyHit(hp) \ No newline at end of file + super(Boss, self).applyHit(hp) + + if self.hitpoints == 20: + self.weapon = FireBallBurst(self._scene, self, 2000, 100, 10) + + elif self.hitpoints == 10: + self.weapon = FireBallSpread(self._scene, self, 2000) + \ No newline at end of file
--- a/demos/shooter/scripts/weapons.py Thu Apr 15 15:53:06 2010 +0000 +++ b/demos/shooter/scripts/weapons.py Fri Apr 16 21:44:18 2010 +0000 @@ -23,7 +23,7 @@ from fife import fife from scripts.ships.shipbase import SpaceObject -from scripts.common.helpers import normalize +from scripts.common.helpers import normalize, rotatePoint class Projectile(SpaceObject): def __init__(self, scene, owner, projectileName, timeToLive): @@ -121,7 +121,7 @@ velocity.y = velocity.y * self._projectileVelocity if (self._scene.time - self._lastfired) > self._firerate: - pjctl = Projectile(self._scene, self._ship, "bullet1", 6000 ) + pjctl = Projectile(self._scene, self._ship, "bullet1", 3000 ) pjctl.run(velocity, self._ship.location) self._lastfired = self._scene.time self._scene.addProjectileToScene(pjctl) @@ -143,4 +143,90 @@ pjctl.run(velocity, self._ship.location) self._lastfired = self._scene.time self._scene.addProjectileToScene(pjctl) + +class FireBallBurst(Weapon): + def __init__(self, scene, ship, firerate, burstrate, burstnumber): + super(FireBallBurst, self).__init__(scene, ship, firerate) + + self._projectileVelocity = 0.50 + + self._burstrate = burstrate + self._burstnumber = int(burstnumber) + self._burstcount = int(burstnumber) + + self._lastburstfired = 0 + + def fire(self, direction): + velocity = normalize(direction) + velocity.x = velocity.x * self._projectileVelocity + velocity.y = velocity.y * self._projectileVelocity + + if (self._scene.time - self._lastfired) > self._firerate: + if (self._scene.time - self._lastburstfired) > self._burstrate and self._burstcount > 0: + pjctl = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl.run(velocity, self._ship.location) + self._scene.addProjectileToScene(pjctl) + + self._lastburstfired = self._scene.time + self._burstcount -= 1 + + if self._burstcount <= 0: + self._lastfired = self._scene.time + self._burstcount = int(self._burstnumber) + self._lastburstfired = 0 + +class FireBallSpread(Weapon): + def __init__(self, scene, ship, firerate): + super(FireBallSpread, self).__init__(scene, ship, firerate) + + self._projectileVelocity = 0.50 + + + 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) + + p1 = rotatePoint(origin, velocity, -30) + p2 = rotatePoint(origin, velocity, -20) + p3 = rotatePoint(origin, velocity, -10) + p4 = rotatePoint(origin, velocity, 0) + p5 = rotatePoint(origin, velocity, 10) + p6 = rotatePoint(origin, velocity, 20) + p7 = rotatePoint(origin, velocity, 30) + + pjctl1 = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl1.run(p1, self._ship.location) + self._scene.addProjectileToScene(pjctl1) + + pjctl2 = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl2.run(p2, self._ship.location) + self._scene.addProjectileToScene(pjctl2) + + pjctl3 = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl3.run(p3, self._ship.location) + self._scene.addProjectileToScene(pjctl3) + + pjctl4 = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl4.run(p4, self._ship.location) + self._scene.addProjectileToScene(pjctl4) + + pjctl5 = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl5.run(p5, self._ship.location) + self._scene.addProjectileToScene(pjctl5) + + pjctl6 = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl6.run(p6, self._ship.location) + self._scene.addProjectileToScene(pjctl6) + + pjctl7 = Projectile(self._scene, self._ship, "fireball", 6000 ) + pjctl7.run(p7, self._ship.location) + self._scene.addProjectileToScene(pjctl7) + + self._lastfired = self._scene.time +
--- a/demos/shooter/scripts/world.py Thu Apr 15 15:53:06 2010 +0000 +++ b/demos/shooter/scripts/world.py Fri Apr 16 21:44:18 2010 +0000 @@ -51,16 +51,15 @@ def __init__(self, app, engine): super(World, self).__init__(engine, regMouse=True, regKeys=True) self._applictaion = app - self.engine = engine - self.timemanager = engine.getTimeManager() - self.eventmanager = engine.getEventManager() - self.model = engine.getModel() - self.filename = '' - self.keystate = { 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'CTRL': False, 'SPACE': False, } - self.dynamic_widgets = {} - self.pump_ctr = 0 - self.map = None - self.scene = None + self._engine = engine + self._timemanager = engine.getTimeManager() + self._eventmanager = engine.getEventManager() + self._model = engine.getModel() + self._filename = '' + self._keystate = { 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'CTRL': False, 'SPACE': False, } + self._pump_ctr = 0 + self._map = None + self._scene = None self._paused = True self._pausedtime = 0 self._starttime = 0 @@ -88,7 +87,7 @@ self._gamecomplete = False def showMainMenu(self): - if self.scene: + if self._scene: self._paused = True cont = True else: @@ -107,15 +106,15 @@ self._applictaion.requestQuit() def reset(self): - if self.map: - self.model.deleteMap(self.map) - self.map = None + if self._map: + self._model.deleteMap(self._map) + self._map = None self.cameras = {} - if self.scene: - self.scene.destroyScene() - self.scene = None + if self._scene: + self._scene.destroyScene() + self._scene = None self._gamecomplete = False @@ -126,12 +125,12 @@ self.resetKeys() - self.filename = filename + self._filename = filename self.reset() - self.map = loadMapFile(self.filename, self.engine) + self._map = loadMapFile(self._filename, self._engine) - self.scene = Scene(self, self.engine, self.map.getLayer('objects')) - self.scene.initScene(self.map) + self._scene = Scene(self, self._engine, self._map.getLayer('objects')) + self._scene.initScene(self._map) self.initCameras() @@ -139,11 +138,11 @@ self._gameover.hide() self._winner.hide() - self._starttime = self.timemanager.getTime() + self._starttime = self._timemanager.getTime() self._genericrenderer = fife.GenericRenderer.getInstance(self.cameras['main']) self._genericrenderer.clearActiveLayers() - self._genericrenderer.addActiveLayer(self.map.getLayer('objects')) + self._genericrenderer.addActiveLayer(self._map.getLayer('objects')) self._genericrenderer.setEnabled(True) @@ -162,19 +161,19 @@ obj_bottomleft = fife.ExactModelCoordinate(bbox.x, bbox.y + bbox.h) loc_topleft = fife.Location() - loc_topleft.setLayer(self.map.getLayer('boundingbox')) + loc_topleft.setLayer(self._map.getLayer('boundingbox')) loc_topleft.setExactLayerCoordinates(obj_topleft) loc_topright = fife.Location() - loc_topright.setLayer(self.map.getLayer('boundingbox')) + loc_topright.setLayer(self._map.getLayer('boundingbox')) loc_topright.setExactLayerCoordinates(obj_topright) loc_bottomright = fife.Location() - loc_bottomright.setLayer(self.map.getLayer('boundingbox')) + loc_bottomright.setLayer(self._map.getLayer('boundingbox')) loc_bottomright.setExactLayerCoordinates(obj_bottomright) loc_bottomleft = fife.Location() - loc_bottomleft.setLayer(self.map.getLayer('boundingbox')) + loc_bottomleft.setLayer(self._map.getLayer('boundingbox')) loc_bottomleft.setExactLayerCoordinates(obj_bottomleft) node_topleft = fife.GenericRendererNode(loc_topleft) @@ -219,8 +218,8 @@ def saveScore(self): self._gamecomplete = False - if self._highscores.isHighScore(self.scene.player.score): - score = self.scene.player.score + if self._highscores.isHighScore(self._scene.player.score): + score = self._scene.player.score dlg = pychan.loadXML('gui/highscoredialog.xml') dlg.execute({ 'okay' : "Yay!" }) @@ -245,61 +244,61 @@ This is done through Camera objects which offer a viewport on the map. """ - for cam in self.map.getCameras(): + for cam in self._map.getCameras(): if cam.getId() == 'main': self.cameras['main'] = cam - self.scene.attachCamera(self.cameras['main']) + self._scene.attachCamera(self.cameras['main']) def resetKeys(self): - self.keystate['UP'] = False - self.keystate['DOWN'] = False - self.keystate['LEFT'] = False - self.keystate['RIGHT'] = False - self.keystate['SPACE'] = False - self.keystate['CTRL'] = False + self._keystate['UP'] = False + self._keystate['DOWN'] = False + self._keystate['LEFT'] = False + self._keystate['RIGHT'] = False + self._keystate['SPACE'] = False + self._keystate['CTRL'] = False def keyPressed(self, evt): keyval = evt.getKey().getValue() keystr = evt.getKey().getAsString().lower() if keyval == fife.Key.UP: - self.keystate['UP'] = True + self._keystate['UP'] = True elif keyval == fife.Key.DOWN: - self.keystate['DOWN'] = True + self._keystate['DOWN'] = True elif keyval == fife.Key.LEFT: - self.keystate['LEFT'] = True + self._keystate['LEFT'] = True elif keyval == fife.Key.RIGHT: - self.keystate['RIGHT'] = True + self._keystate['RIGHT'] = True elif keyval == fife.Key.SPACE: - self.keystate['SPACE'] = True + self._keystate['SPACE'] = True elif keyval == fife.Key.P: self._paused = not self._paused - self._pausedtime += self.timemanager.getTime() + self._pausedtime += self._timemanager.getTime() elif keyval in (fife.Key.LEFT_CONTROL, fife.Key.RIGHT_CONTROL): - self.keystate['CTRL'] = True + self._keystate['CTRL'] = True def keyReleased(self, evt): keyval = evt.getKey().getValue() if keyval == fife.Key.UP: - self.keystate['UP'] = False + self._keystate['UP'] = False elif keyval == fife.Key.DOWN: - self.keystate['DOWN'] = False + self._keystate['DOWN'] = False elif keyval == fife.Key.LEFT: - self.keystate['LEFT'] = False + self._keystate['LEFT'] = False elif keyval == fife.Key.RIGHT: - self.keystate['RIGHT'] = False + self._keystate['RIGHT'] = False elif keyval == fife.Key.SPACE: - self.keystate['SPACE'] = False + self._keystate['SPACE'] = False elif keyval in (fife.Key.LEFT_CONTROL, fife.Key.RIGHT_CONTROL): - self.keystate['CTRL'] = False + self._keystate['CTRL'] = False def mouseWheelMovedUp(self, evt): - if self.keystate['CTRL']: + if self._keystate['CTRL']: self.cameras['main'].setZoom(self.cameras['main'].getZoom() * 1.05) def mouseWheelMovedDown(self, evt): - if self.keystate['CTRL']: + if self._keystate['CTRL']: self.cameras['main'].setZoom(self.cameras['main'].getZoom() / 1.05) def mousePressed(self, evt): @@ -324,19 +323,19 @@ self._genericrenderer.removeAll("quads") - if not self.scene: + if not self._scene: return #update the scene if not self._paused: - if self.scene.paused: - self.scene.unpause(self.timemanager.getTime() - self._starttime) + if self._scene.paused: + self._scene.unpause(self._timemanager.getTime() - self._starttime) - self.scene.update(self.timemanager.getTime() - self._starttime, self.keystate) + self._scene.update(self._timemanager.getTime() - self._starttime, self._keystate) #update the HUD - avgframe = self.timemanager.getAverageFrameTime() + avgframe = self._timemanager.getAverageFrameTime() if avgframe > 0: fps = 1 / (avgframe / 1000) else: @@ -344,7 +343,7 @@ fpstxt = "%3.2f" % fps self._hudwindow.setFPSText(unicode(fpstxt)) - player = self.scene.player + player = self._scene.player exactcoords = player.location.getExactLayerCoordinates() pos = "%1.2f" % exactcoords.x + ", %1.2f" % exactcoords.y self._hudwindow.setPositionText(unicode(pos)) @@ -362,8 +361,8 @@ self._hudwindow.setLivesText(lives) else: - if not self.scene.paused: - self.scene.pause(self.timemanager.getTime() - self._starttime) + if not self._scene.paused: + self._scene.pause(self._timemanager.getTime() - self._starttime) - self.pump_ctr += 1 + self._pump_ctr += 1