예제 #1
0
 def attached(self):
     self.node.set_pos(self.pos)
     self.node.set_hpr(self.hpr)
     self.world.register_updater(self)
     self.world.register_collider(self)
     self.solid.setIntoCollideMask(NO_COLLISION_BITS)
     self.sound = self.world.audio3d.loadSfx('Sounds/plasma.wav')
     self.sound.set_balance(0)
     self.world. audio3d.attachSoundToObject(self.sound, self.node)
     self.sound.set_loop(True)
     self.sound.play()
     self.integrator = Integrator(self.world.render.get_relative_vector(self.node, Vec3(0,0,30)))
예제 #2
0
 def attached(self):
     self.node.set_pos(self.pos)
     self.node.set_hpr(self.hpr)
     self.world.register_updater(self)
     self.world.register_collider(self)
     self.solid.setIntoCollideMask(NO_COLLISION_BITS)
     self.sound = self.world.audio3d.loadSfx('Sounds/plasma.wav')
     self.sound.set_balance(0)
     self.world. audio3d.attachSoundToObject(self.sound, self.node)
     self.sound.set_loop(True)
     self.sound.play()
     self.integrator = Integrator(self.world.scene.get_relative_vector(self.node, Vec3(0,0,30)))
예제 #3
0
class Missile (Projectile):
    def __init__(self, pos, hpr, color, name=None):
        super(Missile, self).__init__(name)
        self.pos = Vec3(*pos)
        self.hpr = hpr
        self.age = 0
        self.color = color
        self.velocity = Vec3(0,0,0)

    def create_node(self):
        self.model = load_model('missile.egg')
        self.body = self.model.find('**/bodywings')
        self.body.set_color(*self.color)
        self.main_engines = self.model.find('**/mainengines')
        self.wing_engines = self.model.find('**/wingengines')
        self.main_engines.set_color(*random.choice(ENGINE_COLORS))
        self.wing_engines.set_color(*random.choice(ENGINE_COLORS))
        self.model.set_scale(MISSILE_SCALE)
        self.model.set_hpr(0,0,0)
        return self.model

    def create_solid(self):
        node = BulletGhostNode(self.name)
        node_shape = BulletSphereShape(.08)
        node.add_shape(node_shape)
        node.set_kinematic(True)
        return node

    def attached(self):
        self.node.set_pos(self.pos)
        self.node.set_hpr(self.hpr)
        self.world.register_updater(self)
        self.world.register_collider(self)
        self.solid.setIntoCollideMask(NO_COLLISION_BITS)
        self.sound = self.world.audio3d.loadSfx('Sounds/plasma.wav')
        self.sound.set_balance(0)
        self.world. audio3d.attachSoundToObject(self.sound, self.node)
        self.sound.set_loop(True)
        self.sound.play()
        self.integrator = Integrator(self.world.scene.get_relative_vector(self.node, Vec3(0,0,30)))

    def decompose(self):
        clist = list(self.color)
        clist.extend([1])
        expl_colors = [clist]
        expl_colors.extend(ENGINE_COLORS)
        expl_pos = self.node.get_pos(self.world.scene)
        for c in expl_colors:
            self.world.attach(TriangleExplosion(expl_pos, 1, size=.1, color=c, lifetime=40))
        self._remove_all()

    def update(self, dt):
        current_pos = Point3(0, self.position().get_y(), 0)
        pos, self.velocity = self.integrator.integrate(self.node.get_pos(), self.velocity, dt)
        if self.velocity.length() > 30:
            self.integrator.accel = Vec3(0,0,0)
        else:
            self.integrator.accel = self.world.scene.get_relative_vector(self.node, Vec3(0,0,30))
        self.move(self.position() + (pos - self.node.get_pos()))

        self.main_engines.set_color(*random.choice(ENGINE_COLORS))
        self.wing_engines.set_color(*random.choice(ENGINE_COLORS))
        result = self.world.physics.contact_test(self.solid)
        self.age += dt
        if len(result.getContacts()) > 0:
            clist = list(self.color)
            clist.extend([1])
            expl_colors = [clist]
            expl_colors.extend(ENGINE_COLORS)
            expl_pos = self.node.get_pos(self.world.scene)
            for c in expl_colors:
                self.world.attach(TriangleExplosion(expl_pos, 3, size=.1, color=c, lifetime=80))
            self.world.do_explosion(self.node, 1.5, 30)
            self._remove_all()

        if self.age > MISSILE_LIFESPAN:
            self._remove_all()

    def _remove_all(self):
        self.sound.stop()
        self.world.audio3d.detachSound(self.sound)
        self.world.garbage.add(self)
