예제 #1
0
    IEnumerator StartCheck()
    {
        WaitForSeconds cd    = new WaitForSeconds(coolDown);
        EnemyInfor     infor = new EnemyInfor();

        infor.hp              = Mathf.RoundToInt(control.inforEnemy.hp / hpFactor);
        infor.duplicate       = null;
        infor.isDuplicate     = false;
        infor.spawnBuffDebuff = false;
        infor.sizeScale       = 1;
        infor.coinAmount      = 0;

        yield return(new WaitForSeconds(coolDown / 2));

        while (true)
        {
            float startAngle = UnityEngine.Random.Range(0, 360);

            for (int i = 0; i < numberOfShoot; i++)
            {
                EnemyControl enemyControl = EnemyFactory.instance.CreateEnemy(prefab.gameObject);
                enemyControl.transform.position = transform.position;
                enemyControl.Setup(infor, false, false);
                enemyControl.SetDirection(startAngle);
                startAngle = startAngle.NextAngle(360 / numberOfShoot);
            }



            yield return(cd);
        }
    }
예제 #2
0
    IEnumerator StartCheck()
    {
        WaitForSeconds wait = new WaitForSeconds(checkTime);
        WaitForSeconds cd   = new WaitForSeconds(coolDown);
        bool           isUseSkill;

        yield return(new WaitForSeconds(startDelayTime));

        while (true)
        {
            isUseSkill = false;
            Collider2D[] cols = Physics2D.
                                OverlapCircleAll(transform.position, checkRadius * transform.localScale.y, LayerConfig.ENEMY_LAYER);
            foreach (var c in cols)
            {
                if (c.tag != eaterTag && c.transform.localScale.y < transform.localScale.y)
                {
                    isUseSkill           = true;
                    control.currentSpeed = 0;
                    c.gameObject.SetActive(false);

                    EnemyControl old = c.GetComponent <EnemyControl>();

                    EnemyInfor newEnemyInfor = control.inforEnemy;
                    newEnemyInfor.hp        = old.hp;
                    newEnemyInfor.sizeScale = control.inforEnemy.sizeScale;

                    EnemyFactory.instance.RemoveEnemy(old);
                    Destroy(c.gameObject);

                    EnemyControl newEnemy = EnemyFactory.instance.CreateEnemy(prefab.gameObject);
                    newEnemy.gameObject.SetActive(false);



                    yield return(new WaitForSeconds(2f));

                    control.currentSpeed = control.speed;
                    newEnemy.gameObject.SetActive(true);
                    newEnemy.Setup(newEnemyInfor, newEnemyInfor.isDuplicate, true);
                    break;
                }
            }

            if (isUseSkill)
            {
                yield return(cd);
            }
            else
            {
                yield return(wait);
            }
        }
    }
예제 #3
0
 public WaveInfor(ConfigWaveRecord config)
 {
     timeDelayOnEachSpawn = config.TimeDelayOnEachSpawn;
     timeDelayToSpawn     = config.TimeDelayToSpawn;
     numbers    = config.Numbers;
     enemyInfor = new EnemyInfor[config.EnemyIds.Count];
     for (int i = 0; i < config.EnemyIds.Count; i++)
     {
         EnemyInfor infor
                       = new EnemyInfor(ConfigurationManager.instance.enemy.GetRecordByKeySearch(config.EnemyIds[i]));
         enemyInfor[i] = infor;
     }
 }
예제 #4
0
 public EnemyInfor(ConfigEnemyRecord config)
 {
     hp              = config.Hp;
     sizeScale       = config.SizeScale;
     prefab          = Resources.Load(config.Prefab) as GameObject;
     isDuplicate     = config.IsDuplicate;
     coinAmount      = config.CoinAmount;
     spawnBuffDebuff = config.SpawnBuffDebuff;
     if (config.IsDuplicate)
     {
         duplicate = new EnemyInfor[config.EnemyDuplicateIds.Count];
         for (int i = 0; i < duplicate.Length; i++)
         {
             duplicate[i] = new EnemyInfor(ConfigurationManager.instance.enemy.GetRecordByKeySearch(config.EnemyDuplicateIds[i]));
         }
     }
 }
