コード例 #1
0
ファイル: HeroSpawner.cs プロジェクト: VeRTeXR/SnakeRPG
        public void SpawnHero()
        {
            var heroOnGrid  = _levelGrid.GetHeroOnGridPositionList();
            var enemyOnGrid = _levelGrid.GetEnemyOnGridPositionList();

            do
            {
                _newHeroGridPosition = new Vector2Int(Random.Range(0, _levelWidth), Random.Range(0, _levelHeight));
            } while (_caravanController.GetCaravanGridPositionList().IndexOf(_newHeroGridPosition) != -1 &&
                     heroOnGrid.IndexOf(_newHeroGridPosition) != -1 && enemyOnGrid.IndexOf(_newHeroGridPosition) != -1);

            _heroGameObject = new GameObject("Hero" + GetInstanceID(), typeof(SpriteRenderer));
            _heroGameObject.transform.position = new Vector3(_newHeroGridPosition.x, _newHeroGridPosition.y);
            var heroEntity = _heroGameObject.AddComponent <HeroEntity>();

            heroEntity.Setup(GetRandomHeroSprite());

            _levelGrid.AppendNewHeroPosition(_newHeroGridPosition);
            _heroOccupiedGridPosition.Add(_newHeroGridPosition);
            _gridPositionHeroEntityPair.Add(_newHeroGridPosition, heroEntity);
        }
コード例 #2
0
ファイル: EnemySpawner.cs プロジェクト: VeRTeXR/SnakeRPG
        private void SpawnEnemy()
        {
            var heroOnGrid  = _levelGrid.GetHeroOnGridPositionList();
            var enemyOnGrid = _levelGrid.GetEnemyOnGridPositionList();

            do
            {
                _newGridPosition = new Vector2Int(Random.Range(0, _levelWidth), Random.Range(0, _levelHeight));
            } while (_caravanController.GetCaravanGridPositionList().IndexOf(_newGridPosition) != -1 &&
                     heroOnGrid.IndexOf(_newGridPosition) != -1 &&
                     enemyOnGrid.IndexOf(_newGridPosition) != -1);

            var enemyObject = new GameObject("Enemy", typeof(SpriteRenderer));

            enemyObject.transform.position = new Vector3(_newGridPosition.x, _newGridPosition.y);
            var enemyEntity = enemyObject.AddComponent <EnemyEntity>();

            enemyEntity.Setup(GetRandomSprite());
            _levelGrid.AppendEnemyPosition(_newGridPosition);
            _enemyOccupiedGridPosition.Add(_newGridPosition);
            _gridPositionEntityPair.Add(_newGridPosition, enemyEntity);
        }