예제 #4
0
class Missile (Projectile):
    def __init__(self, pos, hpr, color, name=None):
        super(Missile, self).__init__(name)
        self.pos = Vec3(*pos)
        self.hpr = hpr
        self.age = 0
        self.color = color
        self.velocity = Vec3(0,0,0)

    def create_node(self):
        self.model = load_model('missile.egg')
        self.body = self.model.find('**/bodywings')
        self.body.set_color(*self.color)
        self.main_engines = self.model.find('**/mainengines')
        self.wing_engines = self.model.find('**/wingengines')
        self.main_engines.set_color(*random.choice(ENGINE_COLORS))
        self.wing_engines.set_color(*random.choice(ENGINE_COLORS))
        self.model.set_scale(MISSILE_SCALE)
        self.model.set_hpr(0,0,0)
        return self.model

    def create_solid(self):
        node = BulletGhostNode(self.name)
        node_shape = BulletSphereShape(.08)
        node.add_shape(node_shape)
        node.set_kinematic(True)
        return node

    def attached(self):
        self.node.set_pos(self.pos)
        self.node.set_hpr(self.hpr)
        self.world.register_updater(self)
        self.world.register_collider(self)
        self.solid.setIntoCollideMask(NO_COLLISION_BITS)
        self.sound = self.world.audio3d.loadSfx('Sounds/plasma.wav')
        self.sound.set_balance(0)
        self.world. audio3d.attachSoundToObject(self.sound, self.node)
        self.sound.set_loop(True)
        self.sound.play()
        self.integrator = Integrator(self.world.render.get_relative_vector(self.node, Vec3(0,0,30)))

    def decompose(self):
        clist = list(self.color)
        clist.extend([1])
        expl_colors = [clist]
        expl_colors.extend(ENGINE_COLORS)
        expl_pos = self.node.get_pos(self.world.render)
        for c in expl_colors:
            self.world.attach(TriangleExplosion(expl_pos, 1, size=.1, color=c, lifetime=40))
        self._remove_all()

    def update(self, dt):
        current_pos = Point3(0, self.position().get_y(), 0)
        pos, self.velocity = self.integrator.integrate(self.node.get_pos(), self.velocity, dt)
        if self.velocity.length() > 30:
            self.integrator.accel = Vec3(0,0,0)
        else:
            self.integrator.accel = self.world.render.get_relative_vector(self.node, Vec3(0,0,30))
        self.move(self.position() + (pos - self.node.get_pos()))

        self.main_engines.set_color(*random.choice(ENGINE_COLORS))
        self.wing_engines.set_color(*random.choice(ENGINE_COLORS))
        result = self.world.physics.contact_test(self.solid)
        self.age += dt
        if len(result.getContacts()) > 0:
            clist = list(self.color)
            clist.extend([1])
            expl_colors = [clist]
            expl_colors.extend(ENGINE_COLORS)
            expl_pos = self.node.get_pos(self.world.render)
            for c in expl_colors:
                self.world.attach(TriangleExplosion(expl_pos, 3, size=.1, color=c, lifetime=80))
            self.world.do_explosion(self.node, 1.5, 30)
            self._remove_all()

        if self.age > MISSILE_LIFESPAN:
            self._remove_all()

    def _remove_all(self):
        self.sound.stop()
        self.world.audio3d.detachSound(self.sound)
        self.world.garbage.add(self)