Beispiel #1
0
    void Update()
    {
        if (!grid)
        {
            return;
        }
        if (allowMove)
        {
            if (doMove)
            {
                //move towards the desination
                Vector3 newPosition = transform.position;
                newPosition.x      = Mathf.MoveTowards(transform.position.x, goal.x, roamingSpeed * Time.deltaTime);
                newPosition.y      = Mathf.MoveTowards(transform.position.y, goal.y, roamingSpeed * Time.deltaTime);
                transform.position = newPosition;

                //check if we reached the destination (use a certain tolerance so we don't miss the point becase of rounding errors)
                if (Mathf.Abs(transform.position.x - goal.x) < 0.01f && Mathf.Abs(transform.position.y - goal.y) < 0.01f)
                {
                    doMove = false;
                }
                else
                {
                    GetComponent <Hero> ().myDistance++;
                }
                //if we did stop moving

                // Set animation og rotation så det passer med bevægelsen
                animator.SetBool("Run", doMove);
                transform.rotation = Quaternion.Euler(rotation);
            }
            else
            {
                //make sure the time is always positive
                if (roamingTime < 0.01f)
                {
                    roamingTime = 0.01f;
                }
                //find the next destination
                goal = FindNextFace();
                //--- let's check if the goal is allowed, if not we will pick another direction during the next frame ---
                if (ForbiddenTilesVores.CheckSquare(goal).Equals('0'))
                {
                    //calculate speed by dividing distance (one of the two distances will be 0, we need the other one) through time
                    roamingSpeed = Mathf.Max(Mathf.Abs(transform.position.x - goal.x), Mathf.Abs(transform.position.y - goal.y)) / roamingTime;
                    //resume movement with the new goal
                    doMove = true;
                }
                else
                {
                    //Debug.Log ("hit the obstacle");
                }
            }
        }
    }
Beispiel #2
0
    /** Flammer spawnes */
    public void blastHallWithFire()
    {
        Spawner    sp      = gameObject.GetComponent <Spawner> ();
        Vector3    bombPos = transform.position;
        GameObject senesteFlamme;

        // Retninger
        Vector3 opVecDec      = new Vector3(270, 0, 0);
        Vector3 nedVecDec     = new Vector3(90, 180, 0);
        Vector3 hoejreVecDec  = new Vector3(0, 90, 270);
        Vector3 venstreVecDec = new Vector3(0, 270, 90);

        // Center
        senesteFlamme = sp.SpawnElement(bombPos, opVecDec);
        senesteFlamme.GetComponent <Exploded> ().placer = placer;

        // Mid & End
        bool up    = true;
        bool down  = true;
        bool left  = true;
        bool right = true;

        for (float i = 0; i <= range; i++)
        {
            /* Hvis enden er nået sættes element til at være flammeEnd
             * ellers sættes den til at være flammeMid */
            int element = i < range ? 1 : 2;

            if (up)
            {
                senesteFlamme = sp.SpawnElement(bombPos + new Vector3(0, i, 0), opVecDec, element);
                senesteFlamme.GetComponent <Exploded> ().placer = placer;
                char ramte = ForbiddenTilesVores.CheckSquare(senesteFlamme.transform.position + new Vector3(0, 1, 0));
                up = setFalseAndDestroy(senesteFlamme, ramte, up);
            }

            if (down)
            {
                senesteFlamme = sp.SpawnElement(bombPos + new Vector3(0, -i, 0), nedVecDec, element);
                senesteFlamme.GetComponent <Exploded> ().placer = placer;
                char ramte = ForbiddenTilesVores.CheckSquare(senesteFlamme.transform.position + new Vector3(0, -1, 0));
                down = setFalseAndDestroy(senesteFlamme, ramte, down);
            }

            if (right)
            {
                senesteFlamme = sp.SpawnElement(bombPos + new Vector3(i, 0, 0), hoejreVecDec, element);
                senesteFlamme.GetComponent <Exploded> ().placer = placer;
                char ramte = ForbiddenTilesVores.CheckSquare(senesteFlamme.transform.position + new Vector3(1, 0, 0));
                right = setFalseAndDestroy(senesteFlamme, ramte, right);
            }

            if (left)
            {
                senesteFlamme = sp.SpawnElement(bombPos + new Vector3(-i, 0, 0), venstreVecDec, element);
                senesteFlamme.GetComponent <Exploded> ().placer = placer;
                char ramte = ForbiddenTilesVores.CheckSquare(senesteFlamme.transform.position + new Vector3(-1, 0, 0));
                left = setFalseAndDestroy(senesteFlamme, ramte, left);
            }
        }
    }