Ejemplo n.º 1
0
    public void SpawnLevels()
    {
        while (root.transform.childCount != 0)
        {
            GameObject toDestroy = root.transform.GetChild(0).gameObject;
            toDestroy.transform.SetParent(null);
            DestroyImmediate(toDestroy);
        }

        int x = 0;
        int y = 0;

        foreach (string assetGUID in AssetDatabase.FindAssets("t:GameObject"))
        {
            x += 35;
            if (x >= 100)
            {
                x  = 0;
                y += 50;
            }
            GameObject    go    = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(assetGUID));
            InfiniteLevel level = go.GetComponent <InfiniteLevel>();
            if (level != null)
            {
                GameObject newLevel = PrefabUtility.InstantiatePrefab(go) as GameObject;
                newLevel.transform.SetParent(root.transform);
                newLevel.transform.position = new Vector3(x, y, 0);
            }
            continue;
        }
        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    }
Ejemplo n.º 2
0
 public void UpdateSpawnChances()
 {
     totalSpawnWeights = 0;
     foreach (var levelObj in possibleLevels)
     {
         InfiniteLevel level = levelObj.GetComponent <InfiniteLevel>();
         if (levelsSpawnRatios.ContainsKey(levelObj))
         {
             if (levelsSpawnRatios[levelObj].ContainsKey(currentLevel))
             {
                 if (levelsCurrentSpawnRatios.ContainsKey(level.gameObject.name))
                 {
                     levelsCurrentSpawnRatios[level.gameObject.name] = levelsSpawnRatios[levelObj][currentLevel];
                 }
                 else
                 {
                     levelsCurrentSpawnRatios.Add(level.gameObject.name, levelsSpawnRatios[levelObj][currentLevel]);
                 }
             }
         }
         else
         {
             if (levelsCurrentSpawnRatios.ContainsKey(level.gameObject.name))
             {
                 levelsCurrentSpawnRatios[level.gameObject.name] = 0;
             }
             else
             {
                 levelsCurrentSpawnRatios.Add(level.gameObject.name, 0);
             }
         }
         totalSpawnWeights += levelsCurrentSpawnRatios[level.gameObject.name];
     }
 }
Ejemplo n.º 3
0
    public void SpawnLevel()
    {
        currentLevel += 1;
        int        scaleMod = 1;
        GameObject nextLevelModel;

        UpdateSpawnChances();
        if (specialLevels.ContainsKey(currentLevel) && specialLevels[currentLevel].GetComponent <InfiniteLevel>().CanSpawn())
        {
            nextLevelModel = specialLevels[currentLevel];
        }
        else
        {
            if (Random.Range(0, 2) == 0)
            {
                scaleMod = -1;
            }

            nextLevelModel = possibleLevels[PickLevelToSpawn()];
        }

        InfiniteLevelGoal boundEnd    = null;
        Vector3           endPrevious = Vector3.zero;
        int minDepth = int.MaxValue;

        for (int levelIdx = 0; levelIdx < levels.Count; ++levelIdx)
        {
            for (int endIdx = 0; endIdx < levels[levelIdx].ends.Count; ++endIdx)
            {
                int currentDepth = levels[levelIdx].GetDepth();
                if (currentDepth < minDepth && levels[levelIdx].ends[endIdx].boundStart == null)
                {
                    minDepth    = currentDepth;
                    boundEnd    = levels[levelIdx].ends[endIdx];
                    endPrevious = levels[levelIdx].ends[endIdx].transform.position;
                }
            }
        }

        InfiniteLevel level  = nextLevelModel.GetComponent <InfiniteLevel>();
        Vector3       newPos = endPrevious - level.start.transform.localPosition;

        GameObject newLevel = Instantiate(nextLevelModel, newPos, Quaternion.identity);

        newLevel.GetComponentInChildren <InfiniteLevel>().levelNumber = currentLevel;
        newLevel.transform.SetParent(levelsRoot);
        newLevel.name = nextLevelModel.name + currentLevel;
        newLevel.transform.position  = newPos;
        boundEnd.boundStart          = newLevel.GetComponentInChildren <InfiniteLevelStart>();
        boundEnd.boundStart.boundEnd = boundEnd;
        if (scaleMod != 1)
        {
            newLevel.transform.localScale = new Vector3(scaleMod * newLevel.transform.localScale.x, newLevel.transform.localScale.y, newLevel.transform.localScale.z);
        }
    }
Ejemplo n.º 4
0
 public void RegisterLevel(InfiniteLevel level)
 {
     if (levels.Contains(level) == false)
     {
         foreach (Transform t in level.GetComponentsInChildren <Transform>())
         {
             if (t.gameObject.name == "Walls")
             {
                 walls.Add(t.gameObject);
             }
         }
         levels.Add(level);
         levelsObj.Add(level.gameObject);
     }
 }
