Ejemplo n.º 1
0
    public bool Load(string mapName)
    {
        string path = GetSelectedPath(mapName);

        try
        {
            BinaryReader reader = new BinaryReader(File.OpenRead(path));
            int          header = reader.ReadInt32();
            if (header <= mapFileVersion)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
            else
            {
                Debug.LogWarning("Unknown map format " + header);
            }
        }
        catch (Exception e)
        {
            Debug.Log($"Exception - Hexmap Load file failed - {e}");
            return(false);
        }
        return(true);
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (!instance)
        {
            instance = this;
        }
        float zoomDelta = Input.GetAxis("Mouse ScrollWheel");

        if (zoomDelta != 0f)
        {
            AdjustZoom(zoomDelta);
        }

        float rotationDelta = Input.GetAxis("Rotation");

        if (rotationDelta != 0f)
        {
            AdjustRotation(rotationDelta);
        }

        float xDelta = Input.GetAxis("Horizontal");
        float zDelta = Input.GetAxis("Vertical");

        if (xDelta != 0f || zDelta != 0f)
        {
            AdjustPosition(xDelta, zDelta);
        }
    }
        private void Start()
        {
            Figures = new Figure[20, 15];

            var cellPosition = hexGrid.GetCell(new Vector3(155.8846f, -0.4045f, 30.0f)).transform.position;

            SpawnFigure(2, 8, 2, 155.8846f, -0.4045f, 30.0f);
            hexGrid.GetCell(new Vector3(155.8846f, -0.4045f, 30.0f)).Walled        = true;
            hexGrid.GetCell(new Vector3(155.8846f, -0.4045f, 30.0f)).isWallCapsule = true;
            SpawnFigure(3, 2, 13, 147.2243f, 0.8379046f, 195.0f);
            hexGrid.GetCell(new Vector3(147.2243f, 0.8379046f, 195.0f)).PlantLevel       = 3;
            hexGrid.GetCell(new Vector3(147.2243f, 0.8379046f, 195.0f)).isWallNonCapsule = true;
            camera = GameObject.Find("Hex Map Camera").GetComponent <HexMapCamera>();

            firstPlayerCounter  = 60.0f;
            secondPlayerCounter = 60.0f;

            playerOwnershipManager = hexGrid.GetComponent <PlayerOwnershipManager>();

            firstPlayerTimerbar        = GameObject.Find("First Player Timer Bar").GetComponent <ProgressBarBehaviour>();
            secondPlayerTimerbar       = GameObject.Find("Second Player Timer Bar").GetComponent <ProgressBarBehaviour>();
            firstPlayerTimerbar.Value  = 100;
            secondPlayerTimerbar.Value = 100;

            players = new Player[2] {
                new Player("first", BuildingType.WALLS), new Player("second", BuildingType.PLANTS)
            };
        }
Ejemplo n.º 4
0
 void Awake()
 {
     instance = this;
     ValidatePostion();
     swivel = transform.GetChild(0);
     stick  = swivel.GetChild(0);
 }
Ejemplo n.º 5
0
    public void SetBaseCity()
    {
        int chunk = Randomize.GetRandomInt(0, hexGridChunk.Length - 1);
        int cell  = Randomize.GetRandomInt(0, 24);

        while (hexGridChunk[chunk].cells[cell].neighbors.Length != 6)
        {
            Debug.Log("Try to find new tile");
            cell = Randomize.GetRandomInt(0, 24);
        }
        //放置城镇中心,2,0,0
        hexGrid.SetTile(hexGridChunk[chunk].cells[cell], 2, 0, 0, 1);
        hexGridChunk[chunk].cells[cell].isVisible   = true;
        hexGridChunk[chunk].cells[cell].visionField = 0;

        hexMapCamera.AdjustPosition(hexGridChunk[chunk].cells[cell].transform.localPosition);
        HexMapCamera.ValidatePostion();

        for (int i = 0; i < 6; i++)
        {
            if (hexGridChunk[chunk].cells[cell].neighbors[i].tileType == (TileType)0)
            {
                hexGrid.SetTile(hexGridChunk[chunk].cells[cell].neighbors[i], 2, 0, Randomize.GetRandomInt(1, 4), 1);
                hexGridChunk[chunk].cells[cell].neighbors[i].isVisible   = true;
                hexGridChunk[chunk].cells[cell].neighbors[i].visionField = 1;
            }
        }
    }
