Example #1
0
 void StartTurn()
 {
     playersTurn             = true;
     remainingMovementPoints = movementPointsPerTurn;
     UIController.Instance.SetRemainingMovmentPointsTextValue(remainingMovementPoints);
     pathMap = NavigationScript.CreatePathsTreeFromStart(startingTile);
 }
Example #2
0
    IEnumerator PlayerMovement(WalkingArea selectedTile)
    {
        StartAnimatingWalk();
        moving = true;
        var path = NavigationScript.CreatePathToTarget(pathMap.paths, selectedTile);

        while (path.Count > 0 && !died)
        {
            var nextStep = path.Last();
            path.Remove(nextStep);
            while ((transform.position - nextStep.CharacterSocket.position).sqrMagnitude > 0.003f)
            {
                if (!footAudioSource.isPlaying)
                {
                    footAudioSource.PlayOneShot(footstepsClips[Random.Range(0, footstepsClips.Length)]);
                }
                PlayerPosition     = transform.position;
                transform.position = Vector2.MoveTowards(transform.position, nextStep.CharacterSocket.position, speed * Time.deltaTime);
                yield return(null);
            }
        }

        startingTile = selectedTile;
        StopWalkingAnimation();

        pathMap = NavigationScript.CreatePathsTreeFromStart(startingTile);
        moving  = false;
    }
Example #3
0
    public void AddNode(GameObject n)
    {
        NavigationScript navnode = n.GetComponent <NavigationScript>();

        nodes.Add(navnode);
        navnode.index = nodes.Count - 1;
    }
Example #4
0
    public void AddNode(GameObject n)
    {
        NavigationScript component = n.GetComponent <NavigationScript>();

        nodes.Add(component);
        component.index = nodes.Count - 1;
    }
Example #5
0
 // Use this for initialization
 void Start()
 {
     rb             = GetComponent <Rigidbody2D>();
     collider       = GetComponent <Collider2D>();
     animator       = GetComponent <Animator>();
     playerCollider = player.GetComponent <Collider2D>();
     navScript      = navMesh.GetComponent <NavigationScript>();
 }
Example #6
0
    void Start()
    {
        catRigidBody     = GetComponent <Rigidbody> ();
        isCucumberBehind = false;

        navigationScript = GetComponent <NavigationScript> ();
        gameOver         = false;
        gameCompleted    = false;
    }
Example #7
0
    public virtual IEnumerator ExecuteTurn()
    {
        bool endTurn = false;

        if (nextWaypoint == null)
        {
            nextWaypoint = waypoints.First();
        }
        StartAnimatingWalk();
        StartTurn();
        var path = NavigationScript.CreatePathToTarget(map.paths, nextWaypoint);

        while (!endTurn)
        {
            int movementPoints = remainingMovementPoints;
            yield return(StartCoroutine(CheckForAttack()));

            if (!(movementPoints == remainingMovementPoints))
            {
                StartAnimatingWalk();
            }
            var nextStep = path.Last();
            if (nextStep.IsSocketOccupied)
            {
                endTurn = true;
            }
            else
            {
                path.Remove(nextStep);
                SpendMovementPoints(map.costs[nextStep]);
                transform.localScale = new Vector3(Mathf.Sign(nextStep.CharacterSocket.position.x - transform.position.x), 1, 1);
                while ((transform.position - nextStep.CharacterSocket.position).sqrMagnitude > 0.003f)
                {
                    transform.position = Vector2.MoveTowards(transform.position, nextStep.CharacterSocket.position, speed * Time.deltaTime);
                    yield return(null);
                }
                startingTile = nextStep;
            }

            if (nextWaypoint == startingTile)
            {
                nextWaypoint = nextWaypoint == waypoints.Last() ? waypoints[0] : waypoints[waypoints.IndexOf(nextWaypoint) + 1];
                map          = NavigationScript.CreatePathsTreeFromStart(startingTile);
                path         = NavigationScript.CreatePathToTarget(map.paths, nextWaypoint);
            }
            nextStep = path.Last();

            endTurn = endTurn?true:(remainingMovementPoints - nextStep.cost) < 0;
            if (endTurn)
            {
                StopWalkingAnimation();
            }
            yield return(null);
        }
    }
Example #8
0
    void CreateMonkey()
    {
        Vector3 pos = gameObject.transform.position;

        pos.y = 0;
        GameObject       monkey = Instantiate(monkeyType, pos, Quaternion.identity) as GameObject;
        NavigationScript monkeyMovementScript = monkey.GetComponent <NavigationScript>();

        monkeyMovementScript.target = monkeyTarget.transform;

        MonkeyDeathScript monkeyDeathScript = monkey.GetComponent <MonkeyDeathScript>();

        monkeyDeathScript.player = player;

        monkey.transform.SetParent(enemyList.transform);

        HealthComponent h;

        switch (DifficultyLevel)
        {
        case 1:
            h      = monkey.GetComponent <HealthComponent>();
            h.life = 10;
            monkeyMovementScript.DamagePotential = 1;
            monkeyMovementScript.Speed           = 1f;
            interval = 2.0f;
            break;

        case 2:
            h      = monkey.GetComponent <HealthComponent>();
            h.life = 10;
            monkeyMovementScript.DamagePotential = 2;
            monkeyMovementScript.Speed           = 1f;
            interval = 1.0f;
            break;

        case 3:
            h        = monkey.GetComponent <HealthComponent>();
            h.life   = 10;
            interval = 0.5f;
            monkeyMovementScript.DamagePotential = 3;
            monkeyMovementScript.Speed           = 1f;
            break;

        default:
            Debug.Log("Impossible level!");
            break;
        }
    }
