Exemplo n.º 1
0
class StartBallMotion(System):
    """
    StartBallMotion ensures that the game restarts after the start key is pressed.
    """
    entity_filters = {
        'ball': and_filter([
            Proxy('model'),
            Resting,
            Ball,
        ]),
    }
    start_key = KeyboardButton.space()

    def update(self, entities_by_filter):
        """
        Check whether the resting ball should be started?
        Note that restarting the ball's movement means removing the Entity's
        Resting Component, and adding it's Movement component with the desired
        direction.
        """

        start_key_is_pressed = base.mouseWatcherNode.is_button_down(
            StartBallMotion.start_key)

        if start_key_is_pressed:
            for entity in set(entities_by_filter['ball']):
                del entity[Resting]
                entity[Movement] = Movement(
                    direction=Vec3(-0.1 * randrange(5, 10), 0, 0))
Exemplo n.º 2
0
 def update(self, entities_by_filter):
     start_balls = base.mouseWatcherNode.is_button_down(
         KeyboardButton.space(), )
     if start_balls:
         for entity in set(entities_by_filter['ball']):
             entity.remove_component(Resting)
             entity.add_component(Movement(value=Vec3(-1, 0, 0)))
Exemplo n.º 3
0
    def update(self, entities_by_filter):
        # Should resting balls be started?
        start_key = KeyboardButton.space()
        start_balls = base.mouseWatcherNode.is_button_down(start_key)

        if start_balls:
            for entity in set(entities_by_filter['ball']):
                del entity[Resting]
                entity[Movement] = Movement(value=Vec3(-1, 0, 0))
Exemplo n.º 4
0
class InputMapperTecladoMouse(InputMapper):

    # teclas accion defecto
    TeclasAccionDefecto = {
        KeyboardButton.enter(): InputMapper.AccionArrojar,
        KeyboardButton.space(): InputMapper.AccionAscender,
        KeyboardButton.tab(): InputMapper.AccionUsar,
        KeyboardButton.control(): InputMapper.AccionAgachar,
        KeyboardButton.alt(): InputMapper.AccionAgarrar,
        KeyboardButton.asciiKey(b"c"): InputMapper.AccionFlotar,
        KeyboardButton.asciiKey(b"x"): InputMapper.AccionSoltar,
        KeyboardButton.asciiKey(b"z"): InputMapper.AccionFrenar,
        KeyboardButton.asciiKey(b"w"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"a"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"s"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"d"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"r"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"f"): InputMapper.AccionAvanzar
    }

    # teclas parametro defecto
    TeclasParamDefecto = {
        KeyboardButton.asciiKey(b"w"): InputMapper.ParametroAdelante,
        KeyboardButton.asciiKey(b"a"): InputMapper.ParametroIzquierda,
        KeyboardButton.asciiKey(b"s"): InputMapper.ParametroAtras,
        KeyboardButton.asciiKey(b"d"): InputMapper.ParametroDerecha,
        KeyboardButton.asciiKey(b"r"): InputMapper.ParametroArriba,
        KeyboardButton.asciiKey(b"f"): InputMapper.ParametroAbajo,
        KeyboardButton.asciiKey(b"q"):
        InputMapper.ParametroGirando | InputMapper.ParametroIzquierda,
        KeyboardButton.asciiKey(b"e"):
        InputMapper.ParametroGirando | InputMapper.ParametroDerecha,
        KeyboardButton.shift(): InputMapper.ParametroRapido,
        KeyboardButton.asciiKey(b"v"): InputMapper.ParametroLento
    }

    def __init__(self, base):
        InputMapper.__init__(self, base)

    def update(self):
        # parametros
        self.parametros = InputMapper.ParametroNulo
        for tecla, parametro in InputMapperTecladoMouse.TeclasParamDefecto.items(
        ):
            if self.isButtonDown(tecla):
                self.parametros |= parametro
        # acciones
        self.accion = InputMapper.AccionNula
        for tecla, accion in InputMapperTecladoMouse.TeclasAccionDefecto.items(
        ):
            if self.isButtonDown(tecla):
                self.accion = accion
                break
Exemplo n.º 5
0
def update(task):
    global thrust
    if thrust > 0:
        thrust -= 1
    if s.mouseWatcherNode.is_button_down(KeyboardButton.space()):
        if thrust < 15:
            thrust += 2

    for beam in beams:
        beam.setScale(thrust / 8)

    return task.cont
