# HG changeset patch
# User prock@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1270849348 0
# Node ID 5e1d6e40d19d81383bb01766159a1057c240b9e4
# Parent 302a69c5141d0893bc2e093a74cfb0e8d86e4a1f
Fixed bounding boxes.
Added bounding box renderer.
The player is now better confined to the screen.
Added more enemies to the map.
diff -r 302a69c5141d -r 5e1d6e40d19d demos/shooter/maps/shooter_map1.xml
--- a/demos/shooter/maps/shooter_map1.xml Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/maps/shooter_map1.xml Fri Apr 09 21:42:28 2010 +0000
@@ -454,10 +454,15 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
diff -r 302a69c5141d -r 5e1d6e40d19d demos/shooter/scripts/common/baseobject.py
--- a/demos/shooter/scripts/common/baseobject.py Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/common/baseobject.py Fri Apr 09 21:42:28 2010 +0000
@@ -57,8 +57,8 @@
exactloc.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale
exactloc.y += self._velocity.y * (self._scene.timedelta/1000.0)/self._yscale
- self._boundingBox.x = (exactloc.x - self._boundingBox.w/2) * self._xscale
- self._boundingBox.y = (exactloc.y - self._boundingBox.h/2) * self._yscale
+ self._boundingBox.x = (exactloc.x * self._xscale - self._boundingBox.w/2)
+ self._boundingBox.y = (exactloc.y * self._yscale - self._boundingBox.h/2)
shiploc.setExactLayerCoordinates(exactloc)
diff -r 302a69c5141d -r 5e1d6e40d19d demos/shooter/scripts/scene.py
--- a/demos/shooter/scripts/scene.py Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/scene.py Fri Apr 09 21:42:28 2010 +0000
@@ -74,8 +74,6 @@
self._nodes.append(SceneNode())
self._player = Player(self, 'player')
- self._player.width = 0.075
- self._player.height = 0.075
self._player.init()
self._player.start()
@@ -137,7 +135,7 @@
if self._player.lives <= -1:
self._gameover = True
self._world.gameOver()
- self.removeAllProjectiles()
+ #self.removeAllProjectiles()
return
self._player.setInvulnerable(2)
@@ -240,6 +238,9 @@
#re-initialize scene
if not self._player.invulnerable:
self.playerHit()
+ obj.destroy()
+
+# self._world.renderBoundingBox(obj)
@@ -258,12 +259,14 @@
o.destroy()
#TODO: the destroy functions should spawn an explosion
#and also destroy the instance and remove itself from the scene
- self.removeObjectFromScene(o)
+ #self.removeObjectFromScene(o)
else:
#player got hit by a projectile
if not self._player.invulnerable:
p.destroy()
self.playerHit()
+
+# self._world.renderBoundingBox(p)
#build a list of projectiles to remove (ttl expired)
diff -r 302a69c5141d -r 5e1d6e40d19d demos/shooter/scripts/ships/enemies.py
--- a/demos/shooter/scripts/ships/enemies.py Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/ships/enemies.py Fri Apr 09 21:42:28 2010 +0000
@@ -32,7 +32,7 @@
super(Saucer1, self).__init__(scene, name, findInstance)
self._dir = 0
self._time = 500
- self.width = 0.075
+ self.width = 0.2
self.height = 0.075
self.velocity.x = -0.5
@@ -91,7 +91,7 @@
def __init__(self, scene, name, direction, findInstance=True):
super(DiagSaucer, self).__init__(scene, name, findInstance)
self.width = 0.2
- self.height = 0.2
+ self.height = 0.075
if direction == 0:
self._ythrust = 0.25
@@ -109,6 +109,9 @@
def __init__(self, scene, name, findInstance=True):
super(Streaker, self).__init__(scene, name, findInstance)
+ self.width = 0.2
+ self.height = 0.2
+
self._maxvelocity = 2.0
self.weapon = Cannon(self._scene, self, 2000)
diff -r 302a69c5141d -r 5e1d6e40d19d demos/shooter/scripts/ships/player.py
--- a/demos/shooter/scripts/ships/player.py Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/ships/player.py Fri Apr 09 21:42:28 2010 +0000
@@ -34,6 +34,9 @@
self._score = 0
self._maxvelocity = 1.5
+ self.width = 0.22
+ self.height = 0.12
+
#give player the default weapon (the cannon)
self.weapon = Cannon(self._scene, self, 200)
@@ -105,22 +108,27 @@
camrect.w -= 2*self._boundingBox.w
camrect.h -= 2*self._boundingBox.h
+ pos = oldpos.getExactLayerCoordinates()
+
if not self._boundingBox.intersects(camrect):
if (self._boundingBox.x + self._boundingBox.w) < camrect.x:
- #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale
- #oldpos.setExactLayerCoordinates(pos)
- self._velocity.x = (self._scene.timedelta * 0.01) / self._xscale
+ 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
+ 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):
+ pos.x += self._velocity.x * (self._scene.timedelta/1000.0)/self._xscale
+ self._velocity.y = 0
+ oldpos.setExactLayerCoordinates(pos)
else:
self._velocity.x = 0
self._velocity.y = 0
-
-
self.location = oldpos
def _getLives(self):
diff -r 302a69c5141d -r 5e1d6e40d19d demos/shooter/scripts/ships/shipbase.py
--- a/demos/shooter/scripts/ships/shipbase.py Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/ships/shipbase.py Fri Apr 09 21:42:28 2010 +0000
@@ -62,6 +62,9 @@
self._flashrate = rate * 2
self._flashnumber = number * 2
+ def destroy(self):
+ self._scene.removeObjectFromScene(self)
+ super(Ship, self).destroy()
def update(self):
if self._flashing:
diff -r 302a69c5141d -r 5e1d6e40d19d demos/shooter/scripts/world.py
--- a/demos/shooter/scripts/world.py Fri Apr 09 17:35:52 2010 +0000
+++ b/demos/shooter/scripts/world.py Fri Apr 09 21:42:28 2010 +0000
@@ -22,6 +22,7 @@
# ####################################################################
from fife import fife
+import copy
import math, random
from fife.extensions import pychan
from fife.extensions.pychan import widgets
@@ -71,8 +72,10 @@
self._hudwindow.hide()
self._gameover = GameOverDisplay()
- self._gameover.hide()
-
+ self._gameover.hide()
+
+ self._genericrenderer = None
+
def showMainMenu(self):
if self.scene:
self._paused = True
@@ -118,6 +121,67 @@
self._gameover.hide()
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.setEnabled(True)
+
+
+ def renderBoundingBox(self, obj):
+ bbox = copy.copy(obj.boundingbox)
+
+ #apply the object layer scale
+ bbox.x /= 0.25
+ bbox.y /= 0.25
+ bbox.w /= 0.25
+ bbox.h /= 0.25
+
+ obj_topleft = fife.ExactModelCoordinate(bbox.x, bbox.y)
+ obj_topright = fife.ExactModelCoordinate(bbox.x + bbox.w, bbox.y)
+ obj_bottomright = fife.ExactModelCoordinate(bbox.x + bbox.w, bbox.y + bbox.h)
+ obj_bottomleft = fife.ExactModelCoordinate(bbox.x, bbox.y + bbox.h)
+
+ loc_topleft = fife.Location()
+ 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.setExactLayerCoordinates(obj_topright)
+
+ loc_bottomright = fife.Location()
+ 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.setExactLayerCoordinates(obj_bottomleft)
+
+ node_topleft = fife.GenericRendererNode(loc_topleft)
+ node_topright = fife.GenericRendererNode(loc_topright)
+ node_bottomright = fife.GenericRendererNode(loc_bottomright)
+ node_bottomleft = fife.GenericRendererNode(loc_bottomleft)
+
+
+ self._genericrenderer.addLine("quads", node_topleft, node_topright, 255, 255, 255)
+ self._genericrenderer.addLine("quads", node_topright, node_bottomright, 255, 255, 255)
+ self._genericrenderer.addLine("quads", node_bottomright, node_bottomleft, 255, 255, 255)
+ self._genericrenderer.addLine("quads", node_bottomleft, node_topleft, 255, 255, 255)
+
+ #had to do this or it would segfault
+ obj_topleft.thisown = 0
+ obj_topright.thisown = 0
+ obj_bottomright.thisown = 0
+ obj_bottomleft.thisown = 0
+ loc_topleft.thisown = 0
+ loc_topright.thisown = 0
+ loc_bottomright.thisown = 0
+ loc_bottomleft.thisown = 0
+ node_topleft.thisown = 0
+ node_topright.thisown = 0
+ node_bottomright.thisown = 0
+ node_bottomleft.thisown = 0
def gameOver(self):
self._gameover.show()
@@ -199,6 +263,10 @@
"""
Called every frame.
"""
+
+ if self._genericrenderer:
+ self._genericrenderer.removeAll("quads")
+
if not self.scene:
return