예제 #1
0
        public override void Initialize()
        {
            childComponents = new List<GameObject>();
            ioManager = new IOManager();
            font = gameRef.Content.Load<SpriteFont>("SpriteFont1");

            platform = new Platform(new Rectangle(18, 40, 445, 650), gameRef.Content);
            guage = new Guage(new Rectangle(platform.Position.X + platform.Position.Width + 2, 40, 100, 650), gameRef.Content);
            Vector2 startingPos = platform.getMidPoint();
            player = new Munchlit(new Rectangle((int)startingPos.X, (int)startingPos.Y, 20, 20), gameRef.Content);

            childComponents.Add(platform);
            childComponents.Add(guage);
            childComponents.Add(player);

            for (int i = platform.Position.X + 12; i <= platform.Position.X + platform.Position.Width - 24; i += 30)
            {

                childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 45, 30, 30), gameRef.Content, 0));
                childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 75, 30, 30), gameRef.Content, 0));
                childComponents.Add(new Meteor(new Rectangle(i, platform.Position.Y + platform.Position.Height - 105, 30, 30), gameRef.Content, 0));
            }

            guiManager.AddLabel("HighScore", font, "Highscore: " + 0);
            guiManager["HighScore"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 40.0f);
            guiManager["HighScore"].Size = new Vector2(200.0f, 75.0f);
            guiManager["HighScore"].Color = Color.Black;

            guiManager.AddLabel("level", font, "Level: " + level);
            guiManager["level"].Position = new Vector2(platform.Position.X + platform.Position.Width / 3 + 20, 10.0f);
            guiManager["level"].Size = new Vector2(150, 20.0f);
            guiManager["level"].Color = Color.Black;

            guiManager.AddLabel("time", font, "Timer: " + timer);
            guiManager["time"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 70.0f);
            guiManager["time"].Size = new Vector2(200.0f, 75.0f);
            guiManager["time"].Color = Color.Black;

            guiManager.AddLabel("lives", font, "Lives: " + player.Lives);
            guiManager["lives"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 100.0f);
            guiManager["lives"].Size = new Vector2(150.0f, 20.0f);
            guiManager["lives"].Color = Color.Black;

            guiManager.AddLabel("points", font, "Points: " + player.Point);
            guiManager["points"].Position = new Vector2(guage.Position.X + guage.Position.Width + 10, 130.0f);
            guiManager["points"].Size = new Vector2(150.0f, 20.0f);
            guiManager["points"].Color = Color.Black;

            guiManager.AddPicture("tmp", gameRef.Content.Load<Texture2D>("Freezling"));
            guiManager["tmp"].Position = new Vector2(guage.Position.X + guage.Position.Width + 30, 200.0f);
            guiManager["tmp"].Size = new Vector2(200.0f, 200.0f);

            guiManager.AddButton("pause", "PAUSE", guage.Position.X + guage.Position.Width + 10, 400, 200.0f, 75.0f);

            guiManager.AddButton("btnMainMenu", "Menu", guage.Position.X + guage.Position.Width + 10, 500, 200.0f, 75.0f);

            guiManager.AddButton("btnExit", "Exit", guage.Position.X + guage.Position.Width + 10, 600, 200.0f, 75.0f);

            btnMainMenu = guiManager["btnMainMenu"] as Button;
            btnMainMenu.Click += (control, button) =>
            {
                GameState MainMenu = this.parent[GameStateType.Playing];
                if (MainMenu != null)
                {
                    this.parent.PushState(MainMenu);

                    MainMenu MainMenuState = new MainMenu(this.gameRef, this.renderer, this.parent);
                    MainMenu.Initialize();
                    this.parent.PushState(MainMenuState);

                }
            };

            btnExit = guiManager["btnExit"] as Button;
            btnExit.Click += (control, button) =>
            {
                gameRef.Exit();
            };

            try
            {
                highScore = ioManager.LoadHighScore();
            }
            catch (Exception)
            {
                ioManager.SaveHighScore(0);
                highScore = 0;
            }
        }
예제 #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
             PresentationParameters pp = GraphicsDevice.PresentationParameters;
            renderer = new EffectRenderer( GraphicsDevice );
            renderer.AddLayer( BlendState.AlphaBlend, Content.Load<Effect>( "basic" ) );
            renderer[ 0 ].Destination = new Rectangle( 0, 0, pp.BackBufferWidth, pp.BackBufferHeight );
            renderer.AddLayer( BlendState.Additive );
            renderer[ 1 ].Destination = renderer[ 0 ].Destination;
            renderer.AddLayer(BlendState.AlphaBlend, Content.Load<Effect>("basic"));
            renderer[2].Destination = renderer[0].Destination;

            stateManager = new StateManager(this);
            Components.Add(stateManager);

            play = new Play( this, renderer, stateManager );
            mainMenu = new MainMenu(this, renderer, stateManager);
            endState = new EndState(this, renderer, stateManager);

            stateManager.RegisterState( GameStateType.Playing, play );
            stateManager.RegisterState(GameStateType.MainMenu, mainMenu);
            stateManager.RegisterState(GameStateType.OptionsMenu, endState);

            stateManager.PushState( mainMenu );
            stateManager.Initialize();

            // TODO: use this.Content to load your game content here
        }