예제 #5
0
    IEnumerator StartWave()
    {
        yield return(new WaitForSeconds(1f));

        foreach (var w in waves)
        {
            waveIndex++;
            totalEnemy     = 0;
            totalEnemyDead = 0;
            yield return(new WaitForSeconds(w.timeDelayToSpawn));

            for (int i = 0; i < w.numbers.Count; i++)
            {
                for (int j = 0; j < w.numbers[i]; j++)
                {
                    EnemyInfor infor = w.enemyInfor[i];

                    EnemyControl enemy = EnemyFactory.instance.CreateEnemy(infor.prefab);
                    enemy.Setup(infor, false, true);
                    enemy.OnEnemyDead       += OnEnemyDead;
                    enemy.transform.position = enemy.GetTopPos();

                    totalEnemy++;
                    if (infor.isDuplicate)
                    {
                        totalEnemy += infor.duplicate.Length;
                    }
                    yield return(new WaitForSeconds(w.timeDelayOnEachSpawn));
                }
            }
            WaitForSeconds waitForSeconds = new WaitForSeconds(0.5f);
            while (true)
            {
                yield return(waitForSeconds);

                if (totalEnemyDead == totalEnemy)
                {
                    break;
                }
            }
        }

        StartCoroutine(CheckEndGame());
    }
예제 #6
0
    public override void OnDead(OnEnemyDeadParam param)
    {
        EnemyInfor infor = new EnemyInfor();

        infor.hp              = Mathf.RoundToInt(control.inforEnemy.hp / hpFactor);
        infor.duplicate       = null;
        infor.isDuplicate     = false;
        infor.spawnBuffDebuff = false;
        infor.sizeScale       = 1;
        infor.coinAmount      = 0;
        for (int i = 0; i < numberOfSpawnOnDead; i++)
        {
            EnemyControl enemyControl = EnemyFactory.instance.CreateEnemy(prefab.gameObject);
            enemyControl.transform.position = transform.position;
            enemyControl.Setup(infor, true, false);
        }

        base.OnDead(param);
    }
예제 #7
0
    IEnumerator StartCheck()
    {
        WaitForSeconds cd    = new WaitForSeconds(coolDown);
        EnemyInfor     infor = new EnemyInfor();

        infor.hp              = Mathf.RoundToInt(control.inforEnemy.hp / hpFactor);
        infor.duplicate       = null;
        infor.isDuplicate     = false;
        infor.spawnBuffDebuff = false;
        infor.sizeScale       = 1;
        infor.coinAmount      = 0;

        yield return(cd);

        while (true)
        {
            EnemyControl e = EnemyFactory.instance.CreateEnemy(prefab.gameObject);
            e.transform.position = transform.position;
            e.Setup(infor, false, false);
            yield return(cd);
        }
    }
