Exemple #1
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            if (currentLevel > GAME_LEVEL.Count)
            {
                currentLevel = GAME_LEVEL.Count;
            }

            frog = new Frog(game,
                            spriteBatch,
                            game.Content.Load <Texture2D>("frog_grn_v"),
                            game.Content.Load <Texture2D>("frog_goal"),
                            game.Content.Load <Texture2D>("death1"),
                            game.Content.Load <Texture2D>("skeleton"),
                            this,
                            game.Content.Load <SoundEffect>("jumpSound"),
                            game.Content.Load <SoundEffect>("deadSound"));

            for (int i = 0; i < 5; i++)
            {
                int       cnt      = ((int[, ])GAME_LEVEL[currentLevel])[i, 0];
                int       speed    = ((int[, ])GAME_LEVEL[currentLevel])[i, 1];
                ArrayList floatArr = new ArrayList();
                for (int j = 0; j < cnt; j++)
                {
                    float space = random.Next(20, 27) / 10f;
                    floatings = new Floatings(game,
                                              spriteBatch,
                                              game.Content.Load <Texture2D>("logs"),
                                              i + 3,
                                              speed,
                                              space / Math.Abs(speed) * j);
                    //Console.WriteLine("floatings : space {0:G}, line {1}", space, i);
                    this.Components.Add(floatings);
                    floatArr.Add(floatings);
                }
                lms = new LoadManager(game, frog, floatArr, null);
                this.Components.Add(lms);
            }

            for (int i = 5; i < 10; i++)
            {
                int cnt   = ((int[, ])GAME_LEVEL[currentLevel])[i, 0];
                int speed = ((int[, ])GAME_LEVEL[currentLevel])[i, 1];
                for (int j = 0; j < cnt; j++)
                {
                    float space = random.Next(12, 18) / 10f;
                    cars = new Cars(game,
                                    spriteBatch,
                                    game.Content.Load <Texture2D>("car" + (i - 4)),
                                    i + 4,
                                    speed,
                                    space / Math.Abs(speed) * j);
                    //Console.WriteLine("cars : space {0:G}, line {1}", space, i);

                    this.Components.Add(cars);
                    cms = new CollisionManager(game, frog, cars, null);
                    this.Components.Add(cms);
                }
            }

            texBg = game.Content.Load <Texture2D>("bg");
            this.Components.Add(frog);

            scoreboard = new Scoreboard(game, spriteBatch, game.Content.Load <Texture2D>("letter_ww"));
            this.Components.Add(scoreboard);

            base.Initialize();
        }