コード例 #1
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.

            spriteBatch = new SpriteBatch(GraphicsDevice);
            SceneController.LoadContent(Content, Window);
            UIMapController.UiMapReaderinitializer(spriteBatch, Window, Content);
            PlayerController.Font = Content.Load <SpriteFont>("myFont");
            InptController.initialize(PlayerController.Font);
            textures          = new Texture2D[3];
            textures[0]       = Content.Load <Texture2D>("grass");
            textures[1]       = Content.Load <Texture2D>("water");
            textures[2]       = Content.Load <Texture2D>("path");
            towerTextures     = new Texture2D[1];
            towerTextures[0]  = Content.Load <Texture2D>("Enemy");
            projectileTexture = towerTextures[0];
            enemyTextures     = new Texture2D[1];
            enemyTextures[0]  = Content.Load <Texture2D>("Enemy");
            mapNames          = XmlReader.GetNames();
            interactableMenu  = new InteractableMenu(mapNames, Content.Load <SpriteFont>("myFont"));
            tileHelpMenu      = XmlReader.GetHelpMenu(spriteBatch, PlayerController.Font, "TileHelpMenu");
            gameHelpMenu      = XmlReader.GetHelpMenu(spriteBatch, PlayerController.Font, "GameHelpMenu");



            // TODO: use this.Content to load your game content here
        }
コード例 #2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            //checks which game state the game currently is in.
            switch (SceneController.CurrentState)
            {
            case SceneController.State.LevelPicker:
                if (nameChosen && !helpMenuActive)
                {
                    UIMapController.UIMapReaderUpdate(gameTime);
                }
                else if (!helpMenuActive)
                {
                    InptController.MapUDrawpdate(spriteBatch);
                }

                if (helpMenuActive)
                {
                    tileHelpMenu.Draw(spriteBatch);
                }


                break;

            case SceneController.State.HighScore:
                if (mapHasBeenSelected && !helpMenuActive)
                {
                    selectedMap.DrawMap(spriteBatch, textures);
                    if (!hasBeenCalledd)
                    {
                        WaveController.Initilazie(selectedMap.PathPoints, enemyTextures);
                        PlayerController.Initalize(spriteBatch);
                        UITowerController.Initilalize(towerTextures, projectileTexture);
                        hasBeenCalledd = true;
                    }
                    WaveController.Update(spriteBatch);
                    PlayerController.draw(spriteBatch);
                    TowerController.Update(gameTime, spriteBatch);
                }
                else if (!helpMenuActive)
                {
                    interactableMenu.Draw(spriteBatch);
                }

                if (helpMenuActive)
                {
                    gameHelpMenu.Draw(spriteBatch);
                }



                break;

            case SceneController.State.Quit:
                this.Exit();
                break;

            default:
                SceneController.MenuDraw(spriteBatch);
                break;
            }

            spriteBatch.End();

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
コード例 #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //checks which game state the game currently is in.
            switch (SceneController.CurrentState)
            {
            case SceneController.State.LevelPicker:
                KeyboardState keyboardState = Keyboard.GetState();
                if (!nameChosen && !helpMenuActive)    //checks if the name is chosen and if the help menu is active.
                {
                    nameChosen = InptController.InputUpdate(gameTime);
                }
                if (!helpMenuActive)    //checks if the help menu is active.
                {
                    if (gameTime.TotalGameTime.TotalMilliseconds > delay + previouslyActiveMenuTime && keyboardState.IsKeyDown(Keys.H))
                    {
                        helpMenuActive           = true;
                        previouslyActiveMenuTime = gameTime.TotalGameTime.TotalMilliseconds;
                    }
                }
                else if (helpMenuActive)
                {
                    if (keyboardState.IsKeyDown(Keys.H) && gameTime.TotalGameTime.TotalMilliseconds > delay + previouslyActiveMenuTime)
                    {
                        helpMenuActive           = false;
                        previouslyActiveMenuTime = gameTime.TotalGameTime.TotalMilliseconds;
                    }
                }
                break;

            case SceneController.State.HighScore:
                KeyboardState keyboardState1 = Keyboard.GetState();
                if (mapHasBeenSelected && !helpMenuActive)
                {
                    selectedMap.MapUpdate();
                }
                if (!helpMenuActive)
                {
                    if (gameTime.TotalGameTime.TotalMilliseconds > delay + previouslyActiveMenuTime && keyboardState1.IsKeyDown(Keys.H))
                    {
                        helpMenuActive           = true;
                        previouslyActiveMenuTime = gameTime.TotalGameTime.TotalMilliseconds;
                    }
                }
                else if (helpMenuActive)
                {
                    if (keyboardState1.IsKeyDown(Keys.H) && gameTime.TotalGameTime.TotalMilliseconds > delay + previouslyActiveMenuTime)
                    {
                        helpMenuActive           = false;
                        previouslyActiveMenuTime = gameTime.TotalGameTime.TotalMilliseconds;
                    }
                }
                UITowerController.Update();

                break;

            case SceneController.State.Quit:
                this.Exit();
                break;

            default:
                SceneController.CurrentState = SceneController.MenuUpdate(gameTime);
                break;
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }