示例#1
0
        public void DrawCircle(SpriteReference sprite, SamplerState samplerState, Vector2 center, int precision, float angleStart, float angleEnd, float radius, float texOffset, float texPrecision, float start, float end, ColorMatrix color, BlendState blend)
        {
            if (start == end)
            {
                return;
            }

            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite?.Texture ?? Pixel, blendState: blend, rasterizerState: RasterizerState, samplerState: samplerState, transform: WorldTransform, projection: Projection, effect: Shader);

            for (int i = 0; i < precision; i++)
            {
                float   angleSlide = (float)i / (precision - 1);
                Vector2 offset     = Util.AngleToVector(MathHelper.Lerp(angleStart, angleEnd, angleSlide));
                var     inside     = center;// + offset * radius * MathHelper.Clamp(start, 0, 1);
                var     outside    = center + offset * radius * MathHelper.Clamp(end, 0, 1);

                var texHorizontal = texPrecision * angleSlide + texOffset;
                var texInside     = 1 - Util.ReverseLerp(MathHelper.Clamp(0, 0, 1), start, end);
                var texOutside    = 1 - Util.ReverseLerp(MathHelper.Clamp(end, 0, 1), start, end);

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(inside, 0), Color.White, new Vector2(texHorizontal, texInside)));
                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(outside, 0), Color.White, new Vector2(texHorizontal, texOutside)));
            }

            PrimitiveBatch.End();
        }
示例#2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            SpriteBatch    = new SpriteBatch(GraphicsDevice);
            PrimitiveBatch = new PrimitiveBatch <VertexPositionColorTexture>(GraphicsDevice);

            Shader      = Content.Load <Effect>("effects");
            ShaderLight = Content.Load <Effect>("effects_light");
        }
示例#3
0
        public SceneTitle(Game game) : base(game)
        {
            Menu       = new TitleUI(this);
            FloorBatch = new PrimitiveBatch <VertexPositionNormalTexture>(GraphicsDevice);

            MorphoPositionBase = new LerpVector2(new Vector2(650, Viewport.Height + 160));
            MorphoHeight       = new LerpFloat(40);
            GroundVelocityBase = new LerpVector2(new Vector2(2, 6) * 0.2f);
            CastleHeight       = new LerpFloat(0);

            var fade = new ScreenFade(this, () => ColorMatrix.Tint(Color.Black), 1, true);


            TitleSM.AddState(TitleState.FadeIn, new TitleStateMachine.Transfer(TitleState.SpeedUp), (state, content, input) => new TitleStateMachine.Data(60));
            TitleSM.AddState(TitleState.SpeedUp, new TitleStateMachine.Transfer(TitleState.MorphoAppear), (state, content, input) => new TitleStateMachine.Data(60));
            TitleSM.AddState(TitleState.MorphoAppear, new TitleStateMachine.Transfer(TitleState.CastleAppear), (state, content, input) => new TitleStateMachine.Data(60));
            TitleSM.AddState(TitleState.CastleAppear, new TitleStateMachine.Transfer(TitleState.TextSlash), (state, content, input) => new TitleStateMachine.Data(320));
            TitleSM.AddState(TitleState.TextSlash, new TitleStateMachine.Transfer(TitleState.TextArrange), (state, content, input) => new TitleStateMachine.Data(40));
            TitleSM.AddState(TitleState.TextArrange, new TitleStateMachine.Transfer(TitleState.Finish), (state, content, input) => new TitleStateMachine.Data(40));
            TitleSM.AddState(TitleState.Finish, new TitleStateMachine.Finish(), (state, content, input) => new TitleStateMachine.Data(0));
            TitleSM.AddOnLeave(TitleState.FadeIn, (input) =>
            {
                fade.Lerp.Set(0, LerpHelper.QuadraticOut, 60);
            });
            TitleSM.AddOnEnter(TitleState.SpeedUp, (input) =>
            {
                GroundVelocityBase.Set(new Vector2(2, 6) * 1.5f, LerpHelper.QuadraticIn, 90);
            });
            TitleSM.AddOnEnter(TitleState.MorphoAppear, (input) =>
            {
                MorphoPositionBase.Set(new Vector2(550, 550), LerpHelper.QuadraticOut, 60);
                MorphoHeight.Set(80, LerpHelper.QuadraticOut, 60);
                CastleHeight.Set(400, LerpHelper.QuadraticOut, 400);
            });
            TitleSM.AddOnEnter(TitleState.TextSlash, (input) =>
            {
                int textX = Viewport.Width / 2;
                int textY = Viewport.Height / 10 + 40;
                MorphoFlash.AddFlash(ColorMatrix.Flat(Color.White), 10);
                TextFlash.AddFlash(ColorMatrix.Flat(Color.Red), 10);
                Particles.Add(new Particle(new SlashEffect(this, 300, 15)
                {
                    Angle = Random.NextFloat(MathHelper.PiOver2 - 0.1f, MathHelper.PiOver2 + 0.1f),
                }, new Vector2(textX, textY)));
                new ScreenShakeRandom(this, 10, 10, LerpHelper.QuadraticOut);
            });
            TitleSM.AddOnLeave(TitleState.TextArrange, (input) =>
            {
                TextFlash.AddFlash(ColorMatrix.Flat(Color.White), 10);
                new ScreenShakeRandom(this, 10, 20, LerpHelper.QuadraticOut);
            });
            TitleSM.Start(TitleState.FadeIn);



            ProtoEffects.Update();
        }
