示例#1
0
        public void Init(HexaTile tile)
        {
            m_tile             = tile;
            m_tile.data.animal = this;

            m_renderer = GetComponent <SpriteRenderer>();

            m_type = (Random.Range(0, 100) >= 0) ? TYPE.HAWK : TYPE.OWL;

            m_renderer.sprite = Map.Instance.GetAnimalSprite(m_type);

            if (m_type == TYPE.HAWK)
            {
                m_renderer.sortingLayerName = Constantes.DIURNO;
                Map.Instance.AddNewDayElement(this);
            }
            else
            {
                m_renderer.sortingLayerName = Constantes.NOTURNO;
                Map.Instance.AddNewNightElement(this);
            }

            transform.localPosition = tile.data.POSITION;

            gameObject.SetActive(true);
        }
示例#2
0
        public void Restore(HexaTile tile)
        {
            m_tiles.Enqueue(tile);

            tile.gameObject.SetActive(false);
            tile.transform.SetParent(transform);
        }
示例#3
0
文件: Gui.cs 项目: raimis001/brsd2015
    public void repairTile()
    {
        if (selected == null)
        {
            return;
        }
        HexaTile tile = ShipData.mainShip.GetTile(selected);

        if (tile == null || tile.device.hpCurrent >= tile.device.hpMax)
        {
            return;
        }

        int price = tile.RepairPrice();

        if (ShipData.metals < price)
        {
            AddMessage("Pietrukst metala");
            return;
        }

        ShipData.addMetals(-price);
        tile.Repair();

        tileDamage.text     = tile.device.hpCurrent.ToString("0") + "/" + tile.device.hpMax.ToString("0");
        tileRepairText.text = tile.RepairPrice().ToString();

        selected = selected;
    }
示例#4
0
    public HexaTile GetTile(string index)
    {
        HexaTile tile = null;

        tileSet.TryGetValue(index, out tile);
        return(tile);
    }
示例#5
0
        public void SetType(HexaTile tile)
        {
            m_tile = tile;
            m_tile.data.obstacle = this;

            m_type = (Random.Range(0, 100) > 50) ? HexaTile.TYPE.TREE : HexaTile.TYPE.ROCK;

            transform.localPosition = m_tile.data.POSITION;

            switch (m_type)
            {
            case HexaTile.TYPE.TREE:
                m_sonarInfos.sprite = Map.Instance.GetSonarSprite(5);
                break;

            case HexaTile.TYPE.ROCK:
                m_sonarInfos.sprite = Map.Instance.GetSonarSprite(4);
                break;
            }

            m_renderer        = GetComponent <SpriteRenderer>();
            m_renderer.sprite = Map.Instance.GetSprite(m_type);

            gameObject.SetActive(true);
        }
示例#6
0
    public void recalcEnergy()
    {
        if (device == null || device.energyProduce < 1 || key == null || key.AllNeighbours == null || key.Count < 1)
        {
            return;
        }

        int cnt = 0;

        foreach (TilePoint point in key.AllNeighbours)
        {
            HexaTile tile = key.ship.GetTile(point.index);
            if (tile != null && tile.device.energyNeed > 0)
            {
                cnt++;
            }
        }
        if (cnt > 0)
        {
            int en = device.energyProduce / cnt;
            foreach (TilePoint point in key.AllNeighbours)
            {
                HexaTile tile = key.ship.GetTile(point.index);
                if (tile != null && tile.device.energyNeed > 0)
                {
                    tile.device.energyCurrent += en;
                }
            }
        }
    }
示例#7
0
    public void Setup(int[] numbers)
    {
        Debug.Assert(tiles != null);

        if (numbers == null)
        {
            Clear();

            return;
        }

        for (int i = 0, max = Mathf.Min(tiles.Length, numbers.Length); i < max; ++i)
        {
            HexaTile tile = tiles[i];
            if (tile != null)
            {
                NumberedHexaCell cell = null;
                if (numbers[i] > 0)
                {
                    cell = GameManager.instance.GenerateHexaCell() as NumberedHexaCell;
                    if (cell != null)
                    {
                        cell.Setup(numbers[i]);
                    }
                }

                tile.SetCell(cell);
            }
        }

        _highestNumber = GetCurrentHighestNumberOnBoard();

        _combineEffectBuffer.Withdraw();
        _explodeEffectBuffer.Withdraw();
    }
