Exemplo n.º 1
0
 public void DeleteHeldItem()
 {
     if (heldElement != null)
     {
         Destroy(heldElement.gameObject);
         heldElement = null;
         Socket.SendMessage(new UpdateItemMessage(0, "", ""));
         return;
     }
 }
Exemplo n.º 2
0
    private void Interact()
    {
        // first check if something is held
        if (grabbedElement != null)
        {
            grabbedElement.Throw();
            grabbedElement = null;
            return;
        }

        // Next check if an interaction is available
        if (nearestInteraction != null)
        {
            GameElement elem = nearestInteraction;
            try
            {
                elem.Interact(this);
            }
            catch (Exception e)
            {
            }

            if (elem is GrabbableElement)
            {
                grabbedElement = elem as GrabbableElement;
                HideIndicator(true);
            }
            if (elem is CollectableElement)
            {
                if (heldElement == null)
                {
                    heldElement = elem as CollectableElement;
                    Socket.SendMessage(new UpdateItemMessage(heldElement.ItemID, heldElement.ItemDescription, heldElement.ItemName));
                }
                else
                {
                    (elem as CollectableElement).Throw();
                }
            }
            nearestInteraction = null;
            return;
        }
    }
Exemplo n.º 3
0
    private void Update()
    {
        // input test
        if (enableKeyboard)
        {
            controller.SetActionState(eControllerActions.Jump, Input.GetKeyDown(KeyCode.Space));
            controller.SetActionState(eControllerActions.Left, Input.GetKey(KeyCode.Q));
            controller.SetActionState(eControllerActions.Right, Input.GetKey(KeyCode.D));
            controller.SetActionState(eControllerActions.Down, Input.GetKey(KeyCode.S));
            controller.SetActionState(eControllerActions.Up, Input.GetKey(KeyCode.Z));
            if (Input.GetKeyDown(KeyCode.A))
            {
                Interact();
            }
            if (Input.GetKeyDown(KeyCode.T))
            {
                heldElement.Throw();
                heldElement = null;
            }
        }

        if (singleAction || continousAction)
        {
            if (continousAction)
            {
                continousActionActive = true;
            }

            ButtonPressedMessage m = new ButtonPressedMessage();
            m.ButtonId = InputTest;
            ReceiveMessage(m);

            if (singleAction)
            {
                singleAction = false;
                ButtonPressedMessage m2 = new ButtonPressedMessage();
                m2.ButtonId = InputTest;
                ReceiveMessage(m2);
            }
        }

        if (!continousAction && continousActionActive)
        {
            ButtonReleasedMessage m = new ButtonReleasedMessage();
            m.ButtonId = InputTest;
            ReceiveMessage(m);
        }
        // end test

        if (nearestInteraction == null)
        {
            RemoveInteraction(null);
        }

        PlayerController ctl = GetComponent <PlayerController>();

        if (ctl.CanClimb && !CarrySomething)
        {
            ShowIndicator(false);
        }
        else
        {
            HideIndicator(false);
        }

        UpdateNearestInteraction();
    }
Exemplo n.º 4
0
    public void ReceiveMessage(Message mess)
    {
        if (mess is ButtonPressedMessage)
        {
            ButtonPressedMessage m = (ButtonPressedMessage)mess;

            switch (m.ButtonId)
            {
            case Buttons.B:
                controller.SetActionState(eControllerActions.Jump, true);
                break;

            case Buttons.A:
                Interact();
                break;

            case Buttons.Joystick:
                controller.SetActionState(eControllerActions.Left, false);
                controller.SetActionState(eControllerActions.Right, false);
                controller.SetActionState(eControllerActions.Down, false);
                controller.SetActionState(eControllerActions.Up, false);
                controller.SetActionState(TranslateJoystickInput(m.Extra1, m.Extra2), true);
                break;

            case Buttons.DPadLeft:
                controller.SetActionState(eControllerActions.Left, true);
                break;

            case Buttons.DPadRight:
                controller.SetActionState(eControllerActions.Right, true);
                break;

            case Buttons.DPadDown:
                controller.SetActionState(eControllerActions.Down, true);
                break;

            case Buttons.DPadUp:
                controller.SetActionState(eControllerActions.Up, true);
                break;
            }
        }
        else if (mess is ButtonReleasedMessage)
        {
            ButtonReleasedMessage m = (ButtonReleasedMessage)mess;

            switch (m.ButtonId)
            {
            case Buttons.DPadLeft:
            case Buttons.DPadRight:
            case Buttons.DPadDown:
            case Buttons.DPadUp:
            case Buttons.Joystick:
                controller.SetActionState(eControllerActions.Left, false);
                controller.SetActionState(eControllerActions.Right, false);
                controller.SetActionState(eControllerActions.Down, false);
                controller.SetActionState(eControllerActions.Up, false);
                break;

            case Buttons.B:
                controller.SetActionState(eControllerActions.Jump, false);
                break;

            case Buttons.A:
                break;
            }
        }
        else if (mess is ItemThrowMessage)
        {
            if (heldElement != null)
            {
                heldElement.Throw();
                heldElement = null;
                Socket.SendMessage(new UpdateItemMessage(0, "", ""));
            }
        }
    }