Beispiel #1
0
 def build_sounds(self):
     self.click_sound = Sound("sounds/click.wav", copies=2, intensity=0.5)
     self.ping_sound = Sound("sounds/ping.wav", copies=2, intensity=0.5)
     self.switch_sound = Sound("sounds/switch.wav", copies=2, intensity=0.5)
     self.bongo_sound = Sound("sounds/bongo.wav", copies=2, intensity=0.5)
     self.music_sound = Sound("sounds/fast_music.ogg",
                              intensity=0.4,
                              loop=True)
Beispiel #2
0
    def build_world(self):
        # Labels
        #space.nodes["Text_Message"].string = [_("Touch all targets in order, man.")]

        # Sounds
        self.pop_sound = Sound("sounds/pop.wav", copies=3, intensity=0.5)

        # Gather target materials
        self.default_target_material = space.nodes["Material_DefaultTarget"]
        self.next_target_material = space.nodes["Material_NextTarget"]

        self.target_infos = []

        for i in range(NUMBER_OF_TARGETS):
            target = X3DFileNode("target.hgt")
            self.add_child(target)

            # Position the target according to the corresponding
            # empty in the scene.
            transform = target.find("Transform_TargetEmpty")
            empty_transform = space.nodes["Transform_BubbleEmpty.%03d" % i]
            transform.translation = empty_transform.translation

            appearance = target.find("Appearance_TargetHaptic")
            toggle = target.find("ToggleGroup_TargetHaptic")

            if i == 0:
                appearance.material = self.next_target_material.h3dNode
                #toggle.graphicsOn = True
                toggle.hapticsOn = True
            else:
                appearance.material = self.default_target_material.h3dNode
                #toggle.graphicsOn = False
                toggle.hapticsOn = False


            # Create target info
            target_info = {
                'target_id': i,
                'appearance': appearance,
                'done': False,
                'original_position': transform.translation,
                'toggle': toggle,
            }

            self.target_infos.append(target_info)

            # Bind touch
            evt = Event()
            evt.target_info = target_info

            bl = MFBoolListener(
                onTrue=self.touch_target,
                callbackObject=evt
            )

            target.find("Mesh_TargetHaptic").h3dNode.isTouched.routeNoEvent(bl)
Beispiel #3
0
 def build_sounds(self):
     self.whizz_sound = Sound(url="sounds/whizz.wav", intensity=1.0)
     self.impact_sound = Sound(url="sounds/impact.wav", intensity=1.0)
     self.squeak_sound = Sound(url="sounds/squeak.wav", intensity=0.5)
     self.ping_sound = Sound(url="sounds/ping.wav", intensity=0.5)
     self.cheers_sound = Sound(url="sounds/cheers.wav", copies=2, intensity=0.5)
     self.fairy_sound = Sound(url="sounds/fairy.wav", intensity=0.5)
     #self.forest_sound = Sound(url="sounds/forest.ogg", intensity=1.0)
     if self.level < 3:
         self.music_sound = Sound(url="sounds/william1.ogg", intensity=0.5, loop=True)
     else:
         self.music_sound = Sound(url="sounds/william2.ogg", intensity=0.5, loop=True)
Beispiel #4
0
 def build_sounds(self):
     self.mug_sound = Sound("sounds/glass1.wav", copies=2, intensity=0.4)
     self.mugmug_sound = Sound("sounds/glass3.wav", copies=2, intensity=0.4)
     self.plate_sound = Sound("sounds/glass2.wav", copies=2, intensity=0.4)
     self.knock_sound = Sound("sounds/knock.wav", copies=5, intensity=0.4)
     self.ping_sound = Sound("sounds/ping.wav", copies=2, intensity=0.4)
     self.cheer_sound = Sound("sounds/cheer.wav", copies=1, intensity=0.5)
Beispiel #5
0
 def build_sounds(self):
     self.bell_sound = Sound("sounds/bell.wav", intensity=0.3, copies=2)
     self.chalktap_sounds = [
         Sound("sounds/chalktap1.wav", intensity=1.0, copies=2),
         Sound("sounds/chalktap2.wav", intensity=1.0, copies=2),
     ]
     self.eraser_sounds = [
         Sound("sounds/eraser1.wav", intensity=0.5, copies=2),
         Sound("sounds/eraser2.wav", intensity=0.5, copies=2),
         Sound("sounds/eraser3.wav", intensity=0.5, copies=2),
     ]
     self.music_sound = Sound("sounds/music.ogg", intensity=0.3, loop=True)
