// Update is called once per frame
    void Update()
    {
        CheckTurn();

        if (isPlayerTurn)
        {
            if (cursorCoords.Equals(playerCoords))
            {
                //Debug.Log("ON THE OBJECTIVE");
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    Debug.Log("TIME TO MOVE, BOYS!");
                    int playerSpeed = playerScript.getSpeed();
                    //(showPlayerMovementArea(playerSpeed/5);
                    cursorScript.SetStatePlayerMovement(playerSpeed);
                    cursorScript.SetPlayerPosition(playerCoords, playerScript);
                    //Debug.Log(playerName);
                }

                else if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    Debug.Log("TIME TO ATTACK, BOYS!");
                    int playerRange = playerScript.getRange();
                    cursorScript.SetStatePlayerAttack(playerRange);
                    cursorScript.SetPlayerPosition(playerCoords, playerScript);
                    cursorScript.SetEnemyPosition(enemyCoords, enemyScript);
                }
            }
        }
    }
Example #2
0
    private void InstantiateEnemies()
    {
        bool found = false;

        while (!found)
        {
            enemyCoords = GetRandomCoord();
            tileclass   = map[enemyCoords.x, enemyCoords.y].GetComponent <TileClass>();
            if (tileclass.getType() != 2 && !enemyCoords.Equals(playerCoords))
            {
                Enemy1.localScale = new Vector3(1.8f, 1.8f, 1.8f);
                Transform enemy1 = (Transform)Instantiate(Enemy1, CoordToPosition(enemyCoords.x, enemyCoords.y), Quaternion.Euler(Vector3.right * 90)) as Transform;
                found = true;
                combatControllerScript.addEnemy(enemyCoords, enemy1.name, enemy1);
                //Debug.Log("Enemy position is "+enemyCoords.x+" "+enemyCoords.y);
            }
        }
    }
Example #3
0
    private void GenerateMap()
    {
        roughTerrainPercent = Random.Range(0f, 1f);
        wallPercent         = Random.Range(0f, 1f);

        mapSize.x = Random.Range(10, 20);
        mapSize.y = Random.Range(10, 20);


        //Creating List of tiles
        allTileCoords = new List <Utility.Coord> ();

        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                allTileCoords.Add(new Utility.Coord(x, y));
            }
        }

        shuffledTileCoords = new Queue <Utility.Coord>(Utility.ShuffleArray(allTileCoords.ToArray()));


        //Populating map with tiles
        string holderName = "Generated Map";

        if (transform.FindChild(holderName))
        {
            Destroy(transform.FindChild(holderName).gameObject);
        }

        Transform mapHolder = new GameObject(holderName).transform;

        mapHolder.parent = transform;


        map = new GameObject[(int)mapSize.x, (int)mapSize.y];

        playerCoords = GetRandomCoord();

        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                Vector3 tilePosition = new Vector3(-mapSize.x / 2 + 0.5f + x, 0, -mapSize.y / 2 + 0.5f + y);

                //Rough Terrain
                if (Random.value < roughTerrainPercent)
                {
                    Transform newTile = (Transform)Instantiate(DirtPlants1Tile, tilePosition, Quaternion.Euler(Vector3.right * 90));
                    newTile.localScale = new Vector3(5, 5, 5) * (1 - outlinePercent);
                    newTile.parent     = mapHolder;
                    GameObject tile = newTile.gameObject;
                    map[x, y] = tile;
                    tileclass = map[x, y].GetComponent <TileClass>();
                    tileclass.setType(1);
                    tileclass.setPos(tilePosition);
                    //Debug.Log(tileclass.getPos());
                }

                //Basic Terrain
                else
                {
                    Transform newTile = (Transform)Instantiate(Dirt1Tile, tilePosition, Quaternion.Euler(Vector3.right * 90));
                    newTile.localScale = new Vector3(5, 5, 5) * (1 - outlinePercent);
                    newTile.parent     = mapHolder;
                    GameObject tile = newTile.gameObject;
                    map[x, y] = tile;
                    tileclass = map[x, y].GetComponent <TileClass>();
                    tileclass.setType(0);
                    tileclass.setPos(tilePosition);
                    //Debug.Log(tileclass.getType());
                }
            }
        }

        //Walls
        bool[,] wallMap = new bool[(int)mapSize.x, (int)mapSize.y];

        int wallCount        = (int)(mapSize.x * mapSize.y * wallPercent);
        int currentWallCount = 0;

        for (int i = 0; i < wallCount; i++)
        {
            Utility.Coord randomCoord = GetRandomCoord();
            wallMap[randomCoord.x, randomCoord.y] = true;
            currentWallCount++;

            //Wall
            if (MapIsFullyAccessible(wallMap, currentWallCount) && !playerCoords.Equals(randomCoord))
            {
                Vector3 wallPosition = CoordToPosition(randomCoord.x, randomCoord.y);
                wallPosition = wallPosition + new Vector3(0, 0.001f, 0);

                Transform newTile = (Transform)Instantiate(DirtRock1Tile, wallPosition, Quaternion.Euler(Vector3.right * 90));
                newTile.localScale = new Vector3(5, 5, 5) * (1 - outlinePercent);
                newTile.parent     = mapHolder;
                GameObject tile = newTile.gameObject;
                map[randomCoord.x, randomCoord.y] = tile;
                tileclass = tile.GetComponent <TileClass>();
                tileclass.setType(2);
                tileclass.setPos(wallPosition);
                //Debug.Log(tileclass.coverType);
                wallMap[randomCoord.x, randomCoord.y] = true;
            }
            else
            {
                wallMap[randomCoord.x, randomCoord.y] = false;
                currentWallCount--;
            }
        }
    }
Example #4
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;
        }
    }