예제 #1
0
        // draws frame
        protected override void Draw(GameTime gameTime)
        {
            string livesString = "";

            _spriteBatch.Begin();

            _spriteBatch.Draw(backgroundTxr, new Rectangle(0, 0, screenSize.X, screenSize.Y), Color.White); // draws background

            PlayerSprite.Draw(_spriteBatch, gameTime);                                                      // draws PlayerSprite
            coinSprite.Draw(_spriteBatch, gameTime);                                                        // draws coinSprite

            foreach (PlatformSprite platform in levels[levelNumber])
            {
                platform.Draw(_spriteBatch, gameTime);                                                      // how many platforms appear in each level
            }
            for (int i = 0; i < PlayerSprite.lives; i++)
            {
                livesString += "p";
            }

            // draws level and lives and colour
            _spriteBatch.DrawString(HeartFont, livesString, new Vector2(15, 5), Color.White);

            // the size in pixes of the font
            _spriteBatch.DrawString(
                UITextFont,
                "level " + (levelNumber + 1),
                new Vector2(screenSize.X - 15 - UITextFont.MeasureString("level " + (levelNumber + 1)).X, 5),
                Color.White);

            _spriteBatch.End();

            base.Draw(gameTime);
        }
예제 #2
0
파일: Game1.cs 프로젝트: Sferion/JumpThing
        protected override void Draw(GameTime gameTime)
        {
            string livesString = "";

            _spriteBatch.Begin();

            _spriteBatch.Draw(backgroundtxr, new Rectangle(0, 0, screenSize.X, screenSize.Y), Color.White);

            playerSprite.Draw(_spriteBatch, gameTime);
            coinSprite.Draw(_spriteBatch, gameTime);
            foreach (PlatformSprite platform in levels[levelNumber])
            {
                platform.Draw(_spriteBatch, gameTime);
            }

            for (int i = 0; i < playerSprite.lives; i++)
            {
                livesString += "p";
            }

            _spriteBatch.DrawString(heartFont, livesString, new Vector2(15, 10), Color.White);

            uiTextFout.MeasureString("level " + levelNumber);
            _spriteBatch.DrawString(uiTextFout, "level " + (levelNumber + 1), new Vector2(screenSize.X - 15 - uiTextFout.MeasureString("level " + levelNumber).X, 5), Color.White);

            _spriteBatch.End();

            base.Draw(gameTime);
        }
예제 #3
0
        protected override void Draw(GameTime gameTime)
        {
            string livesString = "";

            _spriteBatch.Begin();

            _spriteBatch.Draw(                                                          //Draw background
                backTex,
                new Rectangle(0, 0, screenSize.X, screenSize.Y),
                Color.White
                );

            for (int i = 0; i < lives; i++)
            {
                livesString = livesString + "I";
            }
            _spriteBatch.DrawString(font, "Lives: " + livesString, new Vector2(8, -10), Color.Gray);
            _spriteBatch.DrawString(font, "Lives: " + livesString, new Vector2(5, -13), Color.White);

            Vector2 coinTextSize = font.MeasureString("Coins Collected: " + coinCount.ToString());

            _spriteBatch.DrawString(font, "Coins Collected: " + coinCount.ToString(), new Vector2(screenSize.X - coinTextSize.X - 8, -10), Color.Gray);
            _spriteBatch.DrawString(font, "Coins Collected: " + coinCount.ToString(), new Vector2(screenSize.X - coinTextSize.X - 5, -10), Color.White);

            if (!gameOver)
            {
                Vector2 textSize = font.MeasureString("collect 10 coins for another life!");
                _spriteBatch.DrawString(font, "collect 10 coins for another life!", new Vector2(screenSize.X / 2 - (textSize.X / 2) - 5, screenSize.Y - 55), Color.Gray);
                _spriteBatch.DrawString(font, "collect 10 coins for another life!", new Vector2(screenSize.X / 2 - (textSize.X / 2), screenSize.Y - 52), Color.White);

                player.Draw(_spriteBatch, gameTime);                                        //Draw player

                foreach (PlatformSprite platform in levels[currentLevel])                   //Draw all platforms
                {
                    platform.Draw(_spriteBatch, gameTime);
                }

                coin.Draw(_spriteBatch, gameTime);
            }
            else
            {
                Vector2 textSize = bigFont.MeasureString("GAME OVER");
                _spriteBatch.DrawString(bigFont, "GAME OVER", new Vector2(screenSize.X / 2 - (textSize.X / 2) - 5, screenSize.Y / 2 - (textSize.Y / 2) - 5), Color.White);
                _spriteBatch.DrawString(bigFont, "GAME OVER", new Vector2(screenSize.X / 2 - (textSize.X / 2), screenSize.Y / 2 - (textSize.Y / 2)), Color.DarkRed);
                textSize = font.MeasureString("Press Enter to restart.");
                _spriteBatch.DrawString(font, "Press Enter to restart.", new Vector2(screenSize.X / 2 - (textSize.X / 2) - 5, screenSize.Y / 2 - (textSize.Y / 2) + 45), Color.Gray);
                _spriteBatch.DrawString(font, "Press Enter to restart.", new Vector2(screenSize.X / 2 - (textSize.X / 2), screenSize.Y / 2 - (textSize.Y / 2) + 48), Color.White);
            }

            _spriteBatch.End();
            base.Draw(gameTime);
        }