示例#8
0
文件: Gui.cs 项目: raimis001/brsd2015
    public void SetSelected(string oldValue)
    {
        if (oldValue != null)
        {
            ShipData.mainShip.SetSelected(oldValue, false);
        }

        if (selected != null)
        {
            buildPanel.SetActive(false);
            ShipData.mainShip.SetSelected(selected, true);
            selectedPanel.SetActive(true);
            tileDamage.gameObject.SetActive(true);
            tileEnergy.gameObject.SetActive(true);


            HexaTile tile = ShipData.mainShip.GetTile(selected);
            blankPanel.SetActive(tile.device.id == 0);
            devicePanel.SetActive(tile.device.id != 0);
            deviceImage.sprite = deviceSprites[tile.device.id];
            deviceName.text    = ShipData.devices[tile.device.id].name;

            foreach (GuiUpgrade obj in upgrades)
            {
                if (tile.device.upgrades.ContainsKey(obj.gameObject.name))
                {
                    obj.value.text = tile.valueByName(obj.gameObject.name);

                    if (tile.device.upgrades[obj.gameObject.name].level <= 3)
                    {
                        obj.price.text = tile.device.upgrades[obj.gameObject.name].price.ToString();
                        obj.label.text = tile.device.upgrades[obj.gameObject.name].label;
                        obj.button.gameObject.SetActive(true);
                    }
                    else
                    {
                        obj.button.gameObject.SetActive(false);
                    }


                    obj.gameObject.SetActive(true);
                }
                else
                {
                    obj.gameObject.SetActive(false);
                }
            }
        }
        else
        {
            tileDamage.gameObject.SetActive(false);
            tileEnergy.gameObject.SetActive(false);
            selectedPanel.SetActive(false);
            if (_gameMode == 0)
            {
                buildPanel.SetActive(true);
            }
        }
    }
    /// <summary>
    /// The step distance between the hexatiles a and b.
    /// </summary>
    /// <returns>The distance.</returns>
    /// <param name="a">The first tile.</param>
    /// <param name="b">The second tile.</param>
    public static double StepDistance(HexaTile a, HexaTile b)
    {
        int     diffX     = a.x - b.x;
        int     diffY     = a.y - b.y;
        Vector3 dummyZDif = HexaTile.DummyZ(diffX, diffY);

        return(Mathf.Abs(dummyZDif.x) + Mathf.Abs(dummyZDif.y) + Mathf.Abs(dummyZDif.z));
    }
示例#10
0
    public void SetSelected(string index, bool selected)
    {
        HexaTile tile = null;

        tileSet.TryGetValue(index, out tile);
        if (tile != null)
        {
            tile.setSelected(selected);
        }
    }
示例#11
0
    public Vector3 Vector()
    {
        HexaTile tile = ship.GetTile(index);

        if (tile == null)
        {
            return(Vector3.zero);
        }
        return(tile.transform.position);
    }
示例#12
0
    private bool createTile(int x, int y, int tileID, bool check = false, DeviceData device = null)
    {
        TilePoint key = new TilePoint(x, y);

        if (tileSet.ContainsKey(key.index))
        {
            Debug.Log("Existing index " + key.index);
            return(false);
        }
        key.ship = this;

        Vector2 hexpos = ShipData.HexOffset(x, y);

        GameObject obj = Instantiate(ShipData.tileResource, new Vector3(hexpos.x + transform.position.x, hexpos.y + transform.position.y), Quaternion.identity) as GameObject;

        obj.transform.parent = this.transform;
        obj.tag = type;
        HexaTile src = obj.GetComponent <HexaTile>();

        src.tileID = tileID;
        src.key    = key;
        src.createDevice(tileID);

        if (device != null)
        {
            src.device.UpdateData(device);
        }

        tileSet.Add(key.index, src);
        if (tileID == 1)
        {
            zero = src.key;
        }

        if (!check)
        {
            return(true);
        }

        RecalcShip();

        if (src.connected)
        {
            RecalcEnergy();
            return(true);
        }

        tileSet.Remove(src.key.index);
        Destroy(obj);

        RecalcShip();
        RecalcEnergy();

        return(false);
    }
示例#13
0
 public virtual void Initialize()
 {
     for (int i = 0, max = _tiles.Length; i < max; ++i)
     {
         HexaTile tile = _tiles[i];
         if (tile != null)
         {
             tile.Initialize();
         }
     }
 }
示例#14
0
    public bool Working()
    {
        HexaTile tile = ship.GetTile(index);

        if (tile == null)
        {
            return(false);
        }

        return(tile.device.energyCurrent >= tile.device.energyNeed);
    }
