Beispiel #1
0
    private bool Move(char direction, bool check, int x, int y)
    {
        GridSquare new_pos = grid.squares[x, y].GetComponent <GridSquare>();

        if (new_pos.getItem() != "empty" && new_pos.getItem() != "pit" && new_pos.getItem() != "spikes")
        {
            return(false);
        }

        if (!check)
        {
            damaged = false;

            // Slow Movements
            //print("(" + tempx + ", " + tempz + ") | (" + x_pos + ", " + z_pos + ")");
            if (x_pos - this.transform.position.x > 0.5f)
            {
                rb.velocity = new Vector3(1.95f, 0, 0);
            }
            else if (this.transform.position.x - x_pos > 0.5f)
            {
                rb.velocity = new Vector3(-1.95f, 0, 0);
            }

            if (z_pos - this.transform.position.z > 0.5f)
            {
                rb.velocity = new Vector3(0, 0, 1.95f);
            }
            else if (this.transform.position.z - z_pos > 0.5f)
            {
                rb.velocity = new Vector3(0, 0, -1.95f);
            }

            //this.transform.Translate(Vector3.forward * Time.deltaTime);

            //this.transform.position = new Vector3(x_pos, y_pos, z_pos);
            curr_pos = new_pos;

            if ((curr_pos.getItem() == "pit" || curr_pos.getItem() == "spikes") && !curr_pos.triggered)
            {
                running  = false;
                fighting = true;
                Invoke("partyStop", 0.5f);
                curr_pos.triggered = true;
                SFXHandler sfx = GameObject.Find("SFX Source").GetComponent <SFXHandler>();
                if (!NoticeCheck(curr_pos))
                {
                    takeDamage(curr_pos.item.GetComponent <TrapStats>().GetDamage());
                    LogPrint("> The party takess " + curr_pos.item.GetComponent <TrapStats>().GetDamage() + " damage!\n");
                    sfx.playSound(curr_pos.item.GetComponent <TrapStats>().GetFailureSound());
                    this.GetComponent <Renderer>().material.color = Color.red;
                    GameObject.Find("Health").GetComponent <UnityEngine.UI.Text>().text = "HP: " + HEALTH;
                    curr_pos.item.GetComponent <Animator>().SetTrigger("start");
                }
                else if (!AvoidCheck(curr_pos))
                {
                    // Pass Notice Check!
                    takeDamage(curr_pos.item.GetComponent <TrapStats>().GetDamage());
                    LogPrint("> The party takes " + curr_pos.item.GetComponent <TrapStats>().GetDamage() + " damage!\n");
                    sfx.playSound(curr_pos.item.GetComponent <TrapStats>().GetFailureSound());
                    this.GetComponent <Renderer>().material.color = Color.red;
                    GameObject.Find("Health").GetComponent <UnityEngine.UI.Text>().text = "HP: " + HEALTH;
                    curr_pos.item.GetComponent <Animator>().SetTrigger("start");
                }
                else
                {
                    // Pass Avoid Check + successfully dodge
                    sfx.playSound(curr_pos.item.GetComponent <TrapStats>().GetSuccessSound());
                    this.GetComponent <Renderer>().material.color = Color.green;
                }
            }
            else
            {
                this.GetComponent <Renderer>().material.color = Color.white;
            }
        }

        return(true);
    }
Beispiel #2
0
    public void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && !running)
        {
            if (party.Pathfind(grid.end_x, 19 - grid.end_y) == null)
            {
                return;
            }
            foreach (var square in grid.squares)
            {
                square.GetComponent <Renderer>().material = grid.floor_material;
                if (square.item_name == "spikes")
                {
                    square.item.GetComponent <Animator>().SetTrigger("reset");
                }
            }
            running = true;
        }

        if (!isTrigger && running)
        {
            this.GetComponent <Renderer>().material = grid.floor_material;
        }

        if (item_name == "enemy")
        {
            FindTriggerSquares(true);
        }
        else if (item_name != "empty" && !triggered)
        {
            FindTriggerSquares(false);
        }

        if (party == null)
        {
            party = GameObject.Find("Party(Clone)").GetComponent <PartyMovement>();
        }
        else
        {
            int party_x = 0;
            int party_y = 0;
            party.GetPos(ref party_x, ref party_y);
            foreach (var square in triggers)
            {
                //print(running);
                //Debug.Log(party_x + "," + party_y + " | " + square.x_pos + "," + square.y_pos);
                if (square.x_pos == party_x && square.y_pos == party_y && !party.damaged && running)
                {
                    //print("Triggered");
                    if (item_name != "enemy")
                    {
                        triggered      = true;
                        party.running  = false;
                        party.damaged  = true;
                        party.fighting = true;
                        Invoke("partyStop", 0.5f);
                        SFXHandler sfx = GameObject.Find("SFX Source").GetComponent <SFXHandler>();
                        if (!party.NoticeCheck(this))
                        {
                            party.takeDamage(item.GetComponent <TrapStats>().GetDamage());
                            party.LogPrint("> The party takes " + item.GetComponent <TrapStats>().GetDamage() + " damage!\n");
                            sfx.playSound(item.GetComponent <TrapStats>().GetFailureSound());
                            party.GetComponent <Renderer>().material.color = Color.red;
                            GameObject.Find("Health").GetComponent <UnityEngine.UI.Text>().text = "HP: " + party.getHealth();
                            item.GetComponent <Animator>().SetTrigger("start");
                        }
                        else if (!party.AvoidCheck(this))
                        {
                            party.takeDamage(item.GetComponent <TrapStats>().GetDamage());
                            party.LogPrint("> The party takes " + item.GetComponent <TrapStats>().GetDamage() + " damage!\n");
                            sfx.playSound(item.GetComponent <TrapStats>().GetFailureSound());
                            party.GetComponent <Renderer>().material.color = Color.red;
                            GameObject.Find("Health").GetComponent <UnityEngine.UI.Text>().text = "HP: " + party.getHealth();
                            item.GetComponent <Animator>().SetTrigger("start");
                        }
                        else
                        {
                            sfx.playSound(item.GetComponent <TrapStats>().GetSuccessSound());
                            //party.GetComponent<Renderer>().material.color = Color.green;
                        }
                    }
                    else
                    {
                        party.damaged = true;
                        Invoke("partyStop", 0.5f);
                        StartCoroutine(party.Fight(this));
                    }
                }
            }
            if (triggered)
            {
                if (!grid.firstTrap)
                {
                    GameObject.Find("PlotWindow").GetComponent <DialogueHandler>().FirstTrapDialogue();
                    grid.firstTrap = true;
                }
                foreach (var trigger in triggers)
                {
                    trigger.GetComponent <Renderer>().material.color = Color.green;
                    trigger.isTrigger = false;
                }
                triggers.Clear();
            }
        }
        if (item_name == "enemy")
        {
            FindTriggerSquares(true);
        }
        else if (item_name != "empty" && !triggered)
        {
            FindTriggerSquares(false);
        }
    }