コード例 #1
0
ファイル: BattleMap.cs プロジェクト: fernandGP/HexBattleGame
    void InitializeAgents()
    {
        GameObject        go;
        GameCharacter     agent;
        List <Vector2Int> spawntiles;

        int[] spawnIndex = new int[] { -1, -1, -1, -1 };
        int   factionID;

        // Randomly shuffle the spawnList in-place to give enemies a spawn position
        for (int i = 0; i < spawnableTiles_.Count; i++)
        {
            Utils.FisherYatesShuffle <Vector2Int>(spawnableTiles_[i]);
        }


        for (int i = 0; i < battleUnits_.Count; i++)                                    // Place the agents on the battleMap
        {
            agent = battleUnits_[i];
            go    = agent.GameObject();

            factionID = agent.FactionID;
            factions[factionID][agent.ID] = true;
            spawntiles = spawnableTiles_[factionID];

            agent.InGamePosition  = spawntiles[++spawnIndex[factionID]];
            go.transform.position = HexCalculator.CharacterPosition(spawntiles[spawnIndex[factionID]]);

            mapTiles[spawntiles[spawnIndex[factionID]]].Occupier = agent;
        }
    }
コード例 #2
0
    void Move(int dir)
    {
        // First, check if movement is possible
        // - Does the destination tile exist?
        // - Is it free?
        HexTile destinationTile;
        Vector2Int destination;

        if (BattleMap_.mapTiles[InGamePosition].Neighbors.TryGetValue(dir, out destinationTile))
        {
            if (!destinationTile.Occupied)
            {
                destination = destinationTile.Position;

                Vector3 igPosition = HexCalculator.CharacterPosition(destination);
                gameObject.GetComponent <Rigidbody>().position = igPosition;
                gameObject.transform.position = igPosition;

                BattleMap_.mapTiles[InGamePosition].EmptyTile();

                InGamePosition           = destination;
                destinationTile.Occupier = this;

                return;
            }
        }

        // Position at dir has no tile to move at!
        // Position at dir is occupied!
        AddReward(-0.5f);
    }
コード例 #3
0
    void Move(int dir)
    {
        // First, check if movement is possible
        // - Does the destination tile exist?
        // - Is it free?
        HexTile destinationTile;
        Vector2Int destination;

        if (BattleMap_.mapTiles[InGamePosition].Neighbors.TryGetValue(dir, out destinationTile))
        {
            if (!destinationTile.Occupied)
            {
                destination = destinationTile.Position;

                Vector3 igPosition = HexCalculator.CharacterPosition(destination);
                gameObject.GetComponent <Rigidbody>().position = igPosition;
                gameObject.transform.position = igPosition;

                BattleMap_.mapTiles[InGamePosition].EmptyTile();

                InGamePosition           = destination;
                destinationTile.Occupier = this;

                // Give a reward based on distance towards closest predator
                // This will encourage the agent to stay away from predators even if it does not
                // have a chance to live in the long run. ALSO, encourages him to move

                // The bigger the distance, the bigger the reward
                //AddReward(DistanceTowardsClosestPredator() / 10);

                return;
            }
        }

        // Position at dir has no tile to move at!
        // Position at dir is occupied!
        AddReward(-0.5f);
    }