示例#15
0
    IEnumerator ProcessHammer()
    {
        transition = Transition.Hammer;

        _board.ActiveHammerIcons(true);

        yield return(new WaitForSeconds(0.1f));

        NumberedHexaTile targetTile   = null;
        Action <Vector3> onSelectTile = screenPosition => {
            RaycastHit2D hit = Physics2D.Raycast(
                _cachedMainCamera.ScreenToWorldPoint(screenPosition),
                Vector3.zero,
                Mathf.Infinity,
                1 << GameManager.TILE_LAYER
                );

            if (hit.collider != null)
            {
                HexaTile tile = hit.collider.GetComponent <HexaTile>();
                if (tile.cell != null)
                {
                    targetTile = tile as NumberedHexaTile;
                }
            }
        };

        SingleTouchManager.instance.onUntouched += onSelectTile;

        while (targetTile == null)
        {
            yield return(new WaitForEndOfFrame());
        }

        _board.ActiveHammerIcons(false);

        if (onUseItem != null)
        {
            onUseItem(ItemType.BREAK);
        }

        NumberedHexaCell cell = targetTile.cell as NumberedHexaCell;

        cell.gameObject.LeanScale(Vector3.zero, _destroyCellTime)
        .setEaseInBack();

        SoundManager.Instance.PlayUISoundInstance(GameConstants.FX_USE_HAMMER);

        yield return(new WaitForSeconds(_destroyCellTime));

        targetTile.Reset();

        transition = Transition.None;
    }
示例#16
0
    public bool DeleteDevice(string index)
    {
        HexaTile tile   = tileSet[index];
        bool     result = tile.deleteDevice();

        if (result)
        {
            RecalcEnergy();
        }

        return(result);
    }
示例#17
0
    IEnumerator ProcessContinue()
    {
        bool opened   = true;
        bool rewarded = false;

        Action onRewarded = () => {
            opened   = false;
            rewarded = true;
        };

        Action onCanceled = () => {
            opened = false;
        };

        Dictionary <string, object> continueArgs = new Dictionary <string, object>()
        {
            { PopupContinue.PARAM_REWARDED_CALLBACK, onRewarded },
            { PopupContinue.PARAM_CANCEL_CALLBACK, onCanceled }
        };

        StateManager.instance.PushState(GameConstants.STATENAME_POPUPCONTINUE, continueArgs);

        while (opened || StateManager.instance.nowTransitioning)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (rewarded)
        {
            ++_contineCount;

            _snapshots.Clear();

            HexaTile[] tiles = Array.FindAll(
                GameManager.instance.board.tiles,
                t => t != null && Array.TrueForAll(t.neighbors, n => n != null)
                );

            int      targetIndex = Random.Range(0, tiles.Length);
            HexaTile seed        = tiles[targetIndex];

            yield return(GameManager.instance.board.Explode(
                             seed,
                             GameManager.instance.maxContinueExplodeRadius,
                             GameConstants.HIGHEST_CELL_NUMBER));

            GameManager.instance.NewBlockCellNumbers();
        }
        else
        {
            OnShowResult();
        }
    }
示例#18
0
        public void SetInitialTile(HexaTile tile)
        {
            m_tile = tile;

            m_tile.data.bat = this;

            m_wing.Play(true);

            InGameUI.Instance.SetLives(life);
            InGameUI.Instance.SetFood(m_foods);

            transform.localPosition = m_tile.transform.localPosition;
        }
示例#19
0
    public void DeleteTile(string index, bool destroy = false)
    {
        HexaTile tile     = tileSet[index];
        int      deviceId = tile.tileID;

        tileSet.Remove(index);
        tile.Demolish(destroy, false);

        List <HexaTile> rec = new List <HexaTile>();

        foreach (HexaTile t in tileSet.Values)
        {
            t.Reconnect(index);
            rec.Add(t);
        }

        foreach (HexaTile t in rec)
        {
            t.pathToZero();
        }

        if (!destroy)
        {
            RecalcEnergy();
            return;
        }

        if (deviceId == 1)
        {
            DestroyShip();
            return;
        }

        List <string> ind = new List <string>();

        foreach (HexaTile t in tileSet.Values)
        {
            if (!t.connected)
            {
                ind.Add(t.key.index);
            }
        }

        foreach (string idx in ind)
        {
            tileSet[idx].Demolish(true, true);
            tileSet.Remove(idx);
        }
        RecalcEnergy();
    }
示例#20
0
文件: Gui.cs 项目: raimis001/brsd2015
    public void upgradeDevice(string param)
    {
        if (selected == null)
        {
            return;
        }

        HexaTile tile = ShipData.mainShip.GetTile(selected);

        tile.ugradeDevice(param);

        ShipData.mainShip.RecalcEnergy();

        selected = selected;
    }
