Exemplo n.º 1
0
    void GenerateMap()
    {
        tileContainer = new Tile[mapHeight, mapWidth];
        mapDX         = mapWidth / 2;
        mapDY         = mapHeight / 2;
        for (var j = 0; j < mapHeight; j++)
        {
            for (var i = 0; i < mapWidth; i++)
            {
                int x = i - mapDX;
                int y = j - mapDY;

                float      pX         = x * tilePrefab.transform.localScale.x;
                float      pZ         = y * tilePrefab.transform.localScale.z;
                Vector3    position   = new Vector3(pX, 0.0f, pZ);
                Quaternion rotation   = new Quaternion();
                Tile       groundTile = Instantiate(tilePrefab, position, rotation, worldMap.transform) as Tile;
                groundTile.gamePosition = new Vector2i(x, y);
                groundTile.GetComponent <Renderer>().material.color = new Color(0.375f, 0.375f, 0.375f);
                groundTile.passable = terrainPassable[y + mapDY, x + mapDX];

                if (!terrainPassable[y + mapDY, x + mapDX])
                {
                    Instantiate(obstaclePrefab, groundTile.transform);
                }
                if (PersistentData.state != PersistentData.State.ExitingCombat)
                {
                    if (camps[y + mapDY, x + mapDX] > 0)
                    {
                        RecruitmentCamp camp = Instantiate(recruitmentCampPrefab, groundTile.transform);
                        camp.transform.position = position;
                        camp.SetMax(10);
                        camp.SetCurrent(5);
                        camp.gamePosition = new Vector2i(x, y);
                        recruitmentCamps.Add(camp);
                    }

                    if (monsters[y + mapDY, x + mapDX] > -1)
                    {
                        int id    = monsters[y + mapDY, x + mapDX];
                        int count = monsterGroups[id].GetGroupCount();
                        monsterGroups[id].gamePosition = new Vector2i(x, y);
                        GameObject mgPrefab = GetMonsterGroupPrefab(count);
                        GameObject mgIcon   = Instantiate(mgPrefab, groundTile.transform);
                        mgIcon.transform.localScale = new Vector3(1.0f, 10.0f, 1.0f);
                        groundTile.hasMonsters      = true;
                    }
                }

                tileContainer[y + mapDY, x + mapDX] = groundTile;
            }
        }
    }
Exemplo n.º 2
0
    void Start()
    {
        state = State.Playing;

        Creatures.PrepareCreatures();

        playerArmies = new List <Army>();
        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            MonsterGroup pa = PersistentData.playerArmy;
            for (int i = 0; i < pa.armyCount; i++)
            {
                AddSoldiers(pa.armies[i].count);
            }
            ;
        }
        else
        {
            AddSoldiers(5);
            AddSoldiers(5);
            AddSoldiers(5);
        }

        recruitmentCamps = new List <RecruitmentCamp>();

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            monsterGroups     = PersistentData.monsterGroups.ToArray();
            monsterGroupCount = PersistentData.monsterGroups.Count;
        }
        else
        {
            PrepareMonsterGroups();
        }

        GenerateMap();

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            List <SavedCamp> camps = PersistentData.recruitmentCamps;

            for (int i = 0; i < camps.Count; i++)
            {
                SavedCamp       camp  = camps[i];
                RecruitmentCamp rCamp = Instantiate(recruitmentCampPrefab, tileContainer[camp.gamePosition.y + mapDY, camp.gamePosition.x + mapDX].transform);
                rCamp.transform.position = tileContainer[camp.gamePosition.y + mapDY, camp.gamePosition.x + mapDX].transform.position;
                rCamp.SetMax(camp.max);
                rCamp.SetCurrent(camp.current);
                rCamp.gamePosition = camp.gamePosition;
                recruitmentCamps.Add(rCamp);
            }

            for (int i = 0; i < monsterGroupCount; i++)
            {
                MonsterGroup group    = monsterGroups[i];
                int          count    = group.GetGroupCount();
                GameObject   mgPrefab = GetMonsterGroupPrefab(count);
                GameObject   mgIcon   = Instantiate(mgPrefab, tileContainer[group.gamePosition.y + mapDY, group.gamePosition.x + mapDX].transform);
                mgIcon.transform.localScale = new Vector3(1.0f, 10.0f, 1.0f);
                tileContainer[group.gamePosition.y + mapDY, group.gamePosition.x + mapDX].hasMonsters = true;
            }
        }

        mainCamera = Camera.main.gameObject.GetComponent <CameraController>();
        mainCamera.SetConstraint(
            -mapWidth / 2 * tilePrefab.transform.localScale.x + 4,
            mapWidth / 2 * tilePrefab.transform.localScale.x + 4,
            5,
            5,
            -mapHeight / 2 * tilePrefab.transform.localScale.z - 3,
            mapHeight / 2 * tilePrefab.transform.localScale.z - 3
            );

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            Vector2i position = PersistentData.playerPosition;
            player.SetPosition(position.x, position.y);
        }
        else
        {
            player.SetPosition(3, -4);
        }

        pathfinder = new Pathfinder();
        pathfinder.SetTerrain(terrainPassable);

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            currentDay   = PersistentData.day;
            currentWeek  = PersistentData.week;
            currentMonth = PersistentData.month;
        }
        else
        {
            currentDay   = 1;
            currentWeek  = 1;
            currentMonth = 1;
        }

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            SetPlayerMovement(PersistentData.movementPoints);
        }
        else
        {
            SetPlayerMovement(6);
        }

        monthValue.text   = currentMonth.ToString();
        weekValue.text    = currentWeek.ToString();
        dayValue.text     = currentDay.ToString();
        weekdayValue.text = ((WeekDay)currentDay).ToString();

        if (monsterGroupCount == 0)
        {
            victory.gameObject.SetActive(true);
        }

        PersistentData.state = PersistentData.State.WorldMap;

#if UNITY_EDITOR
        DynamicGI.UpdateEnvironment();
#endif
    }