Example #1
0
    // Update is called once per frame
    void Update()
    {
        switch (currentState)
        {
        case GameState.StandBy:
            break;

        case GameState.Idle:
            if (!Cooldown)
            {
                temporal = cursorCoords;
                //Debug.Log(temporal.x + " " + temporal.y);
                //Debug.Log(cursorCoords.x + " " + cursorCoords.y);
                //Debug.Log("Idle");
                //if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A)) CursorMove("DUpLeft");
                //else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D)) CursorMove("DUpRight");
                //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D)) CursorMove("DDownRight");
                //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A)) CursorMove("DDownLeft");
                if (Input.GetKey(KeyCode.A))
                {
                    CursorMove("Left");
                }
                else if (Input.GetKey(KeyCode.W))
                {
                    CursorMove("Up");
                }
                else if (Input.GetKey(KeyCode.D))
                {
                    CursorMove("Right");
                }
                else if (Input.GetKey(KeyCode.S))
                {
                    CursorMove("Down");
                }

                Invoke("ResetCoodldown", 0.10f);
                Cooldown = true;
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                SetStateStandBy();
                //for(int i = 0; i <= 1000; i++) {Debug.Log(i);}
                combatControllerScript.EndTurn();
            }
            break;

        case GameState.PlayerMovement:
            //Debug.Log(position.x + " " + position.y);
            temporal = cursorCoords;
            if (!Cooldown)
            {
                //Debug.Log("PlayerMovement");
                //Debug.Log(playerCoords.Difference(cursorCoords.Add(new Utility.Coord(-1,0))));
                //Debug.Log(playerCoords.x + " " + playerCoords.y);
                //Debug.Log(temporal.x + " " + temporal.y);
                //Debug.Log(cursorCoords.x + " " + cursorCoords.y);
                //if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A)) CursorMove("DUpLeft");
                //else if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D)) CursorMove("DUpRight");
                //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D)) CursorMove("DDownRight");
                //else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A)) CursorMove("DDownLeft");
                (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(-1, 0)))).getType();
                if (Input.GetKey(KeyCode.A) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(-1, 0)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(-1, 0))) <= maxplayerDistance)
                {
                    //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0))));
                    CursorMove("Left");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }

                else if (Input.GetKey(KeyCode.W) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(0, 1)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, 1))) <= maxplayerDistance)
                {
                    //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0))));
                    CursorMove("Up");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }

                else if (Input.GetKey(KeyCode.D) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(1, 0)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(1, 0))) <= maxplayerDistance)
                {
                    //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0))));
                    CursorMove("Right");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }

                else if (Input.GetKey(KeyCode.S) && (mapGeneratorScript.getTile(cursorCoords.Add(new Utility.Coord(0, -1)))).getType() != 2 && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, -1))) <= maxplayerDistance)
                {
                    //Debug.Log(playerCoords.Difference(position.Add(new Utility.Coord(-1,0))));
                    //Debug.Log("MAX IS: "+ maxplayerDistance);
                    CursorMove("Down");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }
            }

            if (Input.GetKeyDown(KeyCode.Alpha1) && !cursorCoords.Equals(playerCoords))
            {
                //Debug.Log("Moving here!");
                movePlayer();
                goBack();
            }

            if (Input.GetKey(KeyCode.Q))
            {
                goBack();
            }
            if (Input.GetKey(KeyCode.Space))
            {
                SetStateStandBy();
                combatControllerScript.EndTurn();
            }
            break;

        case GameState.PlayerAttack:
            temporal = cursorCoords;
            if (!Cooldown)
            {
                //Debug.Log("PlayerAttack");

                //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(-1,0))));
                //Debug.Log(playerCoords.x + " " + playerCoords.y);
                //Debug.Log(temporal.x + " " + temporal.y);
                //Debug.Log(cursorCoords.x + " " + cursorCoords.y);

                if (Input.GetKey(KeyCode.A) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(-1, 0))) <= maxAttackRange)
                {
                    //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(-1,0))));
                    CursorMove("Left");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }

                else if (Input.GetKey(KeyCode.W) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, 1))) <= maxAttackRange)
                {
                    //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(0,1))));
                    CursorMove("Up");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }

                else if (Input.GetKey(KeyCode.D) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(1, 0))) <= maxAttackRange)
                {
                    //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(1,0))));
                    CursorMove("Right");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }

                else if (Input.GetKey(KeyCode.S) && playerCoords.Difference(cursorCoords.Add(new Utility.Coord(0, -1))) <= maxAttackRange)
                {
                    //Debug.Log(playerCoords.Difference(temporal.Add(new Utility.Coord(0,-1))));
                    CursorMove("Down");
                    Invoke("ResetCoodldown", 0.10f);
                    Cooldown = true;
                }
            }

            if (Input.GetKeyDown(KeyCode.Alpha2) && cursorCoords.Equals(enemyCoords))
            {
                Debug.Log("Attack: 1d20 + bab + strengthMod");
                playerScript.MeleeAttack(enemyScript);
                goBack();
            }

            if (Input.GetKey(KeyCode.Q))
            {
                goBack();
            }
            if (Input.GetKey(KeyCode.Space))
            {
                SetStateStandBy();
                combatControllerScript.EndTurn();
            }
            break;
        }
    }