示例#21
0
    void SetTile(Queue <HexaTile> buffer, Vector3 position, int x, int y)
    {
        HexaTile tile = (buffer.Count > 0) ? buffer.Dequeue() : Instantiate(_tilePrefab);

        tile.gameObject.layer = LayerMask.NameToLayer("Tile");
        tile.transform.SetParent(transform);
        tile.transform.localScale    = Vector3.one;
        tile.transform.localRotation = Quaternion.identity;
        tile.transform.localPosition = position;

        tile.SetCoords(x, y);
        tile.AddCollier();

        _tiles[y * _boardWidth + x] = tile;
    }
示例#22
0
    IEnumerator CombineTypeA(Stack <CombineInfo> linkedTileInfos)
    {
        HexaTile seed = linkedTileInfos.ToArray()[linkedTileInfos.Count - 1].tile;
        Vector3  to   = seed.transform.position + CELL_MOVE_OFFSET;

        while (linkedTileInfos.Count > 1)
        {
            NumberedHexaTile linkedTile = linkedTileInfos.Pop().tile;
            HexaCell         cell       = linkedTile.cell;
            Vector3          from       = cell.transform.position + CELL_MOVE_OFFSET;
            cell.LeanMove(from, to, _cellCombineDuration).
            setEaseInBack().
            setOnComplete(() => linkedTile.Reset());
        }

        SoundManager.Instance.PlayUISoundInstance(GameConstants.FX_CELL_COMBINING);

        yield return(new WaitForSeconds(_cellCombineDuration));
    }
示例#23
0
        private IEnumerator Move(HexaTile tile)
        {
            float lerp = 0.0f;

            while (lerp < 1.0f)
            {
                lerp += Time.deltaTime * m_speed;

                transform.position = Vector3.Lerp(m_tile.data.POSITION, tile.data.POSITION, lerp);

                yield return(null);
            }

            m_tile.data.animal = null;
            m_tile             = tile;
            m_tile.data.animal = this;

            Act();
        }
示例#24
0
    public IEnumerator Explode(HexaTile seed, int radius, params int[] ignoreNumbers)
    {
        NumberedHexaTile[] targetTiles = FindExplodeTiles(seed, Mathf.Max(0, radius - 1), ignoreNumbers);

        for (int i = 0, max = targetTiles.Length; i < max; ++i)
        {
            NumberedHexaTile targetTile = targetTiles[i];
            targetTile.Explode(0.5f);

            ParticleSystem explodeEffect = _explodeEffectBuffer.Pop();
            explodeEffect.transform.position =
                targetTile.transform.position + Vector3.back * 0.15f;
            explodeEffect.Play();
        }

        yield return(new WaitForSeconds(0.5f));

        SoundManager.Instance.PlayUISoundInstance(GameConstants.FX_CELL_EXPLODE);

        yield return(new WaitForSeconds(0.2f));
    }
示例#25
0
        private IEnumerator MoveToTile(HexaTile tile)
        {
            Game.update -= CustomUpdate;

            float lerp = 0.0f;

            while (lerp <= 1.0f)
            {
                lerp += Time.deltaTime * m_speed;

                transform.localPosition = Vector2.Lerp(m_tile.data.POSITION, tile.data.POSITION, lerp);

                yield return(null);
            }

            m_tile.data.bat = null;
            m_tile          = tile;
            m_tile.data.bat = this;

            FinishAction();
        }
示例#26
0
    void LinkFlatTiles()
    {
        for (int i = 0; i < _boardHeight; ++i)
        {
            for (int j = 0; j < _boardWidth; ++j)
            {
                HexaTile tile = GetTile(j, i);
                if (tile != null)
                {
                    int y = i - Mathf.Abs((j % 2) - 1);

                    tile.SetNeighbor(0, GetTile(j + 0, i - 1));
                    tile.SetNeighbor(1, GetTile(j - 1, y + 0));
                    tile.SetNeighbor(2, GetTile(j - 1, y + 1));
                    tile.SetNeighbor(3, GetTile(j + 0, i + 1));
                    tile.SetNeighbor(4, GetTile(j + 1, y + 1));
                    tile.SetNeighbor(5, GetTile(j + 1, y + 0));
                }
            }
        }
    }
