Exemplo n.º 1
0
        /// <summary>
        /// Runs the PickUpRefinedCrateRequest.
        /// This will try to make a task for a robot to move a refined crate in refinery to a empty export storage node.
        /// Returns true if succesfully completed.
        /// </summary>
        /// <param name="w"></param>
        /// <returns></returns>
        public bool RunTask(Model w)
        {
            Node emptyStorageNode = null;

            foreach (Node node in w.nodeGrid.nodes)
            {
                if (node is StorageNode)
                {
                    if (!((StorageNode)node).CheckImport() && !((StorageNode)node).GetReserved())
                    {
                        emptyStorageNode = node;
                        ((StorageNode)node).ReserveNode();
                        break;
                    }
                }
            }
            if (emptyStorageNode == null)
            {
                return(false);
            }
            w.tasksForRobot.Add(new TaskForRobot(new double[] { -25, 1 }, ((Node)emptyStorageNode).position, pickUpCrate, refinery, (DropOffTarget)emptyStorageNode));
            w.worldObjects.Add(pickUpCrate);
            pickUpCrate.Move(pickUpCrate.x, pickUpCrate.y, pickUpCrate.z);
            return(true);
        }
Exemplo n.º 2
0
    private bool MoveCrate(Crate crate)
    {
        Vector3 playerPosition = transform.position;
        Vector3 cratePosition  = crate.transform.position;

        // TODO: Convert this to use tile map coordinates
        float horizontalDelta = playerPosition.x - cratePosition.x;
        int   horizontal      = horizontalDelta > 0 ? -1 : 1;
        float verticalDelta   = playerPosition.y - cratePosition.y;
        int   vertical        = verticalDelta > 0 ? -1 : 1;

        if (Mathf.Abs(verticalDelta) > Mathf.Abs(horizontalDelta))
        {
            horizontal = 0;
        }
        else
        {
            vertical = 0;
        }

        // print("Attempting to move crate h:" + horizontal + "("+horizontalDelta+") v:" + vertical + " ("+verticalDelta+")");

        return(crate.Move(horizontal, vertical, out _));
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        float moveHorizontal = -Input.GetAxis(HorizontalAxis);
        float moveVertical   = Input.GetAxis(VerticalAxis);

        Vector3 movement = new Vector3(moveVertical, 0.0F, normalMask?moveHorizontal:-moveHorizontal);


        if (Input.GetButtonDown(UseButton))
        {
            var playerHit = false;

            RaycastHit hit;
            if (Physics.Raycast(transform.position + (Vector3.up * 0.5f), transform.forward, out hit, 0.9f))
            {
                if (hit.transform.gameObject.tag == "Player" && !HasKey)
                {
                    Debug.Log("Player Hit");

                    playerHit = true;
                    if (HasKey)
                    {
                        ThrowKey();
                    }

                    Animator.SetTrigger("Hit");
                    hit.transform.gameObject.GetComponent <CharacterMovement>().Hit(transform.forward);

                    Invoke("playPunchSound", 0.26f);
                }
            }

            if (!playerHit && Physics.Raycast(transform.position + (Vector3.up * 0.5f), transform.forward, out hit, 0.7f, normalMask?Mask:MirrorMask))
            {
                Debug.Log(hit.transform.gameObject.name);

                if (hit.transform.gameObject.tag == "Crate" && !HasKey)
                {
                    isUsingCrate = true;
                    Debug.Log("Crate used");

                    direction = transform.forward;
                    crate     = hit.transform.gameObject.GetComponent <Crate>();
                }
                else if (hit.transform.gameObject.tag == "Key" && !HasKey)
                {
                    Key key = hit.transform.gameObject.GetComponent <Key>();

                    if (key.HasAccess(PlayerID))
                    {
                        HasKey    = true;
                        KeyObject = hit.transform.gameObject;
                        KeyObject.SetActive(false);
                        HandHeldKey.SetActive(true);
                        Debug.Log("found Key");
                        SourceOfAudio.PlayOneShot(KeySound, 1);
                    }
                }
                else if (hit.transform.gameObject.tag == "Door")
                {
                    Debug.Log("Det er en dør");
                    if (HasKey)
                    {
                        Debug.Log("Du vandt, sejt!");
                        if (PlayerID == 1)
                        {
                            scoreManager.IncreasePlayer1Score();
                        }
                        else if (PlayerID == 2)
                        {
                            scoreManager.IncreasePlayer2Score();
                        }
                        SourceOfAudio.PlayOneShot(DoorSound, 1);

                        levelManager.NextLevel();
                    }
                }
                else if (hit.transform.gameObject.tag == "GateFence" && !HasKey)
                {
                    Debug.Log("Der er en låge");
                    Animator.SetBool("OpenDoor", true);
                    hit.transform.gameObject.GetComponent <Animator>().SetBool("Open", true);
                }
                else if (hit.transform.gameObject.CompareTag("WaterPump"))
                {
                    WaterPump wp = hit.transform.gameObject.GetComponent <WaterPump>();
                    Animator.SetTrigger("TurnPump");
                    if (wp != null)
                    {
                        wp.Interact();
                    }
                    else
                    {
                        Debug.LogWarning("mangler WaterPump component!");
                    }
                }
                else if (hit.transform.gameObject.tag == "GateFenceMirror" && !HasKey)
                {
                    Debug.Log("Der er en mirror portal");
                    Animator.SetBool("OpenDoor", true);
                    //mirror player with shadow
                    if (normalMask)
                    {
                        gameObject.layer = MirrorLayer;
                        Body.layer       = MirrorLayer;
                        MirrorBody.layer = NormalLayer;
                    }
                    else
                    {
                        gameObject.layer = NormalLayer;
                        Body.layer       = NormalLayer;
                        MirrorBody.layer = MirrorLayer;
                    }
                    normalMask = !normalMask;
                }
                else
                {
                    Taunt();
                }
            }
            else if (HasKey)
            {
                ThrowKey();
            }
            else if (!playerHit)
            {
                Taunt();
            }
        }
        else if (Input.GetButtonUp(UseButton))
        {
            isUsingCrate = false;
        }


        if (isUsingCrate)
        {
            var diff = 0f;
            if (Mathf.Abs(direction.x) > Mathf.Abs(direction.z))
            {
                movement = new Vector3(movement.x, 0f, 0f);
                diff     = movement.x;
            }
            else
            {
                movement = new Vector3(0f, 0f, movement.z);
                diff     = movement.z;
            }

            Speed = diff / 2;

            crate.Move(movement * (MovementSpeed / 2));
            CharacterControlerVariable.Move(movement * Time.deltaTime * (MovementSpeed / 2));
            Animator.SetBool("Pushing", true);
        }
        else
        {
            Speed = movement.magnitude;

            //CharacterControlerVariable.Move(movement * Time.deltaTime*MovementSpeed);
            if (movement != Vector3.zero)
            {
                transform.rotation = Quaternion.LookRotation(movement);
            }

            CharacterControlerVariable.Move(movement * Time.deltaTime * MovementSpeed);
            Animator.SetBool("Pushing", false);
        }

        //Check if we touch the ground.
        Vector3 transformDown = transform.TransformDirection(Vector3.down);

        if (!Physics.Raycast(transform.position, transformDown, 0.05f))
        {
            //print("We are falling");
            Vector3 fall = new Vector3(0.0f, -0.1f, 0.0f);
            CharacterControlerVariable.Move(fall);
        }

        if (transform.position.y < -4f)
        {
            ResetCharacterOnLevelLoad();
        }
    }