예제 #1
0
 public void TransitionToThenSwap(TileContainer tileA, TileContainer tileB)
 {
     if (TileManagerService
         .GetInstance()
         .AreTilesAdjacent(tileA, tileB)
         )
     {
         IsTransitioning = true;
         bool tileATransitionComplete = false;
         bool tileBTransitionComplete = false;
         if (tileA.Tile != null)
         {
             StartCoroutine(tileA.Tile.TransitionTo(
                                tileB.transform.position,
                                delegate() {
                 SfxManagerService.GetInstance().PlayTileDing();
                 tileATransitionComplete = true;
                 if (tileATransitionComplete && tileBTransitionComplete)
                 {
                     SwapTiles(tileA, tileB);
                     IsTransitioning = false;
                 }
             }
                                ));
         }
         else
         {
             tileATransitionComplete = true;
         }
         if (tileB.Tile != null)
         {
             StartCoroutine(tileB.Tile.TransitionTo(
                                tileA.transform.position,
                                delegate() {
                 tileBTransitionComplete = true;
                 if (tileATransitionComplete && tileBTransitionComplete)
                 {
                     SwapTiles(tileA, tileB);
                     IsTransitioning = false;
                 }
             }
                                ));
         }
         else
         {
             tileBTransitionComplete = true;
         }
         if (tileATransitionComplete && tileBTransitionComplete)
         {
             SwapTiles(tileA, tileB);
             IsTransitioning = false;
         }
     }
 }
예제 #2
0
    void Update()
    {
        if (FreezeUpdateLoop)
        {
            return;
        }
        if (Input.GetKey(KeyCode.Space))
        {
            UnitSpawner.SpawnSoldier();
        }
        List <Tile> tilesToRemove = GetRemovableTiles();
        Dictionary <string, int> removedTileCounts = new Dictionary <string, int>();

        if (tilesToRemove.Count > 0)
        {
            foreach (Tile ttr in tilesToRemove)
            {
                if (!removedTileCounts.ContainsKey(ttr.Name))
                {
                    removedTileCounts[ttr.Name] = 0;
                }
                removedTileCounts[ttr.Name]++;
                Vector2 ttrc = GetTileCoordinates(ttr);
                TileMap[(int)ttrc.y][(int)ttrc.x].Tile.Remove();
                TileMap[(int)ttrc.y][(int)ttrc.x].Tile = null;
            }
            if (removedTileCounts.ContainsKey("Sword") ||
                removedTileCounts.ContainsKey("Arrow") ||
                removedTileCounts.ContainsKey("Thunder") ||
                removedTileCounts.ContainsKey("Shield") ||
                removedTileCounts.ContainsKey("Void")
                )
            {
                SfxManagerService.GetInstance().PlayTilePop();
            }
            if (removedTileCounts.ContainsKey("Skull"))
            {
                SfxManagerService.GetInstance().PlaySkullPop();
            }
            if (removedTileCounts.ContainsKey("Sword"))
            {
                while (removedTileCounts["Sword"] >= 3)
                {
                    UnitSpawner.SpawnSoldier();
                    removedTileCounts["Sword"] -= 3;
                }
            }
            if (removedTileCounts.ContainsKey("Arrow"))
            {
                while (removedTileCounts["Arrow"] >= 3)
                {
                    UnitSpawner.SpawnArcher();
                    removedTileCounts["Arrow"] -= 3;
                }
            }
            if (removedTileCounts.ContainsKey("Thunder"))
            {
                while (removedTileCounts["Thunder"] >= 3)
                {
                    UnitSpawner.SpawnWizard();
                    removedTileCounts["Thunder"] -= 3;
                }
            }
            if (removedTileCounts.ContainsKey("Void"))
            {
                while (removedTileCounts["Void"] >= 3)
                {
                    if (LevelManagerService.GetInstance().CurrentPlayerMana < 3)
                    {
                        StartCoroutine(IncreaseManaByXOverT(1, 0.5f));
                    }
                    removedTileCounts["Void"] -= 3;
                }
            }
            if (removedTileCounts.ContainsKey("Skull"))
            {
                float skullDamage = Mathf.Min(removedTileCounts["Skull"] / 2);
                while (removedTileCounts["Skull"] >= 3)
                {
                    removedTileCounts["Skull"] -= 3;
                    List <GameObject> PlayerSpawnedUnits = UnitSpawner.GetAllSpawnedUnits();
                    foreach (GameObject u in PlayerSpawnedUnits)
                    {
                        if (u != null)
                        {
                            DamagableUnit d = u.GetComponent <DamagableUnit>();
                            if (d != null)
                            {
                                d.TakeDamage(skullDamage);
                            }
                        }
                    }
                }
            }
            StartCoroutine(PushTiles());
        }
    }