コード例 #1
0
ファイル: PlayingState.cs プロジェクト: IMeeus/GameDevProject
        public override void Draw(SpriteBatch spriteBatch)
        {
            _game.GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(sortMode: SpriteSortMode.FrontToBack);
            _entityManager.Draw(spriteBatch);
            _levelManager.Draw(spriteBatch);
            _healthbar.Draw(spriteBatch);
            _scoreBoard.Draw(spriteBatch, "Score: " + Score, false);
            spriteBatch.End();
        }
コード例 #2
0
 /// <summary>
 /// Draws things attached to the character
 /// </summary>
 public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
 {
     // draw the healthbar if the characterr is not down
     if (this.attributes.HP > 0)
     {
         healthbar.Draw(gameTime, spriteBatch);
         if (weapon.IsAttacking)
         {
             weapon.Draw(gameTime, spriteBatch);
         }
     }
     // draw the weapon if an attack animation is being played
     base.Draw(gameTime, spriteBatch);
 }
コード例 #3
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            // Background
            StateManager.GetState(2).Draw(spriteBatch);
            spriteBatch.DrawRectangle(Main.WindowRectangle, Color.Black * .5f);

            // UI
            background.Draw(spriteBatch);
            if (!isHealing)
            {
                vsText.Draw(spriteBatch);
            }

            myHealthBar.Draw(spriteBatch);
            enemyHealthbar.Draw(spriteBatch);

            myRankName.Draw(spriteBatch);
            enemyRankName.Draw(spriteBatch);

            switch (character.weapon)
            {
            case Character.Weapon.Axe: spriteBatch.DrawSprite(axeIcon, MyWeaponPosition); break;

            case Character.Weapon.Sword: spriteBatch.DrawSprite(swordIcon, MyWeaponPosition); break;

            case Character.Weapon.Shield: spriteBatch.DrawSprite(shieldIcon, MyWeaponPosition); break;
            }

            switch (enemyCharacter.weapon)
            {
            case Character.Weapon.Axe: spriteBatch.DrawSprite(axeIcon, EnemyWeaponPosition); break;

            case Character.Weapon.Sword: spriteBatch.DrawSprite(swordIcon, EnemyWeaponPosition); break;

            case Character.Weapon.Shield: spriteBatch.DrawSprite(shieldIcon, EnemyWeaponPosition); break;
            }
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: HendrikMennen/Dash2D
        protected override void Draw(GameTime gameTime)
        {
            float width      = (screenWidth / camera.Zoom);
            float height     = (int)(screenHeight / camera.Zoom);
            var   viewMatrix = camera.TranslationMatrix;
            float frameRate  = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds; //FPS
            var   deltaTime  = (float)gameTime.ElapsedGameTime.TotalSeconds;

            frameCounter.Update(deltaTime);
#if true
            //RENDER TARGET MAIN
            GraphicsDevice.SetRenderTarget(mainTarget);
            GraphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, viewMatrix);
            level.Draw(spriteBatch);
            if (!menu.Open && !chat.Open)
            {
                inv.DrawPreview(spriteBatch);
            }
            spriteBatch.End();
            //MAIN END

            //RENDER TARGET LIGHT
            GraphicsDevice.SetRenderTarget(lightsTarget);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, null, null, null, viewMatrix);
            level.DrawLight(spriteBatch);
            spriteBatch.End();
            //LIGHT END

            //SPLICE RENDER TARGETS TOGETHER
            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

            basiclight.Parameters["lightMask"].SetValue(lightsTarget);
            basiclight.Parameters["AmbientIntensity"].SetValue(time.CurrentTime);
            basiclight.CurrentTechnique.Passes[0].Apply();

            spriteBatch.Draw(mainTarget, Vector2.Zero, Color.White);
            //spriteBatch.Draw(shadowTarget, Vector2.Zero, Color.White);
            spriteBatch.End();
            //

            //MAPEDITOR & INTERFACE
            int xStart = 10; //UI START X
            switch (currentGamestate)
            {
            case GameState.Running:
                spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);     //UI
                inv.Draw(spriteBatch);
                hb.Draw(spriteBatch);
                spriteBatch.End();
                if (Global.showHitboxes)
                {
                    spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, camera.TranslationMatrix);
                    editor.DrawPreview(spriteBatch);
                    spriteBatch.End();
                }
                break;

            case GameState.Editor:
                xStart += editor.TileSelectorBackground.Width;
                spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, camera.TranslationMatrix);
                editor.DrawPreview(spriteBatch);
                spriteBatch.End();

                spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
                editor.Draw(spriteBatch);
                if (editor.currentEditorMode == MapEditor.EditorMode.EntityAdd)
                {
                    inv.Draw(spriteBatch);
                }
                spriteBatch.End();

                spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, editor.TilesetView.TranslationMatrix);
                editor.DrawTileset(spriteBatch);
                spriteBatch.End();
                break;

            case GameState.Pause:
                break;
            }

            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp); //UI

            foreach (var mob in (level.mobs))
            {
                mob.DrawChatBubble(spriteBatch);
            }

#if true
            spriteBatch.DrawString(font, "X: " + level.getClientPlayer().Position.X.ToString(), new Vector2(xStart, 10), Color.Black);
            spriteBatch.DrawString(font, "Y: " + level.getClientPlayer().Position.Y.ToString(), new Vector2(xStart + 120, 10), Color.Black);
            spriteBatch.DrawString(font, "Map: " + level.currentMapName, new Vector2(xStart, 40), Color.Black);
            spriteBatch.DrawString(font, "FPS: " + Math.Round(frameCounter.CurrentFramesPerSecond), new Vector2(xStart, 70), Color.Black);
            spriteBatch.DrawString(font, "RenderedTiles: " + Level.RenderedTiles + " at Zoom: " + Math.Round(Global.camera.Zoom * 10) / 10, new Vector2(xStart, 100), Color.Black);
            spriteBatch.DrawString(font, "TileID: " + level.CurrentMap.getTile(0, level.getClientPlayer().CenterPosition + new Vector2(0, level.getClientPlayer().height / 2)), new Vector2(xStart, 130), Color.Black);
            if (Game1.online)
            {
                spriteBatch.DrawString(font, "Receiving: " + Math.Round((float)NetCode.RecievingBytesPerSecond / 100f) / 10 + "kb/s", new Vector2(xStart, 160), Color.Black);
                spriteBatch.DrawString(font, "Sending: " + Math.Round((float)NetCode.SendingBytesPerSecond / 100f) / 10 + "kb/s", new Vector2(xStart, 190), Color.Black);
            }
#endif
            chat.render(spriteBatch);
            menu.render(spriteBatch);

            spriteBatch.Draw(pointer, new Rectangle(mouseX, mouseY, pointer.Width, pointer.Height), Color.MonoGameOrange);
            spriteBatch.End();
            //
#endif

            base.Draw(gameTime);
        }