コード例 #1
0
        public virtual void Draw(SpriteBatch spriteBatch, Texture2D texture, Color color, int offX = 0, int offY = 0)
        {
            if (texture == null)
            {
                return;
            }
            Rectangle des =
                Globals.TheCarmera.ToViewRegion(new Rectangle((int)PositionInWorld.X - Texture.Left + offX,
                                                              (int)PositionInWorld.Y - Texture.Bottom + offY,
                                                              texture.Width,
                                                              texture.Height));

            if (color == Color.Black)
            {
                spriteBatch.End();
                JxqyGame.BeginSpriteBatch(spriteBatch, Globals.TheGame.GrayScaleEffect);


                spriteBatch.Draw(texture,
                                 des,
                                 null,
                                 Color.White,
                                 0,
                                 new Vector2(0),
                                 SpriteEffects.None,
                                 0);

                spriteBatch.End();
                JxqyGame.BeginSpriteBatch(spriteBatch);
            }
            else
            {
                spriteBatch.Draw(texture,
                                 des,
                                 null,
                                 color,
                                 0,
                                 new Vector2(0),
                                 SpriteEffects.None,
                                 0);
            }
        }
コード例 #2
0
        /// <summary>
        /// Draw map npcs objs magic sprits
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(SpriteBatch spriteBatch)
        {
            if (DrawColor == Color.Black)
            {
                spriteBatch.End();
                JxqyGame.BeginSpriteBatch(spriteBatch, Globals.TheGame.GrayScaleEffect);

                DrawLayer(spriteBatch, 0);

                spriteBatch.End();
                JxqyGame.BeginSpriteBatch(spriteBatch);
            }
            else
            {
                DrawLayer(spriteBatch, 0);
            }

            var start        = GetStartTileInView();
            var end          = GetEndTileInView();
            var magicSprites = MagicManager.MagicSpritesInView;
            var npcs         = NpcManager.NpcsInView;
            var objs         = ObjManager.ObjsInView;

            //Draw body
            foreach (var obj in objs)
            {
                if (obj.Kind == 2)
                {
                    obj.Draw(spriteBatch);
                }
            }

            for (var y = (int)start.Y; y < (int)end.Y; y++)
            {
                for (var x = (int)start.X; x < (int)end.X; x++)
                {
                    Texture2D texture = GetTileTexture(x, y, 1);
                    if (IsLayerDraw(1) && texture != null)
                    {
                        if (DrawColor == Color.Black)
                        {
                            spriteBatch.End();
                            JxqyGame.BeginSpriteBatch(spriteBatch, Globals.TheGame.GrayScaleEffect);

                            DrawTile(spriteBatch, texture, new Vector2(x, y), 1f);

                            spriteBatch.End();
                            JxqyGame.BeginSpriteBatch(spriteBatch);
                        }
                        else
                        {
                            DrawTile(spriteBatch, texture, new Vector2(x, y), 1f);
                        }
                    }
                    foreach (var npc in npcs)
                    {
                        if (x == npc.MapX && y == npc.MapY && npc.Kind != 7)
                        {
                            npc.Draw(spriteBatch);
                        }
                    }
                    foreach (var obj in objs)
                    {
                        if (x == obj.MapX && y == obj.MapY && obj.Kind != 2)
                        {
                            obj.Draw(spriteBatch);
                        }
                    }
                    foreach (var magicSprite in magicSprites)
                    {
                        if (x == magicSprite.MapX && y == magicSprite.MapY)
                        {
                            magicSprite.Draw(spriteBatch);
                        }
                    }
                }
            }

            if (DrawColor == Color.Black)
            {
                spriteBatch.End();
                JxqyGame.BeginSpriteBatch(spriteBatch, Globals.TheGame.GrayScaleEffect);

                DrawLayer(spriteBatch, 2);

                spriteBatch.End();
                JxqyGame.BeginSpriteBatch(spriteBatch);
            }
            else
            {
                DrawLayer(spriteBatch, 2);
            }

            //Draw fly npc
            foreach (var npc in npcs)
            {
                if (npc.Kind == 7)
                {
                    npc.Draw(spriteBatch);
                }
            }
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: wt616/JxqyHD
        public override void Draw(SpriteBatch spriteBatch)
        {
            var texture = GetCurrentTexture();

            if (texture == null)
            {
                return;
            }

            //Make new texture is case of texture be locked after draw
            var data = new Color[texture.Width * texture.Height];

            texture.GetData(data);
            texture = new Texture2D(texture.GraphicsDevice, texture.Width, texture.Height);
            texture.SetData(data);

            var tilePosition = new Vector2(MapX, MapY);
            var start        = tilePosition - new Vector2(3, 15);
            var end          = tilePosition + new Vector2(3, 15);

            if (start.X < 0)
            {
                start.X = 0;
            }
            if (start.Y < 0)
            {
                start.Y = 0;
            }
            if (end.X > Globals.TheMap.MapColumnCounts)
            {
                end.X = Globals.TheMap.MapColumnCounts;
            }
            if (end.Y > Globals.TheMap.MapRowCounts)
            {
                end.Y = Globals.TheMap.MapRowCounts;
            }
            var textureRegion = new Rectangle();
            var region        = RegionInWorld;

            foreach (var npc in NpcManager.NpcsInView)
            {
                if (npc.MapY > MapY && !npc.IsHide)
                {
                    Collider.MakePixelCollidedTransparent(region, texture, npc.RegionInWorld, npc.GetCurrentTexture());
                }
            }
            foreach (var magicSprite in MagicManager.MagicSpritesInView)
            {
                if (magicSprite.MapY >= MapY)
                {
                    Collider.MakePixelCollidedTransparent(region, texture, magicSprite.RegionInWorld, magicSprite.GetCurrentTexture());
                }
            }
            for (var y = (int)start.Y; y < (int)end.Y; y++)
            {
                for (var x = (int)start.X; x < (int)end.X; x++)
                {
                    Texture2D tileTexture;
                    if (y > MapY)
                    {
                        tileTexture = Globals.TheMap.GetTileTextureAndRegion(x, y, 1, ref textureRegion);
                        Collider.MakePixelCollidedTransparent(region, texture, textureRegion, tileTexture);
                    }
                    tileTexture = Globals.TheMap.GetTileTextureAndRegion(x, y, 2, ref textureRegion);
                    Collider.MakePixelCollidedTransparent(region, texture, textureRegion, tileTexture);
                }
            }
            base.Draw(spriteBatch, texture);

            if (Globals.OutEdgeSprite != null &&
                !(Globals.OutEdgeNpc != null && Globals.OutEdgeNpc.IsHide))
            {
                var ct = Globals.OutEdgeSprite.GetCurrentTexture();
                if (ct != null)
                {
                    spriteBatch.End();
                    Globals.TheGame.OutEdgeEffect.Parameters["EdgeColor"].SetValue(new Vector4(
                                                                                       Globals.OutEdgeColor.R / 255.0f,
                                                                                       Globals.OutEdgeColor.G / 255.0f,
                                                                                       Globals.OutEdgeColor.B / 255.0f,
                                                                                       Globals.OutEdgeColor.A / 255.0f));
                    Globals.TheGame.OutEdgeEffect.Parameters["radiusx"].SetValue(1.0f / ct.Width);
                    Globals.TheGame.OutEdgeEffect.Parameters["radiusy"].SetValue(1.0f / ct.Height);
                    JxqyGame.BeginSpriteBatch(spriteBatch, Globals.TheGame.OutEdgeEffect);
                    Globals.OutEdgeSprite.Draw(spriteBatch,
                                               ct,
                                               Color.White,
                                               Globals.OffX,
                                               Globals.OffY);
                    spriteBatch.End();
                    JxqyGame.BeginSpriteBatch(spriteBatch);
                }
            }
            if (Globals.OutEdgeNpc != null &&
                !Globals.OutEdgeNpc.IsHide)
            {
                InfoDrawer.DrawLife(spriteBatch, Globals.OutEdgeNpc);
            }
        }