Mercurial > fife-parpg
changeset 450:ba6817013343
Added score keeping ability.
Some misc cleanup.
Fixed the bounding box.
Enemies are now removed from the scene when they are destroyed.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 01 Apr 2010 19:26:56 +0000 |
parents | 1cf56403347a |
children | f463ab431cc0 |
files | demos/shooter/gui/mainwindow.xml demos/shooter/scripts/common/baseobject.py demos/shooter/scripts/scene.py demos/shooter/scripts/ships/player.py demos/shooter/scripts/world.py |
diffstat | 5 files changed, 39 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/demos/shooter/gui/mainwindow.xml Thu Apr 01 18:44:01 2010 +0000 +++ b/demos/shooter/gui/mainwindow.xml Thu Apr 01 19:26:56 2010 +0000 @@ -11,4 +11,8 @@ <Label text = "Player Velocity: "/> <Label name="velocity" text="x,y "/> </HBox> + <HBox opaque='0'> + <Label text = "SCORE: "/> + <Label name="score" text="0 "/> + </HBox> </VBox> \ No newline at end of file
--- a/demos/shooter/scripts/common/baseobject.py Thu Apr 01 18:44:01 2010 +0000 +++ b/demos/shooter/scripts/common/baseobject.py Thu Apr 01 19:26:56 2010 +0000 @@ -57,8 +57,8 @@ exactloc.x += self._velocity.x exactloc.y += self._velocity.y - self._boundingBox.x = exactloc.x + self._boundingBox.w/2 - self._boundingBox.y = exactloc.y + self._boundingBox.h/2 + self._boundingBox.x = exactloc.x - self._boundingBox.w/2 + self._boundingBox.y = exactloc.y - self._boundingBox.h/2 shiploc.setExactLayerCoordinates(exactloc) self.location = shiploc
--- a/demos/shooter/scripts/scene.py Thu Apr 01 18:44:01 2010 +0000 +++ b/demos/shooter/scripts/scene.py Thu Apr 01 19:26:56 2010 +0000 @@ -94,11 +94,11 @@ return objects - def checkCollision(self, instance1, instance2): - pos1 = instnace1.getLocation().getExactLayerCoordinates() - pos2 = instnace2.getLocation().getExactLayerCoordinates() - - + def removeObjectFromScene(self, obj): + for node in self._nodes: + if obj in node.spaceobjects: + node.spaceobjects.remove(obj) + return def attachCamera(self, cam): self._camera = cam @@ -123,32 +123,40 @@ #which scene nodes to use to update objects leftnode = int(topleft.x) - rightnode = int(bottomright.x) + 2 + rightnode = int(bottomright.x) + 1 - #update other objects on the screen + #get a list of objects on the screen if leftnode < 0: leftnode = 0 if rightnode > self._maxnodes: rightnode = self._maxnodes screenlist = self.getObjectsInRange(leftnode, rightnode) - for cl in screenlist: - cl.update(timedelta) + #update objects on the screen + for obj in screenlist: + obj.update(timedelta) #update the player self._player.update(timedelta, keystate, self._camera) #update the list of projectiles - todelete = list() + projtodelete = list() for p in self._projectiles: p.update(timedelta) + #check to see if the projectile hit any object on the screen for o in screenlist: if p.boundingbox.intersects(o.boundingbox): + self._player.applyScore(100) p.destroy() o.destroy() + self.removeObjectFromScene(o) + + #build a list of projectiles to remove (ttl expired) if not p.running: - todelete.append(p) - for p in todelete: + projtodelete.append(p) + + #remove any non running projectiles + for p in projtodelete: self._projectiles.remove(p) #fire the currently selected gun
--- a/demos/shooter/scripts/ships/player.py Thu Apr 01 18:44:01 2010 +0000 +++ b/demos/shooter/scripts/ships/player.py Thu Apr 01 19:26:56 2010 +0000 @@ -30,7 +30,14 @@ def __init__(self, model, playerName, layer): super(Player, self).__init__(model, playerName, layer) self._bounds = Rect(-100,-100,200,200) + self._score = 0 + + def _getScore(self): + return self._score + def applyScore(self, sc): + self._score += sc + def update(self, timedelta, keystate, camera): key = False @@ -97,3 +104,5 @@ self.location = oldpos + + score = property(_getScore) \ No newline at end of file
--- a/demos/shooter/scripts/world.py Thu Apr 01 18:44:01 2010 +0000 +++ b/demos/shooter/scripts/world.py Thu Apr 01 19:26:56 2010 +0000 @@ -83,6 +83,7 @@ self.fpstext = self.mainwindow.findChild(name="fps") self.velocitytext = self.mainwindow.findChild(name="velocity") self.positiontext = self.mainwindow.findChild(name="position") + self.scoretext = self.mainwindow.findChild(name="score") self.mainwindow.position = (0,0) self.mainwindow.show() @@ -177,5 +178,8 @@ vel = "%1.2f" % player.velocity.x + ", %1.2f" % player.velocity.y self.velocitytext.text = unicode(vel) + score = unicode(str(player.score)) + self.scoretext.text = score + self.pump_ctr += 1