示例#27
0
        public void CustomUpdate()
        {
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                RaycastHit2D raycastHit2D = Physics2D.CircleCast(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.1f, Constantes.FOWARD, float.MaxValue, 1 << 8);

                if (raycastHit2D.collider != null)
                {
                    HexaTile tile = raycastHit2D.collider.GetComponent <HexaTile>();

                    if (tile.data.indexX != m_tile.data.indexX || tile.data.indexY != m_tile.data.indexY)
                    {
                        if (tile.data.indexX >= m_tile.data.indexX - m_range && tile.data.indexX <= m_tile.data.indexX + m_range)
                        {
                            if (tile.data.indexY >= m_tile.data.indexY - m_range && tile.data.indexY <= m_tile.data.indexY + m_range)
                            {
                                if (tile.data.obstacle == null)
                                {
                                    StartCoroutine(MoveToTile(tile));
                                }
                            }
                            else
                            {
#if UNITY_EDITOR
                                Debug.Log("Clicou Longe");
                                Debug.Log("COLOCAR SOM DE ERRO AQUI!");
#endif
                            }
                        }
                        else
                        {
#if UNITY_EDITOR
                            Debug.Log("Clicou Longe");
                            Debug.Log("COLOCAR SOM DE ERRO AQUI!");
#endif
                        }
                    }
                }
            }
        }
示例#28
0
    NumberedHexaTile[] FindExplodeTiles(HexaTile seed, int depth, params int[] ignoreNumbers)
    {
        if (seed == null)
        {
            return(new NumberedHexaTile[0]);
        }

        HexaTile[] neighbors          = seed.neighbors;
        List <NumberedHexaTile> tiles = new List <NumberedHexaTile>();

        if (depth > 0)
        {
            for (int i = 0, max = neighbors.Length; i < max; ++i)
            {
                tiles.AddRange(FindExplodeTiles(neighbors[i], depth - 1, ignoreNumbers));
            }
        }

        NumberedHexaTile tile = seed as NumberedHexaTile;

        if (tile != null &&
            !tiles.Contains(tile) &&
            Array.TrueForAll(ignoreNumbers, n => n != tile.number))
        {
            tiles.Add(tile);
        }

        for (int i = 0, max = neighbors.Length; i < max; ++i)
        {
            NumberedHexaTile neighbor = neighbors[i] as NumberedHexaTile;
            if (neighbor != null &&
                !tiles.Contains(neighbor) &&
                Array.TrueForAll(ignoreNumbers, n => n != neighbor.number))
            {
                tiles.Add(neighbor);
            }
        }

        return(tiles.ToArray());
    }
示例#29
0
文件: Gui.cs 项目: raimis001/brsd2015
    public void deleteTile()
    {
        if (selected == null)
        {
            return;
        }

        HexaTile tile = ShipData.mainShip.GetTile(selected);

        if (tile.device.id == 1)
        {
            AddMessage("Cannot delete pilot cabine");
            return;
        }

        int price = (int)((float)ShipData.devices[tile.device.id].price * 0.75f);

        ShipData.addMetals(price);
        AddMessage("Return metal:" + price.ToString());

        ShipData.mainShip.DeleteTile(selected);
        selected = null;
    }
示例#30
0
文件: Gui.cs 项目: raimis001/brsd2015
    public void deleteDevice()
    {
        if (selected == null)
        {
            return;
        }

        HexaTile tile = ShipData.mainShip.GetTile(selected);

        if (tile.device.id == 1)
        {
            AddMessage("Cannot delete pilot cabine");
            return;
        }

        int price = (int)((float)ShipData.devices[tile.device.id].price * 0.75f);

        if (ShipData.mainShip.DeleteDevice(selected))
        {
            ShipData.addMetals(price);
        }

        selected = tile.key.index;
    }
示例#31
0
 /// <summary>
 /// Return the dummyZ triple of the given tile.
 /// </summary>
 /// <returns>The z.</returns>
 /// <param name="a">The given tile.</param>
 public static Vector3 DummyZ(HexaTile a)
 {
     return HexaTile.DummyZ(a.x,a.y);
 }
示例#32
0
 /// <summary>
 /// Distance between a and b centres in the euclidean space.
 /// </summary>
 /// <param name="a">The first tile.</param>
 /// <param name="b">The second tile.</param>
 /// <param name="apothem">The hexagon apothem.</param>
 public static float Distance(HexaTile a, HexaTile b, float apothem)
 {
     return (a.ToEuclidean(apothem) - b.ToEuclidean(apothem)).magnitude;
 }
示例#33
0
 /// <summary>
 /// The step distance between the hexatiles a and b.
 /// </summary>
 /// <returns>The distance.</returns>
 /// <param name="a">The first tile.</param>
 /// <param name="b">The second tile.</param>
 public static double StepDistance(HexaTile a, HexaTile b)
 {
     int diffX = a.x - b.x;
     int diffY = a.y - b.y;
     Vector3 dummyZDif = HexaTile.DummyZ(diffX,diffY);
     return Mathf.Abs(dummyZDif.x)+Mathf.Abs(dummyZDif.y)+Mathf.Abs(dummyZDif.z);
 }