Example #1
0
        public void Initialize(RenderContext context)
        {
            var scaleX = 1.5f;
            var scaleY = 1.2f;

            //Add Possible Grounds to the list, if all the files have the correct namegiving everything should be loaded in
            if (PiecePrefabList.Count == 0)
            {
                PiecePrefabList.AddPrefab(new PiecePrefab(context, Collision.Col1, "Piece1", scaleX, scaleY));
                PiecePrefabList.AddPrefab(new PiecePrefab(context, Collision.Col2, "Piece2", scaleX, scaleY));
                PiecePrefabList.AddPrefab(new PiecePrefab(context, Collision.Col3, "Piece4", scaleX, scaleY));
                PiecePrefabList.AddPrefab(new PiecePrefab(context, Collision.Col4, "Piece6", scaleX, scaleY));
                PiecePrefabList.AddPrefab(new PiecePrefab(context, Collision.Col5, "Piece8", -scaleX, scaleY));
            }

            //Fill Pickups
            if (PickupPrefabList.Count == 0)
            {
                //Load All Possible Pickups here, models and name
                //Models

                /*aPickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.Health, "PickupLife"));
                 * PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.SpeedUp, "PickupSpeed"));
                 * PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.SpeedDown, "PickupSpeed"));
                 * PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.WindUp, "PickupSwirl"));
                 * PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.WindDown, "PickupSwirl")); */

                //
                PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.Health, "PickupLife"));
                PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.SpeedUp, "PickupFast"));
                PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.SpeedDown, "PickupFast"));
                PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.WindUp, "PickupWhirl"));
                PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.WindDown, "PickupWhirl"));

                PickupPrefabList.AddPrefab(new PickupPrefab(context, PickupName.WindVulcano, "WindVulcano"));
            }

            //Fill trees
            if (TreePrefabList.Count == 0)
            {
                TreePrefabList.AddPrefab(new TreePrefab(context, TreeName.Tree1, "Tree1"));
                TreePrefabList.AddPrefab(new TreePrefab(context, TreeName.Tree2, "Tree2"));
                TreePrefabList.AddPrefab(new TreePrefab(context, TreeName.Tree3, "Tree3"));
            }

            //Fill Enemies
            if (EnemyPrefabList.Count == 0)
            {
                //Load all Possible Pickups here, models and name
                EnemyPrefabList.AddPrefab(new EnemyPrefab(context, EnemyName.Wheel, "EnemyRotator"));
                EnemyPrefabList.AddPrefab(new EnemyPrefab(context, EnemyName.Smash, "SmashingWall"));
                EnemyPrefabList.AddPrefab(new EnemyPrefab(context, EnemyName.FallDown, "Enemy1"));
            }

            //always the same startpieces
            m_Level.Add(new Level_0());
            m_Level[0].Initialize(context);
            GenerateLevel(m_LevelsToGenerate, context);
        }
Example #2
0
        public static Tree GetRandom(Random rnd, int ScreenSize)
        {
            //Roll to generate a random tree that is different from the previous generated enemy
            Tree tree = null;

            //Roll
            var roll = rnd.Next(0, Count);

            //Add pickup here for each roll
            if (roll == 0)
            {
                tree = TreePrefabList.GetPrefab <Tree1>(TreeName.Tree1);
            }
            if (roll == 1)
            {
                tree = TreePrefabList.GetPrefab <Tree1>(TreeName.Tree2);
            }
            if (roll == 2)
            {
                tree = TreePrefabList.GetPrefab <Tree1>(TreeName.Tree3);
            }

            return(tree);
        }
Example #3
0
        public virtual void Initialize(RenderContext context)
        {
            ScreenSize = context.ViewPortSize;

            //Increase the number of levels we have generated so we can see where we are to make it more difficult
            NrLevels++;

            //Each level has a ground and top collision
            var t = PiecePrefabList.GetRandom(new Random(Guid.NewGuid().GetHashCode()), "Top");

            AddChild(t);

            //Change the Width of the level so they tile nicely
            var g = PiecePrefabList.GetRandom(new Random(Guid.NewGuid().GetHashCode()), "Ground");

            Width = g.Width * 0.85f;
            AddChild(g);

            int nrEnemies = 0;
            int nrPickups = 1;

            //Med add Every 3 levels
            if (NrLevels > 5 && NrLevels < 10)
            {
                nrEnemies = randVal.Next(0, 3);
                nrPickups = randVal.Next(0, 3);
            }
            else if (NrLevels > 10)
            {
                nrEnemies = randVal.Next(0, 3);
                nrPickups = randVal.Next(0, 3);
            }
            if (NrLevels < 15)
            {
                AddVolcano(g.Height, g.Position.Y, context);
            }
            else if (NrLevels >= 15 && NrLevels < 50)
            {
                if (NrLevels % 3 == 0)
                {
                    AddVolcano(g.Height, g.Position.Y, context);
                }
            }
            else if (NrLevels > 50)
            {
                if (NrLevels % 5 == 0)
                {
                    AddVolcano(g.Height, g.Position.Y, context);
                }
            }

            //Add A pickup
            for (int i = 0; i < nrPickups; ++i)
            {
                //Can return null
                var pickup = PickupPrefabList.GetRandom(new Random(Guid.NewGuid().GetHashCode()), (int)ScreenSize.Y);
                if (pickup != null)
                {
                    AddChild(pickup);
                }
            }


            //Add trees
            for (int i = 0; i < 3; ++i)
            {
                var tree = TreePrefabList.GetRandom(new Random(Guid.NewGuid().GetHashCode()), (int)ScreenSize.Y);
                if (tree != null)
                {
                    var rnd = new Random(Guid.NewGuid().GetHashCode());
                    tree.Translate(tree.Position.X + rnd.Next(0, 1700), tree.Position.Y - 460.0f);
                    AddChild(tree);
                }
            }

            for (int i = 0; i < nrEnemies; ++i)
            {
                var enemy = EnemyPrefabList.GetRandom(new Random(Guid.NewGuid().GetHashCode()), (int)ScreenSize.Y);
                if (enemy != null)
                {
                    //if enemy is a smash we need 2 of them in opposite directions
                    if (enemy.GetType() == typeof(Smash))
                    {
                        Smash smashTop = EnemyPrefabList.GetPrefab <Smash>(EnemyName.Smash);
                        smashTop.Translate(enemy.Position.X, enemy.Position.Y + smashTop.m_Distance * 2);
                        //Set the directions
                        enemy.Create(1);
                        smashTop.Create(-1);
                        AddChild(smashTop);
                    }


                    if (enemy.GetType() == typeof(Wheel))
                    {
                        var rnd = new Random(Guid.NewGuid().GetHashCode());
                        enemy.Rotate(0, 0, 0);
                        enemy.Scale(1f, -1f, 1.0f);
                        enemy.Translate(rnd.Next(0, 1700), t.Position.Y + (t.Height * 0.9f));
                    }
                    if (enemy.GetType() == typeof(FallDown))
                    {
                        var rnd = new Random(Guid.NewGuid().GetHashCode());
                        enemy.Rotate(0, 180, 0);
                        enemy.Scale(2f, 2f, 1.0f);
                        enemy.Translate(rnd.Next(0, 1700), t.Position.Y + (t.Height * 0.7f));
                    }
                    AddChild(enemy);
                }
            }

            //Set Everything to default if model or textures are missing
            foreach (GameModel model in m_Child.ToList <GameModel>())
            {
                model.Initialize(context);
            }

            IsInitialized = true;
        }