Beispiel #6
0
    def build_sounds(self):
        self.splash_sound = Sound("sounds/splash.wav", copies=5, intensity=0.2)
        self.buzz_sound = Sound("sounds/buzz.wav", copies=5, intensity=0.2)
        self.whoosh_sound = Sound("sounds/whoosh.wav", copies=5, intensity=0.1)
        self.ping_sound = Sound("sounds/ping.wav", copies=5, intensity=0.2)
        self.glass_sound = Sound("sounds/glasstap.wav", copies=5, intensity=0.25)
        self.music_sound = Sound("sounds/music.ogg", copies=5, intensity=0.25, loop=True)

        # Add sound nodes to scenegraph
        for s in [
            self.splash_sound.node,
            self.buzz_sound.node,
            self.whoosh_sound.node,
            self.ping_sound.node,
            self.glass_sound.node,
            self.music_sound.node,
        ]:
            self.add_child(s)
Beispiel #7
0
    def build_world(self):
        # Labels
        space.nodes["Text_Message"].string = [_("Touch all targets in order (1-2-3 ...)")]

        # Sounds
        self.correct_sound = Sound("sounds/correct.wav", copies=3, intensity=0.5)
        self.wrong_sound = Sound("sounds/wrong.wav", copies=3, intensity=0.5)

        # Gather target materials
        self.default_target_material = space.nodes["Material_DefaultTarget"]
        self.correct_target_material = space.nodes["Material_CorrectTarget"]
        self.wrong_target_material = space.nodes["Material_WrongTarget"]

        self.target_infos = []

        for i in range(NUMBER_OF_TARGETS):
            target = X3DFileNode("target.hgt")
            self.add_child(target)

            # Make the haptic part invisible
            target.find("ToggleGroup_TargetHaptic").graphicsOn = False

            # Set the label
            if ALPHANUMERIC_SEQUENCE:
                if i % 2 == 0:
                    label = str((i / 2) + 1)
                else:
                    label = chr(ord('A') + (i / 2))
            else:
                label = str(i + 1)
            target.find("Text_TargetLabel").string = [label]

            # Set outline appearance to default color (black)
            appearance = target.find("Appearance_TargetOutline")
            appearance.material = self.default_target_material.h3dNode

            # Position the target according to the corresponding
            # empty in the scene.
            transform = target.find("Transform_TargetEmpty")
            empty_transform = space.nodes["Transform_CircleEmpty.%03d" % i]
            transform.translation = empty_transform.translation

            # Create target info
            target_info = {
                'appearance': appearance,
                'done': False,
                'original_position': transform.translation,
                'target_id': i,
                'touched_this_round': False,
            }

            self.target_infos.append(target_info)

            # Bind touch
            evt = Event()
            evt.target_info = target_info

            bl = MFBoolListener(
                onTrue=self.touch_target,
                callbackObject=evt
            )

            target.find("Mesh_TargetHaptic").h3dNode.isTouched.routeNoEvent(bl)
Beispiel #8
0
 def build_sounds(self):
     self.ambience_sound = Sound("sounds/ambience.ogg",
                                 intensity=0.4,
                                 loop=True)
     self.coin_insert_sound = Sound("sounds/coininsert.wav", intensity=0.5)
     self.coin_sound = Sound("sounds/coin.wav", intensity=0.5)
     self.ping_sound = Sound("sounds/ping.wav", intensity=0.5)
     self.button_down_sound = Sound("sounds/click.wav")
     self.button_up_sound = Sound("sounds/click.wav", intensity=0.3)
     self.spinstop_sound = Sound("sounds/spinstop.wav", intensity=0.5)
     self.spinstart_sound = Sound("sounds/spinstart.wav", intensity=0.5)
     self.blip_sound = Sound("sounds/blip.wav", intensity=0.5, copies=4)
     self.plunger_sound = Sound("sounds/plunger.wav", intensity=0.5)
     self.coindrop_sound = Sound("sounds/coindrop.wav", intensity=0.5)
Beispiel #9
0
 def build_sounds(self):
     self.click_sound = Sound("../../../media/sounds/click.wav",
                              copies=3,
                              intensity=0.3)
