Ejemplo n.º 1
0
 public void Ready()
 {
     OnLevelReady?.Invoke();
     this.SetTimeout(() => ActiveAtLoaded.ForEach(cpn => cpn.enabled = true), 0.5f);
     CoveredUI.Find("GameUI").ShowAsync();
     ActiveAtLoaded.ForEach(cpn => cpn.enabled = true);
     LevelLoader.Instance.CompleteLoading();
 }
Ejemplo n.º 2
0
        private void SpawnLevel(Level level, Exit exit, LevelRecipie levelRecipie)
        {
            if (ammunition != null)
            {
                foreach (var item in ammunition)
                {
                    ammunitionSpawner.Recycle(item);
                }
            }

            if (stones != null)
            {
                foreach (var stone in stones)
                {
                    stonesSpawner.Recycle(stone);
                }
            }

            if (bushes != null)
            {
                foreach (var bush in bushes)
                {
                    bushSpawner.Recycle(bush);
                }
            }


            stones     = stonesSpawner.Spawn(levelRecipie.stones);
            ammunition = ammunitionSpawner.Spawn(levelRecipie.cartridges);
            bushes     = bushSpawner.Spawn(levelRecipie.bushes);

            enemiesSet.Clear();
            enemiesController.OnEnemyDie -= Enemy_OnDie;

            foreach (var enemy in enemiesController.Spawn(levelRecipie))
            {
                enemiesSet.Add(new EnemySpawnSet(enemy));
            }

            enemiesController.OnEnemyDie += Enemy_OnDie;

            deadEnemies.Clear();

            level.OpenAllDoors();
            exit.Close();

            OnLevelReady?.Invoke(this, new LevelSpawnData(level,
                                                          exit, enemiesSet.Count));

            FireLevelStateChange();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load a new level
        /// </summary>
        /// <param name="newLevel">New level.</param>
        public void LoadLevel(GridXY <Element> newLevel)
        {
            if (newLevel == null || newLevel.Size == 0)
            {
                Debug.LogWarning("The new level grid is not valid");
                return;
            }

            Debug.Log($"0. Loading level {newLevel.Width}x{newLevel.Height}...");
            ClearLevel();

            Debug.Log($"1. Initializing level...");
            Grid.CreateGridXY(newLevel.Width, newLevel.Height, 1, Vector3.zero, true, Element.NULL, Element.NULL);

            Debug.Log("Level is not playable!");
            LvlState = LevelState.NotPlayable;
            OnLevelNotPlayable?.Invoke(this, null);

            Debug.Log("2. Generating level...");
            StartCell = Vector2Int.one * -1;
            EndCell   = Vector2Int.one * -1;

            bool hasStart = false;
            bool hasEnd   = Grid.Size == 1;

            Element type;

            for (int x = 0; x < Grid.Width; x++)
            {
                for (int y = 0; y < Grid.Height; y++)
                {
                    type = newLevel.GetTile(x, y);
                    if (showDebugLog)
                    {
                        Debug.Log($"Setted Tile {x},{y} ({type})");
                    }
                    Grid.SetTile(x, y, type);
                    if (type == Element.Start)
                    {
                        StartCell = new Vector2Int(x, y);
                        hasStart  = true;
                    }
                    else
                    {
                        if (type == Element.End)
                        {
                            EndCell = new Vector2Int(x, y);
                            hasEnd  = true;
                        }
                    }
                }
            }

            Debug.Log("Level is ready!");
            LvlState = LevelState.Ready;
            OnLevelReady?.Invoke(this, new OnLevelReadyEventArgs {
                width = Grid.Width, height = Grid.Height
            });

            if (!hasStart || !hasEnd)
            {
                Debug.LogWarning($"Level has {(!hasStart ? "NO": "")} Start and {(!hasEnd ? "NO" : "")} End");
                return;
            }

            LevelNavigation.SetUp(Grid.Width, Grid.Height, false, true, Grid);

            Debug.Log("Level is playable!");
            LvlState = LevelState.Playable;
            OnLevelPlayable?.Invoke(this, new OnLevelPlayableEventArgs {
                startX = StartCell.x, startY = StartCell.y, endX = EndCell.x, endY = EndCell.y
            });
            OnLevelStart?.Invoke();
        }