Ejemplo n.º 6
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        //DontDestroyOnLoad(gameObject);

        enemies          = new List <Enemy>();
        boardScript      = GetComponent <BoardManager>();
        dungeonScript    = GetComponent <DungeonManager>();
        dungeonBSPScript = GetComponent <BSPDungeonManager>();
        if (GameObject.FindGameObjectWithTag("Player"))
        {
            playerOne = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
        }
        textHandle = new TextHandle();
        textHandle.ReadFile("seeds");

        camera3D = FindObjectOfType <HexMapCamera>();


        InitGame();
    }
Ejemplo n.º 7
0
 void ShowScoutUI()
 {
     scoutUI.gameObject.SetActive(true);
     scoutUI.currentCell   = currentCell;
     scoutUI.resourcePoint = gameManager.FindResourcePoint(currentCell);
     HexMapCamera.MoveTo(currentCell);
 }
    void Start()
    {
        mapGenerator.GenerateMap(70, 60, seed);
        cellCount = 70 * 60;

        HexMapCamera.CenterPosition();

        if (isServer)
        {
            GetAvailableCells();

            do
            {
                FindTreasureCell();
            } while (!FindStartCell(40, 20));

            itemTypes.Add((int)HexItemType.Treasure);
            itemCellIndex.Add(treasureCell.Index);

            RemoveAvailableCell(serverStart);
            RemoveAvailableCell(clientStart);
            RemoveAvailableCell(treasureCell);

            SpreadKeys(10);
            SpreadItems(100);

            SendStart();
        }

        inGame = true;
    }
Ejemplo n.º 9
0
 private void OnEnable()
 {
     if (!instance)
     {
         instance = this;
     }
 }
Ejemplo n.º 10
0
 private void OnEnable()
 {
     if (!instance)
     {
         instance = this;
         ValidatePosition();
     }
 }
Ejemplo n.º 11
0
 private void Awake()
 {
     instance = this;
     ValidatePosition();
     HexMapCamera.Locked = true;
     swivel = transform.GetChild(0);
     stick  = swivel.GetChild(0);
 }
Ejemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        hexMapCamera   = FindObjectOfType <HexMapCamera>();
        attachedObject = transform.parent;
        spriteRenderer = GetComponentInChildren <SpriteRenderer>();

        regression = 1f / (upperLimit - lowerLimit);
        intercept  = 1 - regression * upperLimit;
    }
Ejemplo n.º 13
0
    public void Load()
    {
        string path = Path.Combine(Application.persistentDataPath, "test.map");

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
        {
            _hexGrid.Load(reader);
            HexMapCamera.ValidatePosition();
        }
    }
Ejemplo n.º 14
0
 public void RespawnPlayInRandomCell()
 {
     gamePlayEditor.GetComponent <HexMapEditor>();
     while (!gamePlayEditor.CreateUnit(RandomCoordinate()))
     {
         Debug.Log("Random player set up!");
         hexMapCamera = hexMapCamera.GetComponent <HexMapCamera>();
         // hexMapCamera.MovingCameraToUnit();
     }
 }
Ejemplo n.º 15
0
    void Awake()
    {
        grid = FindObjectOfType <HexGrid>();
        if (FindObjectOfType <HexGameUI>() != null)
        {
            FindObjectOfType <HexGameUI>().m_mainCamera = this;
        }
        instance = this;
        swivel   = transform.GetChild(0);
        stick    = swivel.GetChild(0);

        transform.position = m_startCameraPosition;
    }
Ejemplo n.º 16
0
 void CreateMap(int x, int z)
 {
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z);
     }
     else
     {
         hexGrid.CreateMap(x, z);
     }
     HexMapCamera.ValidatePosition();
     Close();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 创建地图
 /// </summary>
 /// <param name="x"></param>
 /// <param name="z"></param>
 void CreateMap(int x, int z)
 {
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z); // 生成随机地图
     }
     else
     {
         hexGrid.CreateMap(x, z);        // 生成默认地图
     }
     HexMapCamera.ValidatePosition();    // 验证地图边界,矫正摄像机位置
     Close();
 }
Ejemplo n.º 18
0
    public void CreateMap(int x, int z)
    {
        if (m_generateMaps)
        {
            HexMapGenerator.GenerateMap(x, z, m_wrap);
        }
        else
        {
            HexGrid.CreateMap(x, z, m_wrap);
        }

        HexMapCamera.ValidatePosition();
        Close();
    }
Ejemplo n.º 19
0
 void CreateMap(int x, int z)
 {
     //проверка способа создания карты
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z, wrapping);
     }
     else
     {
         hexGrid.CreateMap(x, z, wrapping);
     }
     HexMapCamera.ValidatePosition();
     Close();
 }
Ejemplo n.º 20
0
 void CreateMap(int x, int z)
 {
     if (generateMaps)
     {
         mapGenerator.GenerateMap(x, z);
     }
     else
     {
         hexGrid.CreateMap(x, z);
     }
     HexMapCamera.ValidatePosition();
     playMode.RespawnPlayInRandomCell();
     Close();
 }