Beispiel #10
0
    def build_world(self):
        # Labels
        # FIXME: blender exporter bug requires fixing before the label names can
        # be changed to something more appropriate.
        space.nodes["Text_LengthLabel.001"].string = [_("Listen")]
        space.nodes["Text_LengthLabel.002"].string = [_("Repeat")]

        # Hide all buttons
        for i in range(TOTAL_NUMBER_OF_BUTTONS):
            t = space.nodes["ToggleGroup_Button.%03d" % (i + 1)]
            t.hapticsOn = False
            t.graphicsOn = False

        self.buttons = []
        for id in self.level_button_ids:
            # Make button visible again
            t = space.nodes["ToggleGroup_Button.%03d" % (id)]
            t.hapticsOn = True
            t.graphicsOn = True

            button = {
                "mesh":
                space.nodes["Mesh_Button.%03d" % (id)],
                "transformInfo":
                space.nodes["TransformInfo_Button.%03d" % (id)],
                "transform":
                space.nodes["Transform_Button.%03d" % (id)],
                "material":
                space.nodes["Material_Button.%03d" % (id)],
                "sound":
                Sound(url="sounds/instrument/%s.wav" %
                      self.level_sounds.pop(0),
                      copies=3,
                      intensity=0.5),
            }
            self.buttons.append(button)

            e = Event()
            e.button = button

            pushButton = PushButton(
                transformNode=button["transform"].h3dNode,
                geometry=button["mesh"].h3dNode,
                onPress=self.press_button,
                onRelease=self.release_button,
                displacement=Vec3f(0, 0.01, 0),
                hitForce=1.5,
                event=e,
            )

        # The reward
        self.cup_toggle = space.nodes["ToggleGroup_Cup"]
        self.cup_transform = space.nodes["Transform_Cup"]
        self.cup_dynamic_transform = space.nodes["DynamicTransform_Cup"]
        #self.cup_dynamic_transform.angularMomentum = Vec3f(0, 0, 0.5)
        self.cup_toggle.graphicsOn = False
        self.cup_toggle.hapticsOn = False

        # Build sounds
        self.click_sound = Sound(url="sounds/click.wav",
                                 copies=2,
                                 intensity=0.2)
        self.switch_sound = Sound(url="sounds/switch.wav",
                                  copies=2,
                                  intensity=0.2)
        self.error_sound = Sound(url="sounds/error.wav",
                                 copies=2,
                                 intensity=0.2)
        self.fanfare_sound = Sound(url="sounds/fanfare.wav",
                                   copies=2,
                                   intensity=0.2)
        self.ping_sound = Sound(url="sounds/ping.wav", copies=2, intensity=0.2)
        self.fairy_sound = Sound(url="sounds/fairy.wav",
                                 copies=2,
                                 intensity=0.2)

        # Lights
        self.button_glow_lamp = space.nodes["PointLight_ButtonGlow"]

        # Texts
        self.sequence_length_text = space.nodes["Text_LengthLabel"]
        self.sequence_length_text.string = []
        self.large_text = space.nodes["Text_LargeLabel"]
        self.large_text.string = []
        self.medium_text = space.nodes["Text_MediumLabel"]
        self.medium_text.string = []

        # Leds
        self.led_materials = []
        for i in range(2):
            m = space.nodes["Material_LED%d" % (i + 1)]
            self.led_materials.append(m)
        self.leds_off()
