# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1270069987 0 # Node ID 64676ea554729011ac40c29d536a953317770514 # Parent 2046a1f2f5f25ed50426bc6ed292c0e051a96c52 Added the ability to set the scale of the object layer. Tweaked the player controls a little bit. A little more work needs to be done to keep the player within the bounds of the camera. diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/maps/shooter_map1.xml --- a/demos/shooter/maps/shooter_map1.xml Wed Mar 31 15:40:00 2010 +0000 +++ b/demos/shooter/maps/shooter_map1.xml Wed Mar 31 21:13:07 2010 +0000 @@ -2,15 +2,12 @@ + + - - - - - @@ -21,10 +18,7 @@ - - - @@ -33,8 +27,6 @@ - - @@ -235,11 +227,6 @@ - - - - - @@ -445,11 +432,18 @@ + - + - + + + + + + + diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/objects/ships/saucer1/object.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer1/object.xml Wed Mar 31 21:13:07 2010 +0000 @@ -0,0 +1,4 @@ + + + + diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/objects/ships/saucer1/saucer1.png Binary file demos/shooter/objects/ships/saucer1/saucer1.png has changed diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/objects/ships/saucer2/object.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/shooter/objects/ships/saucer2/object.xml Wed Mar 31 21:13:07 2010 +0000 @@ -0,0 +1,4 @@ + + + + diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/objects/ships/saucer2/saucer2.png Binary file demos/shooter/objects/ships/saucer2/saucer2.png has changed diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/scripts/scene.py --- a/demos/shooter/scripts/scene.py Wed Mar 31 15:40:00 2010 +0000 +++ b/demos/shooter/scripts/scene.py Wed Mar 31 21:13:07 2010 +0000 @@ -26,6 +26,9 @@ from scripts.ships.player import Player from scripts.common.helpers import Rect + + + class Scene(object): def __init__(self, engine, objectLayer): self._engine = engine @@ -47,14 +50,14 @@ timedelta = time - self._lasttime self._lasttime = time - self._player.update(timedelta, keystate, self._camera) - #update camera location - loc = self._player.location + loc = self._camera.getLocation() exactloc = self._camera.getLocation().getExactLayerCoordinates() - exactloc.x += timedelta * 0.0005 + exactloc.x += timedelta * 0.001 loc.setExactLayerCoordinates(exactloc) self._camera.setLocation(loc) + + self._player.update(timedelta, keystate, self._camera) #update the list of projectiles todelete = list() diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/scripts/ships/player.py --- a/demos/shooter/scripts/ships/player.py Wed Mar 31 15:40:00 2010 +0000 +++ b/demos/shooter/scripts/ships/player.py Wed Mar 31 21:13:07 2010 +0000 @@ -37,16 +37,16 @@ oldpos = self.location if keystate['UP']: - self.applyThrust(fife.DoublePoint(0,-0.075)) + self.applyThrust(fife.DoublePoint(0,-0.075), timedelta) key = True if keystate['DOWN']: - self.applyThrust(fife.DoublePoint(0,0.075)) + self.applyThrust(fife.DoublePoint(0,0.075), timedelta) key = True if keystate['LEFT']: - self.applyThrust(fife.DoublePoint(-0.075,0)) + self.applyThrust(fife.DoublePoint(-0.075,0), timedelta) key = True if keystate['RIGHT']: - self.applyThrust(fife.DoublePoint(0.075,0)) + self.applyThrust(fife.DoublePoint(0.075,0), timedelta) key = True if not key and self._velocity.length() > 0: @@ -59,29 +59,41 @@ topleft = camera.toMapCoordinates(fife.ScreenPoint(0,0)) bottomright = camera.toMapCoordinates(fife.ScreenPoint(1024,768)) - #add a little padding to the left edge - topleft.x += 0.1 - camrect = Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y) #player bounding box #TODO: make this configurable + xscale = self._layer.getCellGrid().getXScale() + yscale = self._layer.getCellGrid().getYScale() pos = self.location.getExactLayerCoordinates() bbox = Rect() - bbox.x = pos.x - 0.005 - bbox.y = pos.y - 0.005 - bbox.w = 0.01 - bbox.h = 0.01 + bbox.x = pos.x*xscale - 0.175 + bbox.y = pos.y*yscale - 0.175 + bbox.w = 0.25 + bbox.h = 0.25 + + #add the padding to the edge + camrect.x += bbox.w + camrect.y += bbox.h + camrect.w -= 2*bbox.w + camrect.h -= 2*bbox.h + if not bbox.intersects(camrect): - if pos.x < topleft.x: - pos.x += timedelta * 0.0005 - oldpos.setExactLayerCoordinates(pos) - self._velocity.x = timedelta * 0.0005 + if (bbox.x + bbox.w) < camrect.x: + #pos.x = (bbox.x + bbox.w/2 + 0.1) / xscale + #oldpos.setExactLayerCoordinates(pos) + self._velocity.x = (timedelta * 0.001) / xscale + +# 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 else: self._velocity.x = 0 + self._velocity.y = 0 - self._velocity.y = 0 + self.location = oldpos diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/scripts/ships/shipbase.py --- a/demos/shooter/scripts/ships/shipbase.py Wed Mar 31 15:40:00 2010 +0000 +++ b/demos/shooter/scripts/ships/shipbase.py Wed Mar 31 21:13:07 2010 +0000 @@ -21,6 +21,8 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # #################################################################### +from math import sqrt + from fife import fife from scripts.common.helpers import normalize from scripts.weapons import Weapon @@ -30,6 +32,9 @@ self._scene = scene self._name = shipName self._layer = layer + self._xscale = self._layer.getCellGrid().getXScale() + self._yscale = self._layer.getCellGrid().getYScale() + if uniqInMap: self._instance = self._layer.getInstance(self._name) else: @@ -38,7 +43,7 @@ #velocity as a vector self._velocity = fife.DoublePoint(0,0) - self._maxvelocity = 0.025 + self._maxvelocity = 0.025/sqrt(self._xscale * self._yscale) self._timedelta = 0 self._weapon = None @@ -46,7 +51,7 @@ return self._maxvelocity def _setMaxVelocity(self, maxvel): - self._maxvelocity = maxvel + self._maxvelocity = maxvel/sqrt(self._xscale * self._yscale) def _getLocation(self): return self._instance.getLocation() @@ -66,9 +71,9 @@ def _getWeapon(self, weapon): return self._weapon - def applyThrust(self, vector): - self._velocity.x += vector.x * (self._timedelta/1000.0) - self._velocity.y += vector.y * (self._timedelta/1000.0) + def applyThrust(self, vector, timedelta): + self._velocity.x += (vector.x * (timedelta/1000.0))/self._xscale + self._velocity.y += (vector.y * (timedelta/1000.0))/self._yscale if self._velocity.length() > self._maxvelocity: norm = normalize(self._velocity) @@ -98,8 +103,8 @@ norm.x *= brakingForce norm.y *= brakingForce - self._velocity.x += norm.x * (self._timedelta/1000.0) - self._velocity.y += norm.y * (self._timedelta/1000.0) + self._velocity.x += (norm.x * (self._timedelta/1000.0))/self._xscale + self._velocity.y += (norm.y * (self._timedelta/1000.0))/self._yscale def fire(self, curtime): if self._weapon: diff -r 2046a1f2f5f2 -r 64676ea55472 demos/shooter/scripts/weapons.py --- a/demos/shooter/scripts/weapons.py Wed Mar 31 15:40:00 2010 +0000 +++ b/demos/shooter/scripts/weapons.py Wed Mar 31 21:13:07 2010 +0000 @@ -35,6 +35,9 @@ self._ttl = timeToLive self._starttime = 0 + self._xscale = self._layer.getCellGrid().getXScale() + self._yscale = self._layer.getCellGrid().getYScale() + def create(self, location): self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") fife.InstanceVisual.create(self._instance) @@ -42,6 +45,8 @@ def run(self, velocity, location, time): if not self._running: self._velocity = velocity + self._velocity.x /= self._xscale + self._velocity.y /= self._yscale self.create(location) self._running = True @@ -89,11 +94,12 @@ self._ship = ship self._firerate = firerate self._lastfired = 0 + self._projectileVelocity = fife.DoublePoint(0.075,0) def fire(self, curtime): if (curtime - self._lastfired) > self._firerate: pjctl = Projectile(self._model, "bullet1", self._layer, 2000 ) - pjctl.run(fife.DoublePoint(0.075,0), self._ship.location, curtime) + pjctl.run(fife.DoublePoint(self._projectileVelocity.x,self._projectileVelocity.y), self._ship.location, curtime) self._lastfired = curtime return pjctl