comparison demos/shooter/scripts/weapons.py @ 447:64676ea55472

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.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 31 Mar 2010 21:13:07 +0000
parents 2046a1f2f5f2
children 5e2ec84902a7
comparison
equal deleted inserted replaced
446:2046a1f2f5f2 447:64676ea55472
33 self._obj = self._model.getObject(self._name, "http://www.fifengine.de/xml/tutorial") 33 self._obj = self._model.getObject(self._name, "http://www.fifengine.de/xml/tutorial")
34 self._running = False 34 self._running = False
35 self._ttl = timeToLive 35 self._ttl = timeToLive
36 self._starttime = 0 36 self._starttime = 0
37 37
38 self._xscale = self._layer.getCellGrid().getXScale()
39 self._yscale = self._layer.getCellGrid().getYScale()
40
38 def create(self, location): 41 def create(self, location):
39 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet") 42 self._instance = self._layer.createInstance(self._obj, location.getExactLayerCoordinates(), "bullet")
40 fife.InstanceVisual.create(self._instance) 43 fife.InstanceVisual.create(self._instance)
41 44
42 def run(self, velocity, location, time): 45 def run(self, velocity, location, time):
43 if not self._running: 46 if not self._running:
44 self._velocity = velocity 47 self._velocity = velocity
48 self._velocity.x /= self._xscale
49 self._velocity.y /= self._yscale
45 50
46 self.create(location) 51 self.create(location)
47 self._running = True 52 self._running = True
48 53
49 self._starttime = time 54 self._starttime = time
87 self._model = model 92 self._model = model
88 self._layer = layer 93 self._layer = layer
89 self._ship = ship 94 self._ship = ship
90 self._firerate = firerate 95 self._firerate = firerate
91 self._lastfired = 0 96 self._lastfired = 0
97 self._projectileVelocity = fife.DoublePoint(0.075,0)
92 98
93 def fire(self, curtime): 99 def fire(self, curtime):
94 if (curtime - self._lastfired) > self._firerate: 100 if (curtime - self._lastfired) > self._firerate:
95 pjctl = Projectile(self._model, "bullet1", self._layer, 2000 ) 101 pjctl = Projectile(self._model, "bullet1", self._layer, 2000 )
96 pjctl.run(fife.DoublePoint(0.075,0), self._ship.location, curtime) 102 pjctl.run(fife.DoublePoint(self._projectileVelocity.x,self._projectileVelocity.y), self._ship.location, curtime)
97 self._lastfired = curtime 103 self._lastfired = curtime
98 return pjctl 104 return pjctl
99 105
100 return None 106 return None
101 107