Example #1
0
        private static void RenderLights()
        {
            if (DXManager.Lights == null || DXManager.Lights.Count == 0)
            {
                return;
            }

            if (LightTexture == null || LightTexture.Disposed)
            {
                LightTexture            = new Texture(DXManager.Device, Settings.ScreenSize.Width, Settings.ScreenSize.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
                LightTexture.Disposing += new EventHandler(LightTexture_Disposing);
                LightSurface            = LightTexture.GetSurfaceLevel(0);
            }

            DXManager.Sprite.Flush();

            Surface OldSurface = DXManager.CurrentSurface;

            DXManager.SetSurface(LightSurface);
            DXManager.Device.Clear(ClearFlags.Target, MapInfo.Lights == LightSetting.Night ? Color.Black : Color.FromArgb(255, 50, 50, 50), 0, 0);


            DXManager.SetBlend(true);

            int   Light;
            Point Location;

            for (int I = 0; I < ObjectList.Count; I++)
            {
                if (ObjectList[I].Light > 0)
                {
                    Light = ObjectList[I].Light;

                    if (Light >= DXManager.Lights.Count)
                    {
                        Light = DXManager.Lights.Count - 1;
                    }

                    Location = ObjectList[I].DisplayRectangle.Location;
                    Location.Offset(((Light + 1) * -65 + Globals.CellWidth) / 2, ((Light + 1) * -50 + Globals.CellHeight) / 2);


                    if (DXManager.Lights[Light] != null && !DXManager.Lights[Light].Disposed)
                    {
                        DXManager.Sprite.Draw2D(DXManager.Lights[Light], PointF.Empty, 0, Location, Color.WhiteSmoke);
                    }
                }
            }


            for (int Y = MapObject.User.Location.Y - ViewRangeY - 5; Y <= MapObject.User.Location.Y + ViewRangeY + 5; Y++)
            {
                if (Y < 0)
                {
                    continue;
                }
                if (Y >= MapSize.Height)
                {
                    break;
                }
                for (int X = MapObject.User.Location.X - ViewRangeX - 5; X < MapObject.User.Location.X + ViewRangeX + 5; X++)
                {
                    if (X < 0)
                    {
                        continue;
                    }
                    if (X >= MapSize.Width)
                    {
                        break;
                    }
                    int ImageIndex = (M2CellInfo[X, Y].FrontImage & 0x7FFF) - 1;
                    if (M2CellInfo[X, Y].Light > 0 && M2CellInfo[X, Y].Light < 10)
                    {
                        Light = M2CellInfo[X, Y].Light * 3;
                        int  FileIndex = M2CellInfo[X, Y].FileIndex;
                        Size S         = Libraries.Objects[FileIndex].GetSize(ImageIndex);
                        Location = new Point(
                            (X + Settings.PlayerOffSet.X - MapObject.User.MovePoint.X) * Globals.CellWidth + MapObject.User.MovingOffSet.X,
                            (Y + Settings.PlayerOffSet.Y - MapObject.User.MovePoint.Y) * Globals.CellHeight + MapObject.User.MovingOffSet.Y + 32);// - S.Height);
                        Location.Offset(((Light + 1) * -65 + Globals.CellWidth) / 2, ((Light + 1) * -50 + Globals.CellHeight) / 2);

                        if (M2CellInfo[X, Y].AnimationFrame > 0)
                        {
                            Location.Offset(Libraries.Objects[FileIndex].GetOffSet(ImageIndex));
                        }

                        if (Light > DXManager.Lights.Count)
                        {
                            Light = DXManager.Lights.Count - 1;
                        }

                        if (DXManager.Lights[Light] != null && !DXManager.Lights[Light].Disposed)
                        {
                            DXManager.Sprite.Draw2D(DXManager.Lights[Light], PointF.Empty, 0, Location, Color.WhiteSmoke);
                        }
                    }
                }
            }

            DXManager.SetBlend(false);
            DXManager.Sprite.Flush();
            DXManager.SetSurface(OldSurface);

            //Draw Light Scene
            DXManager.Device.RenderState.SourceBlend      = Blend.Zero;
            DXManager.Device.RenderState.DestinationBlend = Blend.SourceColor;

            DXManager.Sprite.Draw2D(LightTexture, PointF.Empty, 0, PointF.Empty, Color.White);
            DXManager.Sprite.End();

            DXManager.Sprite.Begin(SpriteFlags.AlphaBlend);
        }
Example #2
0
 public virtual void DrawBlend()
 {
     DXManager.SetBlend(true, 0.3F); //0.8
     Draw();
     DXManager.SetBlend(false);
 }