Ejemplo n.º 5
0
    IEnumerator StartNewSurfaces()
    {
        if (From == "" || From == "RIGHT")
        {
            yield return(StartCoroutine("MovePlayerToCenterFromRight"));
        }
        else
        {
            yield return(StartCoroutine("MovePlayerToCenterFromLeft"));
        }
        yield return(new WaitForSeconds(5.0f));

        BlockProperties bp  = Block.GetComponent <BlockProperties> ();
        InfiniteLevel   ifl = gameObject.GetComponent <InfiniteLevel> ();

        foreach (GameObject value in ifl.SurfaceList)
        {
            value.SetActive(false);
        }
        ifl.SurfaceList.Clear();
        //Debug.Log (ifl.SurfaceList.Count);
        PlayerController pc = gameObject.GetComponent <PlayerController>();
        PlayerPhysics    pp = gameObject.GetComponent <PlayerPhysics>();

        if (bp.ToContinue == "CONTINUE")
        {
            if (bp.NextLevelDirection == "LEFT")
            {
                StartCoroutine(ifl.InfiniteLevelLeft(Block.transform.position.x, Block.transform.position.y - 10.0f));
                if (Mathf.Sign(pc.Speed) > 0)
                {
                    pc.Speed *= -1.0f;
                }
            }
            else
            {
                StartCoroutine(ifl.InfiniteLevelRight(Block.transform.position.x, Block.transform.position.y - 10.0f));
                if (Mathf.Sign(pc.Speed) < 0)
                {
                    pc.Speed *= -1.0f;
                }
            }
            From            = bp.NextLevelDirection;
            pp.enabled      = true;
            pc.CurrentSpeed = 0.0f;
            pc.enabled      = true;
        }
    }
Ejemplo n.º 6
0
        protected override void Initialize()
        {
            hud = new HUD(this);

            begin    = true;
            infinite = false;
            normal   = false;

            soundEffect = new SoundEffects(this);
            sound       = new Sounds(this);
            contrl      = new ArrayList();
            camera      = new Camera(this);
            camObj      = new CameraObjectDetector(this);
            itemSpawn   = new ItemSpawn(this);
            start       = new startScreen(this);
            lvCtrl      = new LevelControl(this);
            infLvl      = new InfiniteLevel(this);

            marioColDetector = new MarioCollisionDetector(this);
            enemyColDetector = new EnemyCollisionDetector(this);
            itemColDetector  = new ItemCollisionDetector(this);

            keyboard = new KeyboardController();
            gmPad    = new GamepadController();
            KeyBind keyB = new KeyBind(this);

            keyB.BindKey();
            contrl.Add(keyboard);
            contrl.Add(gmPad);
            paused   = new Pause(this);
            gameOver = new GameOver(this);
            gameover = false;

            marioState = new MarioStateClass(false, false, false, false);
            fireBalls  = new List <Fireball>();
            fbDelay    = 0;

            countOfPopItem = 0;
            projColDet     = new ProjectileCollisionDetector(this, fireBalls);

            animationModifier = 0;
            starDuration      = 500;

            base.Initialize();
        }
Ejemplo n.º 7
0
    public void RemoveLevel(InfiniteLevel level, InfiniteLevel saveLevel = null)
    {
        levels.Remove(level);
        level.RemoveReferences();
        levelsObj.Remove(level.gameObject);
        Destroy(level.gameObject);
        levels[0].CloseLevel();

        FillToDepth();

        foreach (InfiniteLevelGoal currentLevelEnd in level.ends)
        {
            if (currentLevelEnd.boundStart != null && (saveLevel == null || currentLevelEnd.boundStart.level != saveLevel))
            {
                RemoveLevel(currentLevelEnd.boundStart.level);
            }
        }
    }
Ejemplo n.º 8
0
    private void FillLevelsList()
    {
        InfiniteLevelsManager manager = GameObject.FindObjectOfType <InfiniteLevelsManager>();

        if (manager == null)
        {
            Debug.LogWarning("No InfiniteLevelsManager found!");
            return;
        }
        manager.possibleLevels.Clear();
        foreach (string assetGUID in AssetDatabase.FindAssets("t:GameObject"))
        {
            GameObject    go    = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(assetGUID));
            InfiniteLevel level = go.GetComponent <InfiniteLevel>();
            if (level && level.baseLevel)
            {
                manager.possibleLevels.Add(go);
            }
            continue;
        }
        EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
    }
Ejemplo n.º 9
0
    public int DepthFilled()
    {
        InfiniteLevel topLevel = levels[0];

        while (topLevel.start.boundEnd != null)
        {
            topLevel = topLevel.start.boundEnd.level;
        }
        List <InfiniteLevel> currentLevels = new List <InfiniteLevel>();
        List <InfiniteLevel> nextLevels    = new List <InfiniteLevel>();

        nextLevels.Add(topLevel);

        int depth = 0;

        while (nextLevels.Count != 0)
        {
            currentLevels.Clear();
            currentLevels.AddRange(nextLevels);
            nextLevels.Clear();
            foreach (InfiniteLevel level in currentLevels)
            {
                foreach (InfiniteLevelGoal end in level.ends)
                {
                    if (end.boundStart == null)
                    {
                        return(depth);
                    }
                    else
                    {
                        nextLevels.Add(end.boundStart.level);
                    }
                }
            }
            ++depth;
        }
        return(depth);
    }