Example #1
0
 public AbilityInput(ShipInputs inputs)
 {
     boost = inputs.boost;
 }
Example #2
0
    // Update is called once per frame
    public override void Update()
    {
        // if not local player, ignore an controller inputs!!!!
        if (!isLocalPlayer)
        {
            return;
        }

        shipInputs = new ShipInputs();

        // check for controller assignment to the player
        if (!inputIsAttached)
        {
            // check for an available device
            foreach (InputDevice device in InputManager.Devices)
            {
                if (device.Action1.WasPressed && !devicesInUse.Contains(device))
                {
                    SetInput(device);
                    break;
                }
            }
        }

        // if you have an attached controller
        if (inputIsAttached)
        {
            // get inputs from the controller and save them
            shipInputs.warp.isPressed     = actions.warp.IsPressed;
            shipInputs.boost.isPressed    = actions.boost.IsPressed;
            shipInputs.special.isPressed  = actions.special.IsPressed;
            shipInputs.flipShot.isPressed = actions.flipShot.IsPressed;
            shipInputs.start.isPressed    = actions.start.IsPressed;

            shipInputs.warp.wasPressed     = actions.warp.WasPressed;
            shipInputs.boost.wasPressed    = actions.boost.WasPressed;
            shipInputs.special.wasPressed  = actions.special.WasPressed;
            shipInputs.flipShot.wasPressed = actions.flipShot.WasPressed;
            shipInputs.start.wasPressed    = actions.start.WasPressed;

            shipInputs.warp.wasReleased     = actions.warp.WasReleased;
            shipInputs.boost.wasReleased    = actions.boost.WasReleased;
            shipInputs.special.wasReleased  = actions.special.WasReleased;
            shipInputs.flipShot.wasReleased = actions.flipShot.WasReleased;
            shipInputs.start.wasReleased    = actions.start.WasReleased;

            float grindVal = actions.grind.Value;
            if (grindVal < GRIND_RELEASE_VAL)
            {
                shipInputs.grind.wasReleased = true;
                shipInputs.grind.isPressed   = shipInputs.grind.wasPressed = false;
            }
            else
            {
                shipInputs.grind.wasPressed = !shipInputs.grind.isPressed ? true : false;
                shipInputs.grind.isPressed  = true;
            }

            shipInputs.direction.x = actions.movement.X;
            shipInputs.direction.y = actions.movement.Y;

            // send movement inputs to the server
            CmdUploadMovementInput(shipInputs.direction);

            // send ability inputs to the server
            AbilityInput abilityInputs = new AbilityInput(shipInputs);
            if (abilityInputs != prevAbilityInputs)
            {
                CmdUploadAbilityInput(abilityInputs);
            }

            /*
             * if (cmdTimer.Update(Time.deltaTime))
             * {
             *  CmdUploadInput(shipInputs);
             *  cmdTimer.Activate();
             * }
             */

            prevAbilityInputs = abilityInputs;
        }
    }