# HG changeset patch
# User prock@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1270150016 0
# Node ID ba6817013343f36a416a5f2d8d036c499cad289e
# Parent 1cf56403347a605eec2907bea46bef0d73d58b01
Added score keeping ability.
Some misc cleanup.
Fixed the bounding box.
Enemies are now removed from the scene when they are destroyed.
diff -r 1cf56403347a -r ba6817013343 demos/shooter/gui/mainwindow.xml
--- 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 @@
+
+
+
+
\ No newline at end of file
diff -r 1cf56403347a -r ba6817013343 demos/shooter/scripts/common/baseobject.py
--- 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
diff -r 1cf56403347a -r ba6817013343 demos/shooter/scripts/scene.py
--- 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
diff -r 1cf56403347a -r ba6817013343 demos/shooter/scripts/ships/player.py
--- 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
diff -r 1cf56403347a -r ba6817013343 demos/shooter/scripts/world.py
--- 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