コード例 #1
0
ファイル: Lightning.cs プロジェクト: XZelnar/MicroWorld
        public Lightning(Vector2 p1, Vector2 p2, float width = 2f, int life = 60, int detailLevel = 6, bool sound = false, 
            float volume = 0.1f)
        {
            sound = false;//TODO rm

            MaxLife = life;
            w = width;
            GEN_DEPTH = detailLevel;

            Position = p1;

            float l = (p2 - p1).Length() * 4;
            rot = (float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
            transform = Matrix.CreateRotationZ(rot);
            fbo = new RenderTarget2D(GraphicsEngine.Renderer.GraphicsDevice, (int)l + 64, (int)l + 64);

            GenLightning(new Vector2(32, 32 + l / 2), new Vector2(32 + l, 32 + l / 2));
            var r = GraphicsEngine.Renderer;
            r.EnableFBO(fbo);
            r.GraphicsDevice.Clear(Color.Transparent);
            r.BeginUnscaled();
            DrawFBO(r);
            r.End();
            r.DisableFBO();

            if (sound)
                _sound = Sound.Sounds.tesla.Play(volume, (float)(new Random().Next(-250, 250)) / 1000f, 0f);
        }
コード例 #2
0
        public Lightning(Vector2 p1, Vector2 p2, float width = 2f, int life = 60, int detailLevel = 6, bool sound = false,
                         float volume = 0.1f)
        {
            sound = false;//TODO rm

            MaxLife   = life;
            w         = width;
            GEN_DEPTH = detailLevel;

            Position = p1;

            float l = (p2 - p1).Length() * 4;

            rot       = (float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
            transform = Matrix.CreateRotationZ(rot);
            fbo       = new RenderTarget2D(GraphicsEngine.Renderer.GraphicsDevice, (int)l + 64, (int)l + 64);

            GenLightning(new Vector2(32, 32 + l / 2), new Vector2(32 + l, 32 + l / 2));
            var r = GraphicsEngine.Renderer;

            r.EnableFBO(fbo);
            r.GraphicsDevice.Clear(Color.Transparent);
            r.BeginUnscaled();
            DrawFBO(r);
            r.End();
            r.DisableFBO();

            if (sound)
            {
                _sound = Sound.Sounds.tesla.Play(volume, (float)(new Random().Next(-250, 250)) / 1000f, 0f);
            }
        }
コード例 #3
0
        public override void InGameUpdate()
        {
            base.Update();

            MutateLightning();
            var r = GraphicsEngine.Renderer;

            r.EnableFBO(fbo);
            r.GraphicsDevice.Clear(Color.Transparent);
            r.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);
            DrawFBO(r);
            r.End();
            r.DisableFBO();
            //var a = new System.IO.FileStream("C:/tp.png", System.IO.FileMode.Create);
            //fbo.SaveAsPng(a, fbo.Width, fbo.Height);
            //a.Close();

            curLife++;
            if (curLife >= MaxLife)
            {
                IsDead = true;
                if (_sound != null)
                {
                    _sound.Stop();
                    _sound.Dispose();
                    Sound.SoundManager.instances.Remove(_sound);
                    _sound = null;
                }
            }
        }
コード例 #4
0
ファイル: Lightning.cs プロジェクト: XZelnar/MicroWorld
 public override void Dispose()
 {
     fbo.Dispose();
     if (_sound != null)
     {
         _sound.Stop();
         _sound.Dispose();
         _sound = null;
     }
     base.Dispose();
 }
コード例 #5
0
 public override void Dispose()
 {
     fbo.Dispose();
     if (_sound != null)
     {
         _sound.Stop();
         _sound.Dispose();
         _sound = null;
     }
     base.Dispose();
 }
コード例 #6
0
ファイル: Lightning.cs プロジェクト: XZelnar/MicroWorld
        public override void InGameUpdate()
        {
            base.Update();

            MutateLightning();
            var r = GraphicsEngine.Renderer;
            r.EnableFBO(fbo);
            r.GraphicsDevice.Clear(Color.Transparent);
            r.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone);
            DrawFBO(r);
            r.End();
            r.DisableFBO();
            //var a = new System.IO.FileStream("C:/tp.png", System.IO.FileMode.Create);
            //fbo.SaveAsPng(a, fbo.Width, fbo.Height);
            //a.Close();

            curLife++;
            if (curLife >= MaxLife)
            {
                IsDead = true;
                if (_sound != null)
                {
                    _sound.Stop();
                    _sound.Dispose();
                    Sound.SoundManager.instances.Remove(_sound);
                    _sound = null;
                }
            }
        }