Beispiel #11
0
class Game(hgt.game.Game):
    def build(self):
        random.seed()

        cfg = self.load_config()

        # Setup hgt world
        hgt.world.tilt(-SPACE_TILT)
        hgt.world.stereoInfo.focalDistance = 0.50
        hgt.world.load_stylus('ball')
        #hgt.world.load_stylus('spoon')

        # Load Blender scene
        self.add_child(space.world)

        # Force field used to simulate drag/gravity for grabbable objects
        self.forceField = hgn.ForceField()
        self.add_child(self.forceField)

        # Matrix used to compensate for TILT
        self.tiltMatrix = Rotation(1, 0, 0, SPACE_TILT * DEG2RAD)

        self.grabManager = GrabManager(self, self.tiltMatrix)

        self.build_environment()
        self.build_sounds()

        # Add apples in scene as grabbable objects
        for i in [("Apple", 0.3), ("Strawberry", 0.1), ("Melon", 1.0), ("Orange", 0.3)]:
            thing = GrabObject(self.grabManager, space.nodes, name = i[0], mass = i[1])

    def start(self):
        space.nodes["Text_UserMessage"].string = [_("Touch everything.")]
        space.nodes["Text_UserMessage2"].string = [_("Press exit sign when done.")]
        self.startTime = hgt.time.now

    def update(self):
        #print self.tiltMatrix * hgt.haptics.trackerPosition
        self.grabManager.update()
        self.update_trail()
        self.update_earth()
        self.update_guide_arrow()
        self.update_fish()

    def update_guide_arrow(self):
        # Bob the arrow up and down if it's visible
        if self.guideToggle.graphicsOn:
            v = Vec3f(0, 0, 0.005 * math.cos(hgt.time.now * 3))
            self.guideArrow.translation = v

    def update_fish(self):
        o = self.fishTransform.orientation
        m = o * (0.005 * Vec3f(-1, 0, 0))
        self.fishTransform.momentum = m

    def update_earth(self):
        f = hgt.haptics.deviceForce
        if self.touchingEarth:
            # This is just plain wrong, you can only spin the earth in one direction...
            self.earthSpinner.torque = f
        else:
            self.earthSpinner.torque = Vec3f(0, 0, 0)

        # Simulate friction
        self.earthSpinner.angularMomentum = 0.995 * Vec3f(0, 0, self.earthSpinner.angularMomentum.z)

    def update_trail(self):
        # Todo: see if we can add the trail to the topmost (untilted) node to
        # remove the need for tilt compensation
        tp = self.tiltMatrix * hgt.haptics.proxyPosition
        self.trailParticleEmitter.position = tp
        #self.particleTrail.translation = tp
        #self.stylusLight.location = tp

    def clear_user_message(self):
        space.nodes["Text_UserMessage"].string = [" "]
        space.nodes["Text_UserMessage2"].string = [" "]

    def build_environment(self):
        # Spinning earth
        self.earthSpinner = hgn.DynamicTransform(
            angularMomentum = Vec3f(0, 0, 0)
        )
        space.nodes["Transform_EarthSea"].reparent_children_to(self.earthSpinner)

        bl = MFBoolListener(
            onTrue = self.touch_earth,
            onFalse = self.untouch_earth,
        )
        space.nodes["Mesh_EarthSea"].h3dNode.isTouched.routeNoEvent(bl)

        self.touchingEarth = False

        # Touchable fruit plate bottom, coupled to release of grabbed objects
        bl = MFBoolListener(
            onTrue = self.grabManager.release,
        )
        space.nodes["Mesh_GrabReleaseSensor"].h3dNode.isTouched.routeNoEvent(bl)

        # Bobbing guide arrow
        self.guideArrow = hgn.Transform()
        self.guideToggle = hgn.ToggleGroup(graphicsOn = False)
        self.guideArrowPos = space.nodes["Transform_GuideArrow"]
        self.guideArrowPos.reparent_children_to(self.guideArrow)
        self.guideArrowPos.reparent_children_to(self.guideToggle)

        # A light that follows the stylus
        """
        self.stylusLight = hgn.PointLight(
            intensity = 0.1,
            attenuation = Vec3f(0, 10, 50),
        )
        self.add_child(self.stylusLight)
        """

        # An unreachable fish swimming in the aquarium
        self.fishTransform = hgn.DynamicTransform(
            position = Vec3f(0, 0.24, 0),
            angularMomentum = Vec3f(0, 0, 0.075),
        )
        fish = X3DFileNode("fish.x3d")
        self.fishTransform.add(fish)
        self.add_child(self.fishTransform)

        # A button that toggles the "aquarium light" on/off. Really controls
        # the aquarium glass transparency.
        button = space.nodes["Transform_LightButton"]
        buttonMesh = space.nodes["Mesh_LightButton"]
        b = PushButton(
            transformNode = button.h3dNode,
            geometry = buttonMesh.h3dNode,
            onPress = self.press_aquarium_button,
            displacement = Vec3f(0, 0.0025, 0),
            hitForce = 1.0,
        )
        space.nodes["ToggleGroup_AquariumGlassEmpty"].graphicsOn = False
        self.aquariumLightOn = False

        self.aquariumLamp = space.nodes["PointLight_AquariumLamp"]
        self.exitLamp = space.nodes["PointLight_ExitLamp"]

        # Tapping on aquarium glass
        bl = MFBoolListener(
            callbackObject = None,
            onTrue = self.tap_glass,
        )
        space.nodes["Mesh_AquariumGlass"].h3dNode.isTouched.routeNoEvent(bl)

        # Something that when touched initiates the exit procedure
        bl = MFBoolListener(
            callbackObject = None,
            onTrue = self.initiate_exit,
        )
        space.nodes["Mesh_ExitSign"].h3dNode.isTouched.routeNoEvent(bl)
        self.exitSignMaterial = space.nodes["Material_ExitSign"]
        self.exiting = False
        self.readyToQuit = False

        # Particle systems

        # Device trail
        p = X3DFileNode("trail_particles.x3d")
        self.trailParticleEmitter = p.find("EMITTER")
        self.add_child(p)

        # Aquarium bubbles
        #p = X3DFileNode("bubble_particles.x3d")
        #self.add_child(p)
        #self.bubbleParticleSystem = p.find("PARTICLE_SYSTEM")
        #self.bubbleParticleSystem.createParticles = False

    def build_sounds(self):
        self.lightOnSound = Sound("sounds/light_on.wav", intensity = 1.0, copies = 2)
        self.lightOffSound = Sound("sounds/light_off.wav", intensity = 1.0, copies = 2)
        self.melonDropSound = Sound("sounds/melon_drop.wav", intensity = 1.0)
        self.glassTapSound = Sound("sounds/glass_tap.wav", intensity = 0.25, copies = 4)
        self.exitSwitchSound = Sound("sounds/exit_switch.wav", intensity = 0.5, copies = 3)
        self.squeakSound = Sound("sounds/squeak.wav", intensity = 0.5)

    def press_aquarium_button(self, event):
        self.clear_user_message()

        if self.aquariumLightOn:
            self.lightOffSound.play()
            self.aquariumLamp.intensity = 0.0
            #self.bubbleParticleSystem.createParticles = False
        else:
            self.lightOnSound.play()
            self.aquariumLamp.intensity = 0.3
            #self.bubbleParticleSystem.createParticles = True
        self.aquariumLightOn = not self.aquariumLightOn

    def touch_earth(self):
        self.clear_user_message()

        space.nodes["Text_UserMessage"].string = []

        self.touchingEarth = True

        # "The Earth only squeaks when it's not spinning"
        # -Fantomen
        az = self.earthSpinner.angularMomentum.z
        l = 0.08
        if az > -l and az < l:
            self.squeakSound.play(location = hgt.haptics.trackerPosition)

    def untouch_earth(self):
        self.touchingEarth = False

    def tap_glass(self):
        self.clear_user_message()

        self.glassTapSound.play(location = hgt.haptics.trackerPosition)

    def initiate_exit(self):
        self.clear_user_message()

        if not self.exiting:
            self.exitSignMaterial.emissiveColor = RGB(1, 1, 1)
            self.exitLamp.intensity = 0.25
            self.exitSwitchSound.play(location = hgt.haptics.trackerPosition)
            self.exiting = True
            self.exitTimeout = hgt.time.add_timeout(EXIT_TIME, self.check_exit)

    def check_exit(self):
        if self.exiting == True:
            space.nodes["PointLight_LeftLamp"].intensity = 0.2
            space.nodes["PointLight_RightLamp"].intensity = 0.2

            self.lightOffSound.play()
            self.aquariumLamp.intensity = 0.0

            hgt.time.add_timeout(EXIT_TIME, self.quit)
Beispiel #12
0
 def build_sounds(self):
     self.lightOnSound = Sound("sounds/light_on.wav", intensity = 1.0, copies = 2)
     self.lightOffSound = Sound("sounds/light_off.wav", intensity = 1.0, copies = 2)
     self.melonDropSound = Sound("sounds/melon_drop.wav", intensity = 1.0)
     self.glassTapSound = Sound("sounds/glass_tap.wav", intensity = 0.25, copies = 4)
     self.exitSwitchSound = Sound("sounds/exit_switch.wav", intensity = 0.5, copies = 3)
     self.squeakSound = Sound("sounds/squeak.wav", intensity = 0.5)