def addText(self, pos, text): f = self._current_font t = (text,f,self._color,self._aa) surf = f.render(text, self._aa, self._color) txt_id = self._sprite_manager.newSprite(surf, 1.0, T.translation_matrix((pos[0],pos[1],0))) self._texts[txt_id] = [text, f, self._aa, self._color] return txt_id
def moveTo(self, pos): gx = int(pos[0]/16) gy = int(pos[1]/16) if gx != self._grid_x or gy != self._grid_y: self._grid_x = gx self._grid_y = gy try: self._grid[self._grid_cell].remove(self) except: pass self._grid_cell = gc = (gx,gy) try: self._grid[gc].add(self) except: self._grid[gc]={self} self._pos[:] = pos self._pos_m = T.translation_matrix(pos)
def moveText(self, txt_id, pos): self._sprite_manager.setSpriteTransform(txt_id, T.translation_matrix((pos[0],pos[1],0)))
def __init__(self, scene, pos, direction, missile_type, follow): Entity.__init__(self) self._t0 = None self._follow = follow self._scene = scene self._map = scene.getMap() self.moveTo(pos) self._thrust = 0.01 self._speed = 0.1 self._destroyed = False self._graphics = R.loadObject(missile_type+".obj","diffuse") self._pos_m = T.translation_matrix(pos) axis = T.random_vector(3) self._d_rotation = T.quaternion_about_axis(0.01, axis) self._rotation = T.random_quaternion() self._dir = direction scale = 0.05 self._scaling_m = T.scale_matrix(scale) bounds = self._graphics.getObj().getBounds() * scale Entity.setBounds(self,bounds) self._trail= ParticleGenerator("billboard","puff.jpg") self._trail.setEvolveTime(0.5) self._trail.setAcceleration(0) self._trail.setEasing(0.5, 0.5, 0.0, 0.05, 0.2) self._trail.setBrightness(0.5) pg = scene.getParticleManager() def em(t): while True: dx = 2.*random.random()-1. dy = 2.*random.random()-1. dz = 2.*random.random()-1. r = dx*dx+dy*dy+dz*dz if r < 1.0: break return self._pos,(dx*0.2,dy*0.2,dz*0.2) self._trail.setEmitter(em) self._trail.setMode("DYNAMIC") pg.manageGenerator(self._trail) self._last_z = 0