Example #1
0
            public override void Draw(IDrawDevice device)
            {
                if (gameobj == null)
                {
                    return;
                }

                float timeMult = Time.TimeMult;

                for (int j = 0; j < circleEffectData.Length; j++)
                {
                    ref CircleEffect circle = ref circleEffectData[j];
                    if (circle.Alpha <= 0f)
                    {
                        continue;
                    }

                    int segmentNum = MathF.Clamp(MathF.RoundToInt(MathF.Pow(circle.Radius, 0.65f) * 2.5f), 4, 32);

                    float angle = 0.0f;
                    for (int i = 0; i < segmentNum; i++)
                    {
                        vertices[i].Pos.X = circle.Pos.X + (float)Math.Sin(angle) * circle.Radius;
                        vertices[i].Pos.Y = circle.Pos.Y - (float)Math.Cos(angle) * circle.Radius;
                        vertices[i].Pos.Z = circle.Pos.Z - 10f;
                        vertices[i].Color = new ColorRgba(1f, circle.Alpha);
                        angle            += (MathF.TwoPi / segmentNum);
                    }

                    device.AddVertices(material, VertexMode.LineLoop, vertices, 0, segmentNum);

                    circle.Radius -= timeMult * 0.8f;
                    circle.Alpha  -= timeMult * 0.03f;
                }
Example #2
0
        public void FindCollisionActorsByRadius(float x, float y, float radius, Func <ActorBase, bool> callback)
        {
            AABB aabb = new AABB(x - radius, y - radius, x + radius, y + radius);

            collisions.Query((actor) => {
                if ((actor.CollisionFlags & CollisionFlags.CollideWithOtherActors) == 0)
                {
                    return(true);
                }

                // Find the closest point to the circle within the rectangle
                float closestX = MathF.Clamp(x, actor.AABB.LowerBound.X, actor.AABB.UpperBound.X);
                float closestY = MathF.Clamp(y, actor.AABB.LowerBound.Y, actor.AABB.UpperBound.Y);

                // Calculate the distance between the circle's center and this closest point
                float distanceX = (x - closestX);
                float distanceY = (y - closestY);

                // If the distance is less than the circle's radius, an intersection occurs
                float distanceSquared = (distanceX * distanceX) + (distanceY * distanceY);
                if (distanceSquared < (radius * radius))
                {
                    return(callback(actor));
                }

                return(true);
            }, ref aabb);
        }
Example #3
0
        private void OnRender(IDrawDevice device)
        {
            if (framesLeft <= 0)
            {
                OnCinematicsEnd(true);
                return;
            }

            frameProgress += Time.TimeMult;

            if (frameProgress >= frameDelay)
            {
                frameProgress -= frameDelay;
                framesLeft--;

                PrepareNextFrame();
            }

            // Render current frame
            canvas.Begin(device);

            BatchInfo material = device.RentMaterial();

            material.MainTexture = videoTexture;
            canvas.State.SetMaterial(material);

            Vector2 targetSize = device.TargetSize;

            float ratioTarget = targetSize.Y / targetSize.X;
            float ratioSource = (float)height / width;
            float ratio       = MathF.Clamp(ratioTarget, ratioSource - 0.16f, ratioSource);

            float fillHeight = targetSize.X * ratio;
            float yOffset    = (targetSize.Y - fillHeight) * 0.5f;

            canvas.FillRect(0, yOffset, targetSize.X, fillHeight);

            canvas.End();
        }
Example #4
0
        /// <summary>
        /// Updates the <see cref="CurrentFrame"/>, <see cref="NextFrame"/> and <see cref="CurrentFrameProgress"/> properties immediately.
        /// This is called implicitly once each frame before drawing, so you don't normally call this. However, when changing animation
        /// parameters and requiring updated animation frame data immediately, this could be helpful.
        /// </summary>
        public void UpdateVisibleFrames()
        {
            // Calculate visible frames
            curAnimFrame     = 0;
            nextAnimFrame    = 0;
            curAnimFrameFade = 0.0f;
            if (animFrameCount > 0 && animDuration > 0)
            {
                // Calculate currently visible frame
                float frameTemp = animFrameCount * animTime / animDuration;
                curAnimFrame = (int)frameTemp;

                // Normalize current frame when exceeding anim duration
                if (animLoopMode == LoopMode.Once || animLoopMode == LoopMode.FixedSingle)
                {
                    curAnimFrame = MathF.Clamp(curAnimFrame, 0, animFrameCount - 1);
                }
                else
                {
                    curAnimFrame = MathF.NormalizeVar(curAnimFrame, 0, animFrameCount);
                }

                // Calculate second frame and fade value
                curAnimFrameFade = frameTemp - (int)frameTemp;
                if (animLoopMode == LoopMode.Loop)
                {
                    nextAnimFrame = MathF.NormalizeVar(curAnimFrame + 1, 0, animFrameCount);
                }
                else
                {
                    nextAnimFrame = curAnimFrame + 1;
                }
            }
            curAnimFrame  = animFirstFrame + MathF.Clamp(curAnimFrame, 0, animFrameCount - 1);
            nextAnimFrame = animFirstFrame + MathF.Clamp(nextAnimFrame, 0, animFrameCount - 1);
        }