def __init__(self, x, y): super(self.__class__, self).__init__(GameAssets.Instance().getImage('explosion'), x, y) #super(self.__class__, self).__init__(GameAssets.Instance().getImage('dbg2'), x, y) th = 360*random.random() u,v = vec.uvec(th) self.alive = True self.timeAlive = 0.0 self.angle = tv.LinearMotion(0,120)
def thrust(self, dt, throttle): # We assume that at self.angle == 0, the forward direction # is x = 0, y = +1, and that +ive rotation is clock-wise # Throttle is from 0.0 to 1.0 (well, I guess I'm allowing negative tto) #ux, uy = vec.uvec(self.angle) if throttle != 0.0: ux, uy = vec.uvec(self.angleVar.value) ds = throttle * self.maxThrustPower * dt self.motion.thrust( ds * ux, ds * uy) self.currThrottle = throttle
def getTipParams(self): ''' Return postion of tip and forward direction (as angle)''' x,y = self.motion.position() th = self.angleVar.value #fwd = self.angle - 90.0 ux, uy = vec.uvec(th) #tipOffset = gAssets.shipTipAboveCenter x,y = x + self.tipOffset*ux, y + self.tipOffset*uy return ((x,y), th-90.0)
def spawnNew(self, shipPosition, viewportOrigin): # This is very stochastic. It tries to create a new meteor, # but if it doesn't on this go-around is just returns, as it will # be called again fairly soon. #targetN = 15 targetN = int(self.meteorCountCurve(self.gameTime)) if len(self.meteors) >= targetN: return #print "Have", len(self.meteors), "meteors, want", targetN w = self.props.windowWidth h = self.props.windowHeight x = None y = None offset = 250 side = random.randint(0,3) # side selects (left, right, bottom, top) sides = ('left', 'right', 'bottom', 'top') # for debugging if side < 2: # left or right y = viewportOrigin[1] + random.randrange(h) if side == 0: x = viewportOrigin[0] - offset else: x = viewportOrigin[0] + w + offset else: # top or bottom x = viewportOrigin[0] + random.randrange(w) if side == 2: y = viewportOrigin[1] - offset else: y = viewportOrigin[1] + h + offset # Make sure it's within the meteor field if x < -w or y < -h or x > 2*w or y > 2*h: return speedBase = self.meteorSpeedCurve(self.gameTime) speed = random.gauss(speedBase, 30) name = random.choice(self.meteorPool) th = 360*random.random() u,v = vec.uvec(th) m = MeteorSprite(name, (x, y), (speed*u, speed*v), self.meteorBatch, self.props) self.meteors.append(m)
def addMeteorsXXX(self, n, shipPosition): return w = self.props.windowWidth h = self.props.windowHeight for _ in range(0,n): # Meteors bounce around in a 3w x 3h block # Spawn new meteor on "opposite side of the torus" # This is not good!!! XXX speed = random.gauss(100, 30) x = tv.wrap(shipPosition[0] + 1.5*w, -w, 2*w) y = tv.wrap(shipPosition[1] + 1.5*h, -h, 2*h) th = 360*random.random() u,v = vec.uvec(th) m = MeteorSprite("foo", (x, y), (speed*u, speed*v), self.meteorBatch, self.props) self.meteors.append(m)
def initialMeteors(self, n, shipPosition): w = self.props.windowWidth h = self.props.windowHeight for i in range(0,n): x = random.uniform(-w, 2*w) y = random.uniform(-h, 2*h) dx, dy = (x - shipPosition[0]), (y - shipPosition[1]) if dx*dx + dy*dy < 150*150: # Don't start off right next to a meteor # And it's okay if we don't get exactly n created here. continue speed = random.gauss(100, 30) name = random.choice(self.meteorPool) th = 360*random.random() u,v = vec.uvec(th) m = MeteorSprite(name, (x, y), (speed*u, speed*v), self.meteorBatch, self.props) self.meteors.append(m)
def get(self): # Sigh. Gotta set some standards w.r.t. angles return vec.Vector(self.x, self.y), vec.Vector(*vec.uvec(self.rotation+90.))