예제 #8
0
    public void InitChessPieces()
    {
        List <PieceInfor> listInfo = new List <PieceInfor>();

        //White
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_1", Path = "Pieces/W_PAWN", X = 0, Y = 1, Score = 10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_2", Path = "Pieces/W_PAWN", X = 1, Y = 1, Score = 10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_3", Path = "Pieces/W_PAWN", X = 2, Y = 1, Score = 10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_4", Path = "Pieces/W_PAWN", X = 3, Y = 1, Score = 10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_5", Path = "Pieces/W_PAWN", X = 4, Y = 1, Score = 10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_6", Path = "Pieces/W_PAWN", X = 5, Y = 1, Score = 10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_7", Path = "Pieces/W_PAWN", X = 6, Y = 1, Score = 10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_PAWN_8", Path = "Pieces/W_PAWN", X = 7, Y = 1, Score = 10
        });

        listInfo.Add(new PieceInfor()
        {
            Name = "W_CASTLE_1", Path = "Pieces/W_CASTLE", X = 0, Y = 0, Score = 50
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_CASTLE_2", Path = "Pieces/W_CASTLE", X = 7, Y = 0, Score = 50
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_KNIGHT_1", Path = "Pieces/W_KNIGHT", X = 1, Y = 0, Score = 30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_KNIGHT_2", Path = "Pieces/W_KNIGHT", X = 6, Y = 0, Score = 30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_BISHOP_1", Path = "Pieces/W_BISHOP", X = 2, Y = 0, Score = 30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_BISHOP_2", Path = "Pieces/W_BISHOP", X = 5, Y = 0, Score = 30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_QUEEN_1", Path = "Pieces/W_QUEEN", X = 3, Y = 0, Score = 80
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "W_KING_1", Path = "Pieces/W_KING", X = 4, Y = 0, Score = 9000
        });

        //Black
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_1", Path = "Pieces/B_PAWN", X = 0, Y = 6, Score = -10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_2", Path = "Pieces/B_PAWN", X = 1, Y = 6, Score = -10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_3", Path = "Pieces/B_PAWN", X = 2, Y = 6, Score = -10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_4", Path = "Pieces/B_PAWN", X = 3, Y = 6, Score = -10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_5", Path = "Pieces/B_PAWN", X = 4, Y = 6, Score = -10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_6", Path = "Pieces/B_PAWN", X = 5, Y = 6, Score = -10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_7", Path = "Pieces/B_PAWN", X = 6, Y = 6, Score = -10
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_PAWN_8", Path = "Pieces/B_PAWN", X = 7, Y = 6, Score = -10
        });

        listInfo.Add(new PieceInfor()
        {
            Name = "B_CASTLE_1", Path = "Pieces/B_CASTLE", X = 0, Y = 7, Score = -50
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_CASTLE_2", Path = "Pieces/B_CASTLE", X = 7, Y = 7, Score = -50
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_KNIGHT_1", Path = "Pieces/B_KNIGHT", X = 1, Y = 7, Score = -30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_KNIGHT_2", Path = "Pieces/B_KNIGHT", X = 6, Y = 7, Score = -30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_BISHOP_1", Path = "Pieces/B_BISHOP", X = 2, Y = 7, Score = -30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_BISHOP_2", Path = "Pieces/B_BISHOP", X = 5, Y = 7, Score = -30
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_QUEEN_1", Path = "Pieces/B_QUEEN", X = 3, Y = 7, Score = -80
        });
        listInfo.Add(new PieceInfor()
        {
            Name = "B_KING_1", Path = "Pieces/B_KING", X = 4, Y = 7, Score = -9000
        });

        whiteLifeCells.Clear();
        blackLifeCells.Clear();
        blackCells.Clear();
        whiteCells.Clear();

        var totalWhite = 0;
        var totalBlack = 0;

        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                this.arrayLocationCurrent[i, j] = 0;
            }
        }

        foreach (var item in listInfo)
        {
            GameObject GO = GameObject.Instantiate <GameObject>(ResourceCTL.Instance.GetGameObject(item.Path));
            GO.transform.parent = this.transform.GetChild(1);
            GO.name             = item.Name;
            BasePiece p = GO.GetComponent <BasePiece>();
            p.setInfor(item, _cells[item.X][item.Y]);
            pieces.Add(p);

            this.arrayLocationCurrent[item.X, item.Y] = item.Score;

            //if (Cells[item.X][item.Y]._currentPiece.player == EPlayer.BLACK)
            //{
            //    Cells[item.X][item.Y]._currentPiece.BeSelected();
            //}
            //else
            //{
            //    Cells[item.X][item.Y]._currentPiece.BeSelected();
            //}


            Cells[item.X][item.Y]._currentPiece.BeSelected();

            foreach (var item2 in Cells[item.X][item.Y]._currentPiece._targetedCells)
            {
                if (item2._currentPiece != null)
                {
                    if (item2._currentPiece.player == EPlayer.BLACK)
                    {
                        if (Math.Abs(item2._currentPiece.Info.Score) >= totalBlack)
                        {
                            blackCells.Clear();
                            blackCells.Add(Cells[item.X][item.Y]);
                            blackCells.Add(item2);
                        }
                    }
                    else
                    {
                        if (Math.Abs(item2._currentPiece.Info.Score) >= totalWhite)
                        {
                            whiteCells.Clear();
                            whiteCells.Add(Cells[item.X][item.Y]);
                            whiteCells.Add(item2);
                        }
                    }
                }
                list.Add(item2);
            }
            var pieceInfor = new EnemyInfor(Cells[item.X][item.Y]._currentPiece, list);

            if (item.Score > 0)
            {
                whiteLifeCells.Add(pieceInfor);
            }
            else
            {
                blackLifeCells.Add(pieceInfor);
            }

            Cells[item.X][item.Y]._currentPiece.BeUnSelected();
        }

        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                this.arrayLocationFuture[i, j] = this.arrayLocationCurrent[i, j];
            }
        }
    }
