Draw() public method

Draws the animated player.
public Draw ( GameTime gameTime, SpriteBatch spriteBatch ) : void
gameTime Microsoft.Xna.Framework.GameTime
spriteBatch Microsoft.Xna.Framework.Graphics.SpriteBatch
return void
Example #1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue); // Draw background

            spriteBatch.Begin();

            for (int i = 0; i < bullets.Count; i++) // Draw bullets
            {
                bullets[i].Draw(spriteBatch);
            }

            for (int i = 0; i < platforms.Count; i++) // Draw platforms
            {
                platforms[i].Draw(spriteBatch);
            }

            for (int i = 0; i < enemies.Count; i++) // Draw enemies and their health bars
            {
                enemies[i].Draw(spriteBatch);
                healthBars[i].Draw(spriteBatch, gun.Damage);
            }

            player.Draw(spriteBatch);  // Draw player

            glasses.Draw(spriteBatch); // Draw glasses

            if (isTurnedLeft == true)
            {
                gun.DrawLeft(spriteBatch); // Draw left gun
            }
            else
            {
                gun.DrawRight(spriteBatch);                                                                 // Draw right gun
            }
            spriteBatch.Draw(crosshairTex, new Vector2(mouseState.X - 10, mouseState.Y - 10), Color.White); // Draw crosshair

            spriteBatch.End();

            base.Draw(gameTime);
        }
Example #2
0
        /// <summary>
        /// Draw everything in the level from background to foreground.
        /// </summary>
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //for (int i = 0; i <= EntityLayer; ++i)
            //    spriteBatch.Draw(layers[i], Vector2.Zero, Color.White);

            DrawTiles(spriteBatch);
            //DrawStrip(spriteBatch);
            foreach (Gem gem in gems)
            {
                gem.Draw(gameTime, spriteBatch);
            }

            Player.Draw(gameTime, spriteBatch);

            foreach (Enemy enemy in enemies)
            {
                enemy.Draw(gameTime, spriteBatch);
            }

            //for (int i = EntityLayer + 1; i < layers.Length; ++i)
            //    spriteBatch.Draw(layers[i], Vector2.Zero, Color.White);
        }
Example #3
0
        /// <summary>
        /// Draw everything in the level from background to foreground.
        /// </summary>
        public void Draw(GraphicsDevice graphicsDevice, GameTime gameTime, SpriteBatch spriteBatch)
        {
            for (int i = 0; i <= EntityLayer; ++i)
            {
                spriteBatch.Draw(layers[i], Vector2.Zero, Color.White);
            }

            if (IsLoading)
            {
                Rectangle titleSafeArea = graphicsDevice.Viewport.TitleSafeArea;
                Vector2   center        = new Vector2(titleSafeArea.X + titleSafeArea.Width / 2.0f,
                                                      titleSafeArea.Y + titleSafeArea.Height / 2.0f);

                Vector2 statusSize = new Vector2(loadingOverlay.Width, loadingOverlay.Height);
                spriteBatch.Draw(loadingOverlay, center - statusSize / 2, Color.White);
            }
            else
            {
                DrawTiles(spriteBatch);

                foreach (Gem gem in gems)
                {
                    gem.Draw(gameTime, spriteBatch);
                }

                Player.Draw(gameTime, spriteBatch);

                foreach (Enemy enemy in enemies)
                {
                    enemy.Draw(gameTime, spriteBatch);
                }

                for (int i = EntityLayer + 1; i < layers.Length; ++i)
                {
                    spriteBatch.Draw(layers[i], Vector2.Zero, Color.White);
                }
            }
        }
Example #4
0
        protected void DrawGameState(SpriteBatch spritebatch)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            var transformMatrix = camera.GetViewMatrix();

            spriteBatch.Begin(transformMatrix: transformMatrix);
            {
                foreach (Enemy e in enemies)
                {
                    e.Draw(spriteBatch);
                }
                map.Draw(spriteBatch);
                Debug.WriteLine("goal" + (goal == null));
                goal.Draw(spriteBatch);
            }

            player.Draw(spriteBatch);
            spriteBatch.End();

            spriteBatch.Begin();
            spriteBatch.DrawString(arialFont, "Score : " + score.ToString(),
                                   new Vector2(20, 20), Color.Orange);



            for (int i = 0; i < lives; i++)

            {
                Debug.WriteLine("heart" + (heart == null));
                spriteBatch.Draw(heart, new Vector2(ScreenWidth - 80 - i * 20,
                                                    20), Color.White);
            }

            spriteBatch.End();
        }
