Exemplo n.º 1
0
    public Stage(Platform startPlatform)
    {
        GameObject = new GameObject("Stage");

        PlatformsFactory = new PlatformsFactory(GameObject.transform);

        var space = UnityEngine.Random.Range(MINIMUM_SPACE, MAXIMUM_SPACE);

        CurrentLevel = new Level(startPlatform,
                                 PlatformsFactory.CreatePlatform(startPlatform, space));

        CurrentLevel.OnLevelEnd           += CurrentLevel_OnLevelEnd;
        CurrentLevel.SpaceBetweenPlatforms = space;

        OnStageStart?.Invoke();
    }
Exemplo n.º 2
0
    private void CurrentLevel_OnLevelEnd(Level level, bool isWin)
    {
        if (isWin)
        {
            Scores += level.Score;

            var space = UnityEngine.Random.Range(MINIMUM_SPACE, MAXIMUM_SPACE);

            CurrentLevel = new Level(level.AimPlatform,
                                     PlatformsFactory.CreatePlatform(level.AimPlatform, space));
            CurrentLevel.OnLevelEnd           += CurrentLevel_OnLevelEnd;
            CurrentLevel.SpaceBetweenPlatforms = space;
        }
        else
        {
            OnStageEnd?.Invoke();
        }
    }
Exemplo n.º 3
0
        public PlatformsPool(GameParams gameParams, PlatformsFactory factory)
        {
            Parent = new GameObject("Platforms");
            _pools = new Dictionary <PlatformType, Queue <PlatformComponent> >();

            foreach (var prefab in gameParams.PlatformPrefabs)
            {
                if (!_pools.ContainsKey(prefab.Type))
                {
                    _pools[prefab.Type] = new Queue <PlatformComponent>(gameParams.PlatformPoolCapacity);
                }

                for (var i = 0; i < gameParams.PlatformPoolCapacity; i++)
                {
                    var platform = factory.Create(prefab);
                    platform.transform.parent   = Parent.transform;
                    platform.transform.position = Vector3.zero;
                    platform.gameObject.SetActive(false);
                    _pools[prefab.Type].Enqueue(platform);
                }
            }
        }