Exemplo n.º 6
0
def test_keyboardbutton_ascii():
    assert KeyboardButton.space() == KeyboardButton.ascii_key(' ')
    assert KeyboardButton.backspace() == KeyboardButton.ascii_key('\x08')
    assert KeyboardButton.tab() == KeyboardButton.ascii_key('\x09')
    assert KeyboardButton.enter() == KeyboardButton.ascii_key('\x0d')
    assert KeyboardButton.escape() == KeyboardButton.ascii_key('\x1b')

    assert KeyboardButton.ascii_key(' ').name == 'space'
    assert KeyboardButton.ascii_key('\x08').name == 'backspace'
    assert KeyboardButton.ascii_key('\x09').name == 'tab'
    assert KeyboardButton.ascii_key('\x0d').name == 'enter'
    assert KeyboardButton.ascii_key('\x1b').name == 'escape'
    assert KeyboardButton.ascii_key('\x7f').name == 'delete'

    assert KeyboardButton.ascii_key('a').name == 'a'
Exemplo n.º 7
0
 def defineKeys(self):
     for k in self.keyState.keys():
         self.keyState[k] = False
     if self.isKeyDown(KeyboardButton.up()):
         self.keyState["WalkFw"] = True
     if self.isKeyDown(KeyboardButton.down()):
         self.keyState["WalkBw"] = True
     if self.isKeyDown(KeyboardButton.left()):
         self.keyState["RotateL"] = True
     if self.isKeyDown(KeyboardButton.right()):
         self.keyState["RotateR"] = True
     if self.isKeyDown(KeyboardButton.shift()):
         self.keyState["Run"] = True
     if self.isKeyDown(KeyboardButton.space()):
         self.keyState["Jump"] = True
     if self.isKeyDown(KeyboardButton.asciiKey("d")):
         self.keyState["Duck"] = True
Exemplo n.º 8
0
    def __init__(self, sb, mouse_magnitude=30, min_pitch=-60, max_pitch=60):
        self.base = sb
        self.mouse_magnitude = mouse_magnitude
        self.min_pitch = min_pitch
        self.max_pitch = max_pitch

        props = WindowProperties()
        props.set_cursor_hidden(True)
        props.set_mouse_mode(WindowProperties.MRelative)
        self.base.win.requestProperties(props)
        self.accept('mouse1', self.mouse1)

        tm = self.base.task_mgr
        tm.add(self.mouse_move, 'fp-mouse-move')
        tm.add(self.kb_move, 'fp-kb-move')
        self.keys = {
            'forward': KeyboardButton.ascii_key(b'w'),
            'left': KeyboardButton.ascii_key(b'a'),
            'right': KeyboardButton.ascii_key(b'd'),
            'backward': KeyboardButton.ascii_key(b's'),
            'up': KeyboardButton.space(),
            'down': KeyboardButton.control()
        }
Exemplo n.º 9
0
    def update(self, entities_by_filter):
        for entity in entities_by_filter['character']:
            character = entity[CharacterController]
            character.jumps = False
            character.sprints = False
            character.crouches = False
            character.move.x = 0.0
            character.move.y = 0.0
            character.heading = 0.0
            character.pitch = 0.0
            # For debug purposes, emulate analog stick on keyboard
            # input, being half-way pressed, by holding shift
            analog = 1
            if base.mouseWatcherNode.is_button_down(KeyboardButton.shift()):
                analog = 0.5
            if base.mouseWatcherNode.is_button_down(
                    KeyboardButton.ascii_key("w")):
                character.move.y += analog
            if base.mouseWatcherNode.is_button_down(
                    KeyboardButton.ascii_key("s")):
                character.move.y -= analog
            if base.mouseWatcherNode.is_button_down(
                    KeyboardButton.ascii_key("a")):
                character.move.x -= analog
            if base.mouseWatcherNode.is_button_down(
                    KeyboardButton.ascii_key("d")):
                character.move.x += analog

            # Rotation
            if base.mouseWatcherNode.is_button_down(KeyboardButton.up()):
                character.pitch += 1
            if base.mouseWatcherNode.is_button_down(KeyboardButton.down()):
                character.pitch -= 1
            if base.mouseWatcherNode.is_button_down(KeyboardButton.left()):
                character.heading += 1
            if base.mouseWatcherNode.is_button_down(KeyboardButton.right()):
                character.heading -= 1

            if TurntableCamera in entity:
                camera = entity[TurntableCamera]
                camera.heading = camera.pitch = 0
                if base.mouseWatcherNode.is_button_down(
                        KeyboardButton.ascii_key("j")):
                    camera.heading = 1
                if base.mouseWatcherNode.is_button_down(
                        KeyboardButton.ascii_key("l")):
                    camera.heading = -1
                if base.mouseWatcherNode.is_button_down(
                        KeyboardButton.ascii_key("i")):
                    camera.pitch = -1
                if base.mouseWatcherNode.is_button_down(
                        KeyboardButton.ascii_key("k")):
                    camera.pitch = 1

            # Special movement modes.
            # By default, you run ("sprint"), unless you press e, in
            # which case you walk. You can crouch by pressing q; this
            # overrides walking and running. Jump by pressing space.
            # This logic is implemented by the Walking system. Here,
            # only intention is signalled.
            if base.mouseWatcherNode.is_button_down(
                    KeyboardButton.ascii_key("e")):
                character.sprints = True
            if base.mouseWatcherNode.is_button_down(
                    KeyboardButton.ascii_key("c")):
                character.crouches = True
            if base.mouseWatcherNode.is_button_down(KeyboardButton.space()):
                character.jumps = True