示例#4
0
        public void DrawLine(SpriteReference sprite, Vector2 pos1, Vector2 pos2, float widthMod, float lengthMod, float offset, ColorMatrix color, BlendState blend)
        {
            var delta = pos2 - pos1;
            var dist  = delta.Length();
            var side  = (delta / dist).TurnLeft();
            var width = sprite.Height;

            //SetupNormal(WorldTransform, Projection);
            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite.Texture, blendState: blend, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos1 + side * width * widthMod / 2, 0), Color.White, new Vector2(-offset / sprite.Width, 1)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos1 - side * width * widthMod / 2, 0), Color.White, new Vector2(-offset / sprite.Width, 0)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos2 + side * width * widthMod / 2, 0), Color.White, new Vector2((dist * lengthMod - offset) / sprite.Width, 1)));
            PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos2 - side * width * widthMod / 2, 0), Color.White, new Vector2((dist * lengthMod - offset) / sprite.Width, 0)));
            PrimitiveBatch.End();
        }
示例#5
0
        public void DrawGrappleLine(Vector2 start, Vector2 end, float waveAmplitude, float waveOffset, float waveFrequency, int precision, LerpHelper.Delegate lerp, Color color, BlendState blend)
        {
            SetupColorMatrix(ColorMatrix.Identity, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.LineStrip, texture: Pixel, blendState: blend, rasterizerState: RasterizerState, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);

            var delta   = end - start;
            var lateral = Vector2.Normalize(new Vector2(-delta.Y, delta.X));

            for (int i = 0; i < precision; i++)
            {
                float slide    = (float)i / (precision - 1);
                float posSlide = (float)lerp(0, 1, slide);
                var   offset   = lateral * (float)Math.Sin((slide * waveFrequency + waveOffset) * MathHelper.TwoPi) * (float)Math.Sin(MathHelper.Pi * slide) * waveAmplitude;
                var   pos      = start + posSlide * delta + offset;

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(pos, 0), color, new Vector2(0, 0)));
            }

            PrimitiveBatch.End();
        }
示例#6
0
        public void DrawMissileCurve(SpriteReference sprite, Func <float, Vector2> curve, int precision, Func <float, float> thickness, float start, float end, ColorMatrix color, BlendState blend)
        {
            List <Vector2> points  = new List <Vector2>();
            List <float>   lengths = new List <float>();
            List <Vector2> pivots  = new List <Vector2>();

            LineSet line = new LineSet();

            for (int i = 0; i <= precision; i++)
            {
                line.AddPoint(curve((float)i / precision));
            }

            line.GetBeam(start, end, points, pivots, lengths);

            var dist  = line.TotalDistance;
            var width = sprite.Height;

            SetupColorMatrix(color, WorldTransform, Projection);
            PrimitiveBatch.Begin(PrimitiveType.TriangleStrip, texture: sprite.Texture, blendState: blend, rasterizerState: RasterizerState.CullNone, samplerState: SamplerState.PointWrap, transform: WorldTransform, projection: Projection, effect: Shader);

            for (int i = 0; i < points.Count; i++)
            {
                var point    = points[i];
                var side     = pivots[i];
                var len      = lengths[i];
                var slide    = len / dist;
                var tex      = (slide - start) / (end - start);
                var widthMod = thickness(slide);

                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(point + side * width * widthMod / 2, 0), Color.White, new Vector2(tex, 1)));
                PrimitiveBatch.AddVertex(new VertexPositionColorTexture(new Vector3(point - side * width * widthMod / 2, 0), Color.White, new Vector2(tex, 0)));
            }

            PrimitiveBatch.End();
        }