Beispiel #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);

            //Sends data to my super-class for all to use.
            Position.content      = Content;
            Position.ScreenWidth  = graphics.GraphicsDevice.Viewport.Width;
            Position.ScreenHeight = graphics.GraphicsDevice.Viewport.Height;

            //Create and load my High Scores.
            highScore = new HighScoreClass(Content);
            highScore.LoadScores();
            highScore.SetScores();

            //Create my managers.
            gameManager  = new GameManager(graphics.GraphicsDevice.Viewport, new Vector2(50, 50), 10, 3, 100);
            menuManager  = new MenuManager();
            scoreManager = new ScoreManager(highScore, Content);
            // TODO: use this.Content to load your game content here
        }
Beispiel #2
0
        //Update everything.
        public void Update(GameTime gameTime)
        {
            km.Update();
            if (inputName == true)
            {
                //If you are inputting a name, blink the last "|" every 800 milliseconds.
                twinkleTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (twinkleTimer > 800)
                {
                    twinkleTimer = 0;
                    if (twinkle == false)
                    {
                        twinkle = true;
                    }
                    else if (twinkle == true)
                    {
                        twinkle = false;
                    }
                }
                if (twinkle == true)
                {
                    input.Text = "Input name: " + name + "|";
                }
                else
                {
                    input.Text = "Input name: " + name + " ";
                }

                //If pressed anything is true, yet you are not pressing anything, turn boolean false.
                if (km.InputKey() == false && pressedAnything == true)
                {
                    pressedAnything = false;
                }

                //Makes this char something that would never be used. Hopefully.
                char last = '$';

                char remember = ' ';
                int  lastNum  = 0;
                bool destroy  = false;

                //If pressed back, make up the entire name again but with one less char.
                if (km.Key(Keys.Back))
                {
                    //input.GetText = "";
                    string rememberName = name;
                    name = "";
                    for (int i = 0; i < rememberName.Length - 1; i++)
                    {
                        name += rememberName[i];
                    }
                }

                //If pressed enter, send in the new score along with the inputed name. Reset score afterwards and get new scores.
                if (km.Key(Keys.Enter))
                {
                    inputName = false;
                    highScores.NewScore(currentScore, name);
                    name         = "";
                    currentScore = 0;
                    highScores.SetScores();
                    highScores.LoadScores();
                    GetScore();
                }

                //If pressed a button, input the character pressed into the string where you are writing your name.
                if (km.InputKey())
                {
                    KeyGrabber.InboundCharEvent += (inboundCharacter) =>
                    {
                        if (pressedAnything == false)
                        {
                            pressedAnything = true;

                            //Only append characters that exist in the spritefont.
                            if (inboundCharacter < 32)
                            {
                                return;
                            }

                            if (inboundCharacter > 126)
                            {
                                return;
                            }

                            name += inboundCharacter;

                            //In order to counter writing an infinite number of the same character which it was doing, this program here erases the new character if it is the same as the last one.
                            if (name != null)
                            {
                                for (int i = 0; i < name.Length; i++)
                                {
                                    if (name[i] == remember)
                                    {
                                        destroy = true;
                                    }
                                    if (destroy == true)
                                    {
                                        name.Remove(i);
                                        //i--;
                                        break;
                                    }
                                    else
                                    {
                                        remember = name[i];
                                    }
                                    lastNum = i;
                                }
                            }

                            //In the end, insert the last pressed character into "last".
                            if (name != null)
                            {
                                last = name[lastNum];
                            }
                        }
                    };
                }
                //If it is anything but $, insert it into the string.
                if (last != '$')
                {
                    input.Text += last;
                }
            }
            //keyinput
        }
Beispiel #3
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);

            //Sends data to my super-class for all to use.
            Position.content = Content;
            Position.ScreenWidth = graphics.GraphicsDevice.Viewport.Width;
            Position.ScreenHeight = graphics.GraphicsDevice.Viewport.Height;

            //Create and load my High Scores.
            highScore = new HighScoreClass(Content);
            highScore.LoadScores();
            highScore.SetScores();

            //Create my managers.
            gameManager = new GameManager(graphics.GraphicsDevice.Viewport, new Vector2(50, 50), 10, 3, 100);
            menuManager = new MenuManager();
            scoreManager = new ScoreManager(highScore, Content);
            // TODO: use this.Content to load your game content here
        }