Example #1
0
    bool CanMoveToPosition(Vector3 tilePosition)
    {
        RaycastHit hit;
        Vector3    movingDirection = tilePosition - movedObject.transform.position;

        return(!movedObject.GetComponent <Rigidbody>().SweepTest(movingDirection.normalized, out hit, movingDirection.magnitude, QueryTriggerInteraction.Ignore));
    }
    // Use this for initialization
    void Start()
    {
        spawnTimer = maximumSpawnInterval;
        Score      = 0;

        //Build list of navigable tiles
        navigableTiles = new List <NavTile>();
        foreach (NavTile tile in navTileContainer.GetComponentsInChildren <NavTile>())
        {
            if (tile.navigable)
            {
                navigableTiles.Add(tile);
            }
        }

        player.GetComponent <Player>().onCollect += OnCollectCrate;

        startGroup.SetActive(true);
        gameplayGroup.SetActive(false);
        gameOverGroup.SetActive(false);

        int currentHighScore = PlayerPrefs.GetInt("highscore");

        highScoreText.text = string.Format(highScoreText.text, currentHighScore);
    }
    private Vector3 getPositionForNext(MovableObject g)
    {
        Vector2 currentSize     = g.GetComponent <SpriteRenderer>().bounds.size;
        Vector3 currentPosition = g.transform.position;

        currentPosition.x += currentSize.x;
        return(currentPosition);
    }
Example #4
0
    public void destroyObject(MovableObject food)
    {
        Food recycledFood = food.GetComponent <Food>();

        if (recycledFood != null)
        {
            recycledFood.delete();
        }
    }
Example #5
0
 public void AcceptActive()
 {
     if (_activeObject.Accept())
     {
         EditAction editAction;
         toolsPanel.SetActive(false);
         if (!(_activeObject.createdFromPanel))
         {
             editAction = new MoveEditAction(
                 _activeObject.gameObject,
                 new TransformDelta(_activeObject.restTransform, _activeObject.transform)
                 );
         }
         else
         {
             GameObject button = itemsPanel.GetComponent <ItemsPanel>().GetOrCreateButton(_activeObject.gameObject);
             button.GetComponent <ItemCreator>().DecrementAndCreate();
             editAction = new CreateEditAction(
                 _activeObject.gameObject,
                 button
                 );
             _activeObject.createdFromPanel = false;
         }
         _history.Add(editAction);
         if (_activeObject.movableObjectType == MovableObjectType.Gravity)
         {
             _activeObject.GetComponent <SimulationObject>().enabled = true;
             _activeObject.GetComponent <SimulationObject>().UpdateRest();
         }
         _activeObject.restTransform.copyFrom(_activeObject.transform);
         _activeObject.controller.toolMode = 0;
         _activeObject = null;
     }
     else
     {
         Debug.Log("Bad Position");
     }
 }
Example #6
0
    public bool StartCooking()
    {
        if (foodHolder.HasMovable())
        {
            MovableObject movable = foodHolder.GetMovable();
            currentFood = movable.GetComponent <Food>();
            if (currentFood != null && currentFood.GetStatus() == FoodStatus.CUT)
            {
                isCooking = true;
            }
        }

        return(isCooking);
    }
Example #7
0
    public bool startChopping()
    {
        chopperKnife.gameObject.SetActive(false);
        if (chopperHolder.hasMovable())
        {
            MovableObject movable = chopperHolder.GetMovableObjet();
            currentFood = movable.GetComponent <Food>();

            if (currentFood != null && currentFood.getStatus() == FoodStatus.RAW)
            {
                isChopping = true;
            }
        }

        return(isChopping);
    }
Example #8
0
 public bool StartChopping(Player p)
 {
     player = p;
     if (chopperHolder.HasMovable())
     {
         MovableObject movable = chopperHolder.GetMovable();
         currentFood = movable.GetComponent <Food>();
         if (currentFood != null && currentFood.GetStatus() == FoodStatus.RAW)
         {
             isChopping = true;
             player.lightsaber.currentState.activateSaber();
         }
     }
     open.Play();
     cut.Play();
     return(isChopping);
 }
    private void Update()
    {
        transform.position = new Vector3(transform.position.x, 0, transform.position.z);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Furniture currentFurniture = furnitureDetection.getSelected();

            if (currentFurniture != null)
            {
                Holder currentFurnitureHolder = currentFurniture.GetComponent <Holder>();

                if (myHolder.hasMovable() && !currentFurnitureHolder.hasMovable())
                {
                    MovableObject movable = myHolder.GetMovableObjet();
                    Trash         trash   = currentFurniture.GetComponent <Trash>();
                    if (trash != null)
                    {
                        Food food = movable.GetComponent <Food>();
                        if (food != null)
                        {
                            trash.destroyObject(movable);
                            myHolder.removeMovable();
                            currentFurnitureHolder.setMovable(movable);
                        }

                        Container container = movable.GetComponent <Container>();
                        if (container != null)
                        {
                            container.returnToEmpty();
                        }
                    }
                    else
                    {
                        Stove     stove     = currentFurniture.GetComponent <Stove>();
                        Container container = movable.GetComponent <Container>();
                        if (stove != null && container != null)
                        {
                            myHolder.removeMovable();
                            currentFurnitureHolder.setMovable(movable);
                        }
                        else if (stove == null)
                        {
                            OrganizingPlates organizingPlates = currentFurniture.GetComponent <OrganizingPlates>();
                            Plate            plate            = movable.GetComponent <Plate>();

                            if (organizingPlates != null)
                            {
                                if (plate != null)
                                {
                                    if (plate.plateContent == plateContent.TOMATO || plate.plateContent == plateContent.ONION || plate.plateContent == plateContent.MUSHROOM)
                                    {
                                        currentFurnitureHolder.setMovable(movable);
                                        plate.toEating();
                                        myHolder.removeMovable();

                                        Delivery delivery = currentFurniture.GetComponent <Delivery>();
                                        delivery.receivePlate(plate.plateContent);
                                        delivery.activatePanels();
                                    }
                                }
                            }
                            else
                            {
                                myHolder.removeMovable();
                                currentFurnitureHolder.setMovable(movable);
                            }
                        }
                    }
                }
                else if (myHolder.hasMovable() && currentFurnitureHolder.hasMovable())
                {
                    MovableObject movable = myHolder.GetMovableObjet();
                    Container     pot     = movable.GetComponent <Container>();
                    Plate         plate   = currentFurnitureHolder.GetMovableObjet().GetComponent <Plate>();


                    Container container = currentFurnitureHolder.GetComponentInChildren <Container>();
                    if (container != null)
                    {
                        if (container.verifyFood(movable.gameObject))
                        {
                            Food food = myHolder.GetComponentInChildren <Food>();
                            food.changeToCook();
                            container.addFood(food);
                            myHolder.removeMovable();

                            Cooking cooking = container.GetComponent <Cooking>();
                            cooking.setInitialTime();
                            if (!cooking.isActivated())
                            {
                                cooking.activateCanvas();
                            }
                        }
                    }
                    else
                    {
                        Stove stove = currentFurniture.GetComponent <Stove>();
                        if (stove != null && movable.GetComponent <MovableObject>().GetComponent <Container>() != null)
                        {
                            myHolder.removeMovable();
                            currentFurnitureHolder.setMovable(movable);
                        }
                    }

                    //--------------------------------------------------------

                    if (pot != null && plate != null)
                    {
                        if (pot.canGiveToPlate())
                        {
                            Cooking cooking = pot.GetComponent <Cooking>();
                            plate.receiveContent(cooking.iconCanvas);
                            plate.setPlateContent(pot.getPotContent());
                            pot.returnToEmpty();
                        }
                    }
                    else
                    {
                        Container pot2   = currentFurnitureHolder.GetMovableObjet().GetComponent <Container>();
                        Plate     plate2 = movable.GetComponent <Plate>();
                        if (pot2 != null && plate2 != null)
                        {
                            if (pot2.canGiveToPlate())
                            {
                                Cooking cooking = pot2.GetComponent <Cooking>();
                                plate2.receiveContent(cooking.iconCanvas);
                                plate2.setPlateContent(pot2.getPotContent());
                                pot2.returnToEmpty();
                            }
                        }
                    }
                }
                else if (currentFurnitureHolder.hasMovable() && !myHolder.hasMovable())
                {
                    MovableObject movable = currentFurnitureHolder.GetMovableObjet();
                    Chopper       chopper = currentFurniture.GetComponent <Chopper>();

                    if (chopper != null)
                    {
                        myHolder.setMovable(movable);
                        currentFurnitureHolder.removeMovable();

                        Timing timing = currentFurniture.GetComponent <Timing>();
                        timing.desactivateCanvas();
                        anim.SetBool("chopping", false);
                        chopper.stopChopping();
                    }
                    else
                    {
                        Container container = movable.GetComponent <Container>();

                        if (container != null)
                        {
                            myHolder.setMovable(movable);
                            currentFurnitureHolder.removeMovable();
                        }
                        else
                        {
                            myHolder.setMovable(movable);
                            currentFurnitureHolder.removeMovable();
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            Furniture currentFurniture = furnitureDetection.getSelected();

            if (currentFurniture != null)
            {
                Holder furnitureHolder = currentFurniture.GetComponent <Holder>();
                if (furnitureHolder != null)
                {
                    MovableAnchor movableA = furnitureHolder.GetComponentInChildren <MovableAnchor>();
                    if (movableA != null)
                    {
                        Food food = movableA.GetComponentInChildren <Food>();
                        if (food != null && (food.getStatus() == FoodStatus.RAW || food.getStatus() == FoodStatus.CUT))
                        {
                            currentChopper = currentFurniture.GetComponent <Chopper>();
                            if (currentChopper != null)
                            {
                                timing = currentFurniture.GetComponent <Timing>();
                                if (timing != null)
                                {
                                    timing.activateCanvas();
                                }
                                myKnife.gameObject.SetActive(true);
                                isChopping = currentChopper.startChopping();
                                anim.SetBool("chopping", isChopping);
                            }
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            Furniture currentFurniture = furnitureDetection.getSelected();

            if (currentFurniture != null)
            {
                Creator creator         = currentFurniture.GetComponent <Creator>();
                Holder  furnitureHolder = currentFurniture.GetComponent <Holder>();
                if (creator != null && myHolder.movableAnchor.transform.childCount == 0 && furnitureHolder.movableAnchor.transform.childCount == 0)
                {
                    MovableObject movable = creator.createFood();
                    myHolder.setMovable(movable);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.LeftAlt) && !boost)
        {
            boost = true;
            speed = 0.25f;
        }

        if (boost)
        {
            if (timeBoost >= 0)
            {
                timeBoost -= Time.deltaTime;
                speed      = speed + (-0.15f) * Time.deltaTime;
            }
            else
            {
                boost     = false;
                speed     = 0.1f;
                timeBoost = 1f;
            }
        }
    }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        int currentLayerMask = allRaycastLayers;

        if (heldMovableObject != null && heldMovableObject is Limb)
        {
            //Debug.Log("USING holdingLimbRaycastLayers");
            currentLayerMask = holdingLimbRaycastLayers;
        }

        bool shouldRaycast = true;

        if (heldMovableObject != null && heldMovableObject is Draggable)
        {
            shouldRaycast = false;
        }

        Ray inputRay = mainCamera.ScreenPointToRay(Input.mousePosition);

        Debug.DrawRay(inputRay.origin, inputRay.direction, Color.blue, 1f);
        RaycastHit hit;

        if (shouldRaycast && Physics.Raycast(inputRay, out hit, 40, currentLayerMask))
        {
            if (hit.collider.gameObject.layer == 8 || hit.collider.gameObject.layer == 9 || hit.collider.gameObject.layer == 10)
            {
                IHightlightableObject highlightableObject = hit.collider.gameObject.GetComponent <IHightlightableObject>();
                if (highlightableObject != null && highlightableObject != currentHightlightedObject)
                {
                    if (currentHightlightedObject != null)
                    {
                        currentHightlightedObject.HightlightEnd();
                    }
                    currentHightlightedObject = highlightableObject;
                    currentHightlightedObject.HightlightStart();
                }
            }
            else
            {
                if (currentHightlightedObject != null)
                {
                    currentHightlightedObject.HightlightEnd();
                    currentHightlightedObject = null;
                }
            }
        }
        else
        {
            if (currentHightlightedObject != null)
            {
                currentHightlightedObject.HightlightEnd();
                currentHightlightedObject = null;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (currentHightlightedObject != null)
            {
                MovableObject moveableObject = currentHightlightedObject.GetGameObject().GetComponent <MovableObject>();
                if (moveableObject != null)
                {
                    heldMovableObject = moveableObject;
                    heldMovableObject.OnMoveStart();
                    //currentZOffsetFromCamera = (heldMovableObject.gameObject.transform.position - mainCamera.transform.position).z;
                    playerRigidbody.MovePosition(heldMovableObject.transform.position);
                    //Limb move offset is from -1 to 1 in localspace. Turn it into normal -0.5 to 0.5 to use it as an anchor
                    playerHingeJoint.connectedAnchor = heldMovableObject.GetMoveOffset() * 0.5f; //heldMovableObject.transform.
                    playerHingeJoint.connectedBody   = heldMovableObject.GetComponent <Rigidbody>();
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (heldMovableObject != null)
            {
                playerHingeJoint.connectedBody = null;
                heldMovableObject.OnMoveStop();
                if (currentHightlightedObject != null && currentHightlightedObject is AttachPoint && heldMovableObject is Limb)
                {
                    AttachPoint attachPoint = currentHightlightedObject as AttachPoint;
                    if (!attachPoint.HasLimb())
                    {
                        SoundEffects.PlayAudioAtLocation("critch", transform.position);
                        attachPoint.AttachLimb(heldMovableObject as Limb, true);
                    }
                }
                heldMovableObject = null;
            }
        }
        else if (Input.GetMouseButton(0))
        {
            if (heldMovableObject != null)
            {
                Vector2 mouseDelta = (Vector2)Input.mousePosition - previousMousePosition;
                if (heldMovableObject is Limb)
                {
                    //heldMovableObject.OnMoveInDirection(((Vector2)Input.mousePosition - previousMousePosition) * Time.deltaTime);
                    //currentZOffsetFromCamera = (heldMovableObject.gameObject.transform.position - mainCamera.transform.position).z;
                    playerRigidbody.MovePosition(mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, zOffsetFromCamera)) - Vector3.up * 0.35f);
                }
                else if (heldMovableObject is Draggable && mouseDelta.magnitude > Vector2.zero.magnitude)
                {
                    heldMovableObject.OnMoveInDirection(mouseDelta);
                }
            }
        }

        previousMousePosition = Input.mousePosition;
    }
Example #11
0
    void Update()
    {
        float horizontalMovement = Input.GetAxis("Horizontal");
        float verticalMovement   = Input.GetAxis("Vertical");

        moveTo = new Vector3(horizontalMovement, 0, verticalMovement);

        if (moveTo != Vector3.zero)
        {
            animator.SetBool("Walking", true);
            animator.SetBool("IDLE", false);
            animator.SetBool("Pulling", false);
            animator.SetBool("Cutting", false);
        }
        else
        {
            if (isChopping)
            {
                animator.SetBool("IDLE", false);
                animator.SetBool("Walking", false);
                animator.SetBool("Pulling", false);
                animator.SetBool("Cutting", true);
            }
            else
            {
                animator.SetBool("IDLE", true);
                animator.SetBool("Walking", false);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Furniture currentFurniture = furnitureDetection.GetSelected();
            if (currentFurniture != null)
            {
                Holder currentFurnitureHolder = currentFurniture.GetComponent <Holder>();
                //Give
                if (currentFurnitureHolder != null)
                {
                    //Si el jugador tiene un objeto
                    if (PlayerHolder.HasMovable())
                    {
                        //Si ambos tienen objeto no lo cambia, se queda igual
                        if (PlayerHolder.HasMovable() && currentFurnitureHolder.HasMovable())
                        {
                            MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                            MovableObject playerMovable    = PlayerHolder.GetMovable();

                            PlayerHolder.SetMovable(playerMovable);
                            currentFurnitureHolder.SetMovable(furnitureMovable);
                        }
                        //Si solo uno tiene objeto
                        else
                        {
                            MovableObject movable = PlayerHolder.GetMovable();
                            Trash         trash   = currentFurniture.GetComponent <Trash>();
                            Cooker        cooker  = currentFurniture.GetComponent <Cooker>();
                            Chopper       chopper = currentFurniture.GetComponent <Chopper>();
                            //Si el mueble es el basurero
                            if (trash != null && movable.GetComponent <Food>())
                            {
                                PlayerHolder.RemoveMovable();
                                Destroy(movable.gameObject);

                                /*Food food = movable.GetComponent<Food>();
                                 * if (food!= null)
                                 * {
                                 *  food.Delete();
                                 * }*/
                            }
                            //Solo acepta basura en el basurero
                            if (trash != null && movable.GetComponent <Food>() == false)
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                MovableObject playerMovable    = PlayerHolder.GetMovable();

                                PlayerHolder.SetMovable(playerMovable);
                                currentFurnitureHolder.SetMovable(furnitureMovable);
                            }
                            //Solo acepta la olla en los hornos
                            if (cooker != null && movable.GetComponent <Container>() == false)
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                MovableObject playerMovable    = PlayerHolder.GetMovable();

                                PlayerHolder.SetMovable(playerMovable);
                                currentFurnitureHolder.SetMovable(furnitureMovable);
                            }
                            if (chopper != null && movable.GetComponent <Food>() == false)
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                MovableObject playerMovable    = PlayerHolder.GetMovable();

                                PlayerHolder.SetMovable(playerMovable);
                                currentFurnitureHolder.SetMovable(furnitureMovable);
                            }
                            //Si tiene el objeto y lo que tiene en frente tiene la olla
                            else
                            {
                                MovableObject furnitureMovable = currentFurnitureHolder.GetMovable();
                                if (furnitureMovable != null)
                                {
                                    Container furnitureContainer = furnitureMovable.GetComponent <Container>();
                                    if (furnitureContainer != null)
                                    {
                                        Food food = movable.GetComponent <Food>();
                                        if (food != null)
                                        {
                                            if (furnitureContainer.CanAccept(food))
                                            {
                                                PlayerHolder.RemoveMovable();
                                            }
                                        }
                                    }
                                }
                                currentFurnitureHolder.SetMovable(movable);
                                PlayerHolder.RemoveMovable();
                            }
                        }
                    }
                    //Pick
                    else
                    {
                        if (currentFurnitureHolder.HasMovable())
                        {
                            MovableObject movable = currentFurnitureHolder.GetMovable();
                            PlayerHolder.SetMovable(movable);
                            currentFurnitureHolder.RemoveMovable();
                        }
                        else
                        {
                            IngredientSpawner ingred = currentFurniture.GetComponent <IngredientSpawner>();
                            if (ingred != null)
                            {
                                MovableObject movable = ingred.GetIngredient();
                                PlayerHolder.SetMovable(movable);
                            }
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            Furniture currentFurniture = furnitureDetection.GetSelected();
            if (currentFurniture != null)
            {
                Chopper currentChopper = currentFurniture.GetComponent <Chopper>();
                //Comienza a cortar
                if (currentChopper != null)
                {
                    isChopping = currentChopper.StartChopping(this);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            tempForce = force;
            Debug.Log("La fuerza temporal es");
            Debug.Log(tempForce);
            timer += Time.deltaTime;
            while (timer < 10.0f)
            {
                timer += Time.deltaTime;
                force  = forceBoost;
                Debug.Log("La fuerza es");
                Debug.Log(force);
            }
            force = tempForce;
            Debug.Log("La fuerza es");
            Debug.Log(force);
        }
    }