예제 #9
0
    protected void SetNewLocation(Cell newCell)
    {
        var me = this;

        ChessBoard.Current.arrayLocationFuture[this.location.X, this.location.Y]       = 0;
        ChessBoard.Current.arrayLocationFuture[newCell.location.X, newCell.location.Y] = this.Info.Score;

        setPosCount++;
        if (setPosCount > 1)
        {
            this._currentCell.SetPiece(null);
        }

        this._currentCell = newCell;
        newCell.SetPiece(this);
        this.location = newCell.location;

        currentLocationX = newCell.location.X;
        currentLocationY = newCell.location.Y;

        //this.transform.position = offsetPosition + new Vector2(location.X * ChessBoard.Current.CELL_SIZE,
        //    location.Y * ChessBoard.Current.CELL_SIZE);

        this.transform.DOMove(offsetPosition + new Vector2(location.X * ChessBoard.Current.CELL_SIZE,
                                                           location.Y * ChessBoard.Current.CELL_SIZE), 0.75f);



        if ((this.Info.Score == 10 && this.location.Y == 7) || (this.Info.Score == -10 && this.location.Y == 0))
        {
            var pieceInfor = new PieceInfor();
            if (this.location.Y == 7)
            {
                pieceInfor.Name  = "W_QUEEN_" + ChessBoard.Current.indexQueenWhite;
                pieceInfor.Path  = "Pieces/W_QUEEN";
                pieceInfor.Score = 80;
                pieceInfor.X     = this.location.X;
                pieceInfor.Y     = this.location.Y;
                ChessBoard.Current.indexQueenWhite++;
            }
            else
            {
                pieceInfor.Name  = "B_QUEEN_" + ChessBoard.Current.indexQueenBlack;
                pieceInfor.Path  = "Pieces/B_QUEEN";
                pieceInfor.Score = 80;
                pieceInfor.X     = this.location.X;
                pieceInfor.Y     = this.location.Y;
                ChessBoard.Current.indexQueenBlack++;
            }

            GameObject.Destroy(this.gameObject);

            GameObject GO = GameObject.Instantiate <GameObject>(ResourceCTL.Instance.GetGameObject(pieceInfor.Path));
            GO.transform.parent = ChessBoard.Current.transform.GetChild(1);
            GO.name             = pieceInfor.Name;
            BasePiece p = GO.GetComponent <BasePiece>();
            //p.setInfor(pieceInfor, _cells[item.X][item.Y]);
            p.setInfor(pieceInfor, ChessBoard.Current.Cells[pieceInfor.X][pieceInfor.Y]);

            _currentCell.SetPiece(p);


            newCell._currentPiece.BeSelected();
            var list = new List <Cell>();
            foreach (var item in newCell._currentPiece._targetedCells)
            {
                list.Add(item);
            }
            var _pieceInfor = new EnemyInfor(newCell._currentPiece, list);
            if (this.Info.Score == 10)
            {
                ChessBoard.Current.whiteLifeCells.Add(_pieceInfor);
            }
            else
            {
                ChessBoard.Current.blackLifeCells.Add(_pieceInfor);
            }
            newCell._currentPiece.BeUnSelected();
        }
    }