Ejemplo n.º 21
0
    public void SetLabel(string text)
    {
        UnityEngine.UI.Text label = uiRect.GetComponent <Text>();
        label.text = text;

        float angle = HexMapCamera.GetRotationAngle() + 30f;
        int   delta = Mathf.FloorToInt(angle / 60f);

        if (delta == 6)
        {
            delta = 0;
        }

        uiRect.localRotation = Quaternion.Euler(0f, 0f, -60f * delta);
    }
Ejemplo n.º 22
0
    public void AddUnit(HexUnit unit, HexCell location)
    {
        cellShaderData.ImmediateMode = true;
        units.Add(unit);
        unit.Grid = this;
        unit.transform.SetParent(transform, false);
        unit.Location                = location;
        unit.Orientation             = Random.Range(0f, 360f);
        cellShaderData.ImmediateMode = false;

        if (unit.Owned)
        {
            HexMapCamera.SetPosition(unit.Location);
        }
    }
    void Awake()
    {
        instance            = this;
        followingGameObject = false;
        swivel = transform.GetChild(0);
        stick  = swivel.GetChild(0);

        if (isOrthographic)
        {
            camera.orthographic = true;
        }
        else
        {
            camera.orthographic = false;
        }
    }
Ejemplo n.º 24
0
    private void Awake()
    {
        _swivel = transform.GetChild(0);
        _stick  = _swivel.GetChild(0);

        // TODO: check if removing the null check breaks the logic, HexMapCameraInstance != null
        if (HexMapCameraInstance)
        {
            Destroy(gameObject);
        }
        else
        {
            HexMapCameraInstance = this;
        }

        _mainCamera = GetComponentInChildren <Camera>();
    }
    void Load(string pathp)
    {
        if (!File.Exists(pathp))
        {
            path = null;
            return;
        }

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
            int header = reader.ReadInt32();
            if (header <= 1)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
        }
    }
Ejemplo n.º 26
0
    public void Load()
    {
        string path = Path.Combine(Application.persistentDataPath, "test.map");

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
            int header = reader.ReadInt32();

            if (header <= 1)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
            else
            {
                Debug.LogWarning("Unknown map format " + header);
            }
        }
    }
        public IEnumerator CheckValidateCameraPosition()
        {
            SceneManager.LoadScene("Scene", LoadSceneMode.Single);
            yield return(new WaitForSeconds(1.0f));

            goA = SceneManager.GetActiveScene().GetRootGameObjects();
            GameObject Camera = goA[2];

            HexMapCamera.ValidatePosition();
            Assert.AreEqual(Camera.gameObject.transform.localPosition, new Vector3(0f, 0f, 0f));

            foreach (GameObject g in goA)
            {
                GameObject.Destroy(g);
            }
            GameObject.Destroy(Camera);
            SceneManager.UnloadScene("Scene");
        }
Ejemplo n.º 28
0
    public void Load()
    {
        DirectoryInfo info = new DirectoryInfo(Application.dataPath);
        string        path = Path.Combine(info.ToString() + "/Maps", "test.map");

        using (BinaryReader reader = new BinaryReader(File.OpenRead(path)))
        {
            int header = reader.ReadInt32();
            if (header <= HexMapEditor.mapVersion)
            {
                hexGrid.Load(reader, header);
                HexMapCamera.ValidatePosition();
            }
            else
            {
                Debug.LogWarning("Unknown map format " + header);
            }
        }
    }
 void Load(string path)
 {
     if (!File.Exists(path))
     {
         Debug.LogError("File does not exist " + path);
         return;
     }
     using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) {
         int header = reader.ReadInt32();
         if (header <= mapFileVersion)
         {
             hexGrid.Load(reader, header);
             HexMapCamera.ValidatePosition();
         }
         else
         {
             Debug.LogWarning("Unknown map format " + header);
         }
     }
 }
Ejemplo n.º 30
0
    public void UseItem(HexItemType type)
    {
        switch (type)
        {
        case HexItemType.Poison:
            otherUnit.SpeedEffect(-20, 3);
            SendEffect(HexItemType.Poison);
            break;

        case HexItemType.FakeTreasureItem:
            AddItem(HexItemType.FakeTreasure, myUnit.Location);
            SendItem(HexItemType.FakeTreasure, myUnit);
            break;

        case HexItemType.Change:
            grid.changeUnits();
            HexMapCamera.SetPosition(myUnit.Location);
            SendEffect(HexItemType.Change);
            break;
        }
    }