Exemplo n.º 10
0
    def __init__(self):
        #
        # MODEL AND ANIMATION
        #
        # The players model file path
        self.basePath = "character/"
        self.model = self.basePath + "character"
        # Paths of the animation files
        self.anim_idle = self.basePath + "character-Idle"
        self.anim_walk = self.basePath + "character-Walk"
        self.anim_plant = self.basePath + "character-Plant"
        # NOTE: This should always be enabled to smoth the transition within
        #       animations. For example for the accleration of the character
        #       untill it reaches full pace.
        self.enable_interpolation = True

        #
        # AUDIO
        #
        self.sfxPath = "sfx/"
        self.walk_sound = loader.loadSfx(self.sfxPath + "step.ogg")
        self.walk_sound.setLoop(True)


        #
        # CONTROLS
        #
        self.key_forward = KeyboardButton.asciiKey('w')
        self.key_backward = KeyboardButton.asciiKey('s')
        self.key_left = KeyboardButton.asciiKey('a')
        self.key_right = KeyboardButton.asciiKey('d')
        self.key_plant = KeyboardButton.space()
        self.key_center_camera = KeyboardButton.home()
        # accleration for the various states
        self.accleration = 3.5
        # the speed of how fast the player deacclerates
        self.deaccleration = 16.0
        # maximum acclerations at the various states
        self.max_accleration = 8.0
        # the speed for how fast the player is generally moving
        self.speed = 0.7

        #
        # GAME SPECIFIC
        #
        # planting possibility
        self.planting_enabled = False
        self.carry_seed = False

        #
        # CAMERA CONTROL VARIABLES
        #
        # Camera basics
        self.cam_near_clip = 0.5
        self.cam_far_clip = 5000
        self.cam_fov = 70
        # Mouse camera movement
        # enables the camera control via the mouse
        self.enable_mouse = True
        # invert vertical camera movements
        self.mouse_invert_vertical = False
        # screen sizes
        self.win_width_half = base.win.getXSize() / 2
        self.win_height_half = base.win.getYSize() / 2
        # mouse speed
        self.mouse_speed_x = 150.0
        self.mouse_speed_y = 80.0
        # the next two vars will set the min and max distance the cam can have
        # to the node it is attached to
        self.max_cam_distance = 5.0
        self.min_cam_distance = 2.0
        # the initial cam distance
        self.cam_distance = (self.max_cam_distance - self.min_cam_distance) / 2.0 + self.min_cam_distance
        # the maximum distance on the Z-Axis to the player
        self.max_cam_height_distance = 2.0
        # the minimum distance on the Z-Axis to the player
        self.min_cam_height_distance = 0.15
        # the average camera height
        self.cam_height_avg = (self.max_cam_height_distance - self.min_cam_height_distance) / 2.0 + self.min_cam_height_distance
        # the initial cam height
        self.cam_height = self.cam_height_avg
        # the speed of the cameras justification movement towards
        # the average height
        self.cam_z_justification_speed = 1
        # a floater which hovers over the player and is used as a
        # look at position for the camera
        self.cam_floater_pos = Point3F(0, 0, 1.5)

        #
        # PHYSICS
        #
        # show collision solids
        self.show_collisions = False
        # The physical physic_world which will be responsible for collision checks and
        # physic updates
        self.physic_world = None
        # the name of the collision solids that surround the character
        self.char_collision_name = "CharacterCollisions"
        # the mass of the character
        self.player_mass = 25
        # the heights of the various player states
        # normal height
        self.player_height = 1.186
        # the radius of the players collision shape
        self.player_radius = self.player_height / 4.0
        # step height
        self.stepheight = 0.7