Example #5
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)
        {
            float offset;

            GraphicsDevice.Clear(Color.Black);


            var viewMatrix       = camera.GetViewMatrix();
            var projectionMatrix = Matrix.CreateOrthographicOffCenter(0, viewWidth, viewHeight, 0, 0f, -1f);

            // TODO: Add your drawing code here
            spriteBatch.Begin(transformMatrix: viewMatrix);
            switch (gameState)
            {
            case GAME_STATE_MENU:
                offset = arialFont.MeasureString("Zander's Platformer").X / 2;
                spriteBatch.DrawString(arialFont, "Zander's Platformer", new Vector2(viewWidth / 2 - offset, 80), Color.Red);
                offset = arialFont.MeasureString("Press Enter").X / 2;
                spriteBatch.DrawString(arialFont, "Press Enter", new Vector2(viewWidth / 2 - offset, 120), Color.Red);
                break;

            case GAME_STATE_GAME:
                GraphicsDevice.Clear(Color.CornflowerBlue);
                mapRenderer.Draw(map, ref viewMatrix, ref projectionMatrix);
                player.Draw(spriteBatch);
                foreach (Enemy e in enemies)
                {
                    e.Draw(spriteBatch);
                }
                goal.Draw(spriteBatch);


                //HUD
                for (int i = 0; i < lives; i++)
                {
                    spriteBatch.Draw(heart, new Vector2(viewWidth - 80 - i * 20, 20) + camera.Position, Color.White);
                }
                spriteBatch.DrawString(arialFont, "Score: " + score.ToString(), new Vector2(20, 20) + camera.Position, Color.Black);
                break;

            case GAME_STATE_GAMEOVER:
                offset = arialFont.MeasureString("Game Over").X / 2;
                spriteBatch.DrawString(arialFont, "Game Over", new Vector2(viewWidth / 2 - offset, 80), Color.Red);
                offset = arialFont.MeasureString("Press Enter to retry").X / 2;
                spriteBatch.DrawString(arialFont, "Press Enter to retry", new Vector2(viewWidth / 2 - offset, 120), Color.Red);
                break;

            case GAME_STATE_WIN:
                offset = arialFont.MeasureString("You win!").X / 2;
                spriteBatch.DrawString(arialFont, "You win!", new Vector2(viewWidth / 2 - offset, 80), Color.Red);
                offset = arialFont.MeasureString("Score: " + score.ToString()).X / 2;
                spriteBatch.DrawString(arialFont, "Score: " + score.ToString(), new Vector2(viewWidth / 2 - offset, 100), Color.Red);
                offset = arialFont.MeasureString("Life Multiplier: " + lives.ToString()).X / 2;
                spriteBatch.DrawString(arialFont, "Life Multiplier: " + lives.ToString(), new Vector2(viewWidth / 2 - offset, 120), Color.Red);
                int finalScore = score * lives;
                offset = arialFont.MeasureString("Final Score: " + finalScore.ToString()).X / 2;
                spriteBatch.DrawString(arialFont, "Final Score: " + finalScore.ToString(), new Vector2(viewWidth / 2 - offset, 140), Color.Red);
                offset = arialFont.MeasureString("Press Enter to play again").X / 2;
                spriteBatch.DrawString(arialFont, "Press Enter to play again", new Vector2(viewWidth / 2 - offset, 180), Color.Red);
                break;
            }
            spriteBatch.End();

            base.Draw(gameTime);
        }
Example #6
0
        public static void Main()
        {
            #region Window Initialization

            Vector2 screenSize = new Vector2(256, 224);
            SetTargetFPS(60);

            InitWindow((int)screenSize.x, (int)screenSize.y, "Platformer");

            #endregion

            #region General Initialization

            Player player = new Player(new Vector2(200, 20));

            Camera camera = new Camera(0.25f);
            camera.pos = player.pos;
            Vector2 screenOffset = screenSize / 2;

            #endregion

            #region Level Initialization

            Sector testLevel = new Sector("data/level1.txt");

            #endregion

            while (!WindowShouldClose())
            {
                //Greater state machine for game state

                #region Update

                player.Update(testLevel.colliders);
                camera.Update(player.pos);

                #endregion

                #region Draw

                //Initialization

                BeginDrawing();
                ClearBackground(Color.BLACK);
                screenOffset = screenSize / 2;

                //Draw background color or gradient
                DrawRectangleGradientV(0, 0, (int)screenSize.x, (int)screenSize.y, Color.DARKBLUE, Color.BLACK);

                //Draw background elements, farthest to closest from camera

                //Draw foreground elements

                DebugOptions.DrawSectorColliders(testLevel, camera.pos, screenOffset);
                player.Draw(camera.pos - (player.size / 2), screenOffset);
                //player.DrawColliders();

                //Draw particle effects and other screen space effects

                //Draw UI elements

                //Termination

                EndDrawing();

                #endregion
            }

            CloseWindow();
        }