Example #9
0
    void shootCatFood()
    {
        if (cookieClone != null)
        {
            Destroy(cookieClone, 0.0f);
        }

        if (cucumberClone != null)
        {
            Destroy(cucumberClone, 0.0f);
        }

        //cookieClone = Instantiate (cookie, transform.position + 1.5f * (transform.forward), transform.rotation);
        //cookieClone.GetComponent<Rigidbody> ().AddForce (transform.forward * 3, ForceMode.Impulse);

        cookieClone = Instantiate(cookie, transform.position + 6f * (transform.forward), transform.rotation);
        //cookieClone.GetComponent<Rigidbody> ().AddForce (transform.forward * 3, ForceMode.Impulse);

        if ((navigationScript == null) && (cat != null))
        {
            navigationScript = cat.GetComponent <NavigationScript> ();
        }

        if (navigationScript != null)
        {
            navigationScript.anim.SetInteger("walkingrandom", 0);
            navigationScript.anim.SetInteger("randomwalk", 0);

            navigationScript.anim.SetInteger("calmdown", 1);
            navigationScript.anim.SetInteger("eatpickup", 0);
            navigationScript.anim.SetInteger("turnback", -1);

            navigationScript.anim.SetInteger("eatfinishraisehead", 1);
            navigationScript.anim.SetInteger("walktofood", 1);

            navigationScript.finishedEating = false;
            if (navigationScript.waitFinishEatingCR != null)
            {
                StopCoroutine(navigationScript.waitFinishEatingCR);
            }

            navigationScript.navMeshAgent.enabled = true;
            navigationScript.navMeshAgent.SetDestination(cookieClone.transform.position);
        }

        foodClip.clip = foodAudioClip;
        foodClip.Play();
    }
Example #10
0
    // Use this for initialization
    void Start()
    {
        int i = 0;

        foreach (Transform n in transform)
        {
            NavigationScript navnode = n.GetComponent <NavigationScript>();
            if (navnode != null)
            {
                nodes.Add(navnode);
                navnode.index = i;
                navnode.transform.FindChild("Speech").GetComponent <TextMesh>().text = i + "";

                i++;
            }
        }
        foreach (NavigationScript n in nodes)
        {
            n.CalcEdges();
        }
    }
Example #11
0
    void Start()
    {
        int num = 0;

        foreach (Transform item in transform)
        {
            NavigationScript component = item.GetComponent <NavigationScript>();
            if (component != null)
            {
                nodes.Add(component);
                component.index = num;
                component.transform.Find("Speech").GetComponent <TextMesh>().text = num + string.Empty;
                num++;
            }
        }
        foreach (NavigationScript node in nodes)
        {
            node.CalcEdges();
        }
        enterance = GameObject.Find("Enterance").GetComponent <NavigationScript>();
    }
Example #12
0
    void OnDrawGizmosSelected()
    {
        self = this.gameObject.GetComponent <NavigationScript>();

        if (self != null)
        {
            Gizmos.color = new Color(0.5f, 0.05f, 0.75f, 1f);
            Vector3 origin = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z);
            foreach (Transform t in self.patrolpath)
            {
                if (t == null)
                {
                    continue;
                }
                Vector3 end = new Vector3(t.position.x, t.position.y, origin.z);
                Gizmos.DrawLine(origin, t.position);
                origin = t.position;
            }
            return;
        }
    }
Example #13
0
    private void OnTileHovered(WalkingArea tile)
    {
        if (!playersTurn || moving)
        {
            return;
        }

        if (selectedTile == null || selectedTile != tile)
        {
            selectedTile = tile;
            var path = NavigationScript.CreatePathToTarget(pathMap.paths, tile);
            int remainingMovement = remainingMovementPoints;
            for (int i = path.Count - 2; i >= 0; i--)
            {
                var step = path[i];
                remainingMovement -= step.cost;

                step.rend.color = remainingMovement >= 0 ? step.reachableColor : step.unreachableColor;
            }
            UIController.Instance.SetMovementCostTextValue(pathMap.costs[selectedTile]);
        }
    }
Example #14
0
    void CreateCavalleryMonkey()
    {
        Vector3 pos = gameObject.transform.position;

        pos.y = 0;
        GameObject       monkey = Instantiate(cavalleryMonkeyType, pos, Quaternion.identity) as GameObject;
        NavigationScript monkeyMovementScript = monkey.GetComponent <NavigationScript>();

        monkeyMovementScript.target = monkeyTarget.transform;

        MonkeyDeathScript monkeyDeathScript = monkey.GetComponent <MonkeyDeathScript>();

        monkeyDeathScript.player = player;

        monkey.transform.SetParent(enemyList.transform);

        HealthComponent h = monkey.GetComponent <HealthComponent>();

        h.life = 12;
        monkeyMovementScript.DamagePotential = 1;
        monkeyMovementScript.Speed           = 2f;
        interval = 2.0f;
    }
Example #15
0
 protected virtual void StartTurn()
 {
     map = NavigationScript.CreatePathsTreeFromStart(startingTile);
     remainingMovementPoints = movementPointsPerTurn;
 }