示例#1
0
    private void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.blue;
        Gizmos.DrawWireSphere(transform.position, m_Threshold.AsFloat());

        if (m_RespawnPoints != null)
        {
            for (int respawnPointIndex = 0; respawnPointIndex < m_RespawnPoints.Length; ++respawnPointIndex)
            {
                RespawnPoint respawnPoint = m_RespawnPoints[respawnPointIndex];

                if (respawnPoint == null)
                {
                    continue;
                }

                TSVector2 normalizedDir = respawnPoint.forceDirection.normalized;

                // Draw main direction.

                if (respawnPoint.transform != null)
                {
                    Gizmos.color = Color.yellow;

                    Vector3 from = respawnPoint.transform.position.ToVector();
                    Vector3 to   = from + new Vector3(normalizedDir.x.AsFloat(), normalizedDir.y.AsFloat(), 0f);
                    Gizmos.DrawLine(from, to);
                }

                if (MathFP.Abs(respawnPoint.errorAngle) > FP.Zero)
                {
                    // Draw error range.

                    {
                        Gizmos.color = Color.red;

                        TSVector2 normalizedDirLeft = normalizedDir.Rotate(-respawnPoint.errorAngle);

                        Vector3 from = respawnPoint.transform.position.ToVector();
                        Vector3 to   = from + new Vector3(normalizedDirLeft.x.AsFloat(), normalizedDirLeft.y.AsFloat(), 0f);
                        Gizmos.DrawLine(from, to);
                    }

                    {
                        Gizmos.color = Color.red;

                        TSVector2 normalizedDirRight = normalizedDir.Rotate(respawnPoint.errorAngle);

                        Vector3 from = respawnPoint.transform.position.ToVector();
                        Vector3 to   = from + new Vector3(normalizedDirRight.x.AsFloat(), normalizedDirRight.y.AsFloat(), 0f);
                        Gizmos.DrawLine(from, to);
                    }
                }
            }
        }
    }
示例#2
0
文件: PointFP.cs 项目: nakijun/adasg
        static public int Distance(int dx, int dy)
        {
            dx = MathFP.Abs(dx);
            dy = MathFP.Abs(dy);
            if (dx == 0)
            {
                return(dy);
            }
            else if (dy == 0)
            {
                return(dx);
            }

            long len = (((long)dx * dx) >> SingleFP.DecimalBits) + (((long)dy * dy) >> SingleFP.DecimalBits);
            long s   = (dx + dy) - (MathFP.Min(dx, dy) >> 1);

            s = (s + ((len << SingleFP.DecimalBits) / s)) >> 1;
            s = (s + ((len << SingleFP.DecimalBits) / s)) >> 1;
            return((int)s);
        }
示例#3
0
        public GradientBrushFP(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax, int ff_angle, int type)
        {
            bounds.Reset(ff_xmin, ff_ymin,
                         ff_xmax == ff_xmin ? ff_xmin + 1 : ff_xmax,
                         ff_ymax == ff_ymin ? ff_ymin + 1 : ff_ymax);
            matrix = new MatrixFP();
            matrix.Translate(-(ff_xmin + ff_xmax) / 2, -(ff_ymin + ff_ymax) / 2);
            matrix.Rotate(-ff_angle);
            this.type = type;
            if (type == RADIAL_GRADIENT)
            {
                matrix.Scale(MathFP.Div(SingleFP.One, bounds.Width), MathFP.Div(SingleFP.One, bounds.Height));
            }
            int ff_ang = MathFP.Atan(MathFP.Div(bounds.Height, bounds.Width == 0 ? 1 : bounds.Width));
            int ff_len = PointFP.Distance(bounds.Height, bounds.Width);

            ff_length = MathFP.Mul(ff_len, MathFP.Max(
                                       MathFP.Abs(MathFP.Cos(ff_angle - ff_ang)),
                                       MathFP.Abs(MathFP.Cos(ff_angle + ff_ang))));
        }
示例#4
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * calculate the distance.
         * @param dx
         * @param dy
         * @return
         */
        static public int Distance(int dx, int dy)
        {
            dx = MathFP.Abs(dx);
            dy = MathFP.Abs(dy);
            if (dx == 0)
            {
                return(dy);
            }
            if (dy == 0)
            {
                return(dx);
            }

            var len = (((long)dx * dx) >> SingleFP.DECIMAL_BITS)
                      + (((long)dy * dy) >> SingleFP.DECIMAL_BITS);
            long s = (dx + dy) - (MathFP.Min(dx, dy) >> 1);

            s = (s + ((len << SingleFP.DECIMAL_BITS) / s)) >> 1;
            s = (s + ((len << SingleFP.DECIMAL_BITS) / s)) >> 1;
            return((int)s);
        }
示例#5
0
        public static GraphicsPathFP  CreateArc(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax, int ff_startangle, int ff_sweepangle, bool closed, bool standalone)
        {
            if (ff_sweepangle < 0)
            {
                ff_startangle += ff_sweepangle;
                ff_sweepangle  = -ff_sweepangle;
            }
            int segments = MathFP.Round(MathFP.Div(4 * MathFP.Abs(ff_sweepangle), MathFP.PI)) >> SingleFP.DecimalBits;

            if (segments == 0)
            {
                segments = 1;
            }
            GraphicsPathFP path = new GraphicsPathFP();
            int            ff_darg = ff_sweepangle / segments;
            int            ff_arg = ff_startangle;
            int            ff_lastcos = MathFP.Cos(ff_startangle);
            int            ff_lastsin = MathFP.Sin(ff_startangle);
            int            ff_xc = (ff_xmin + ff_xmax) / 2;
            int            ff_yc = (ff_ymin + ff_ymax) / 2;
            int            ff_rx = (ff_xmax - ff_xmin) / 2;
            int            ff_ry = (ff_ymax - ff_ymin) / 2;
            int            ff_RXBETA = MathFP.Mul(17381, ff_rx);
            int            ff_RYBETA = MathFP.Mul(17381, ff_ry);
            int            ff_currcos, ff_currsin, ff_x1, ff_y1, ff_x2, ff_y2;

            if (closed)
            {
                path.AddMoveTo(new PointFP(ff_xc, ff_yc));
            }

            for (int i = 1; i <= segments; i++)
            {
                ff_arg     = i == segments?ff_startangle + ff_sweepangle:ff_arg + ff_darg;
                ff_currcos = MathFP.Cos(ff_arg);
                ff_currsin = MathFP.Sin(ff_arg);
                ff_x1      = ff_xc + MathFP.Mul(ff_rx, ff_lastcos);
                ff_y1      = ff_yc + MathFP.Mul(ff_ry, ff_lastsin);
                ff_x2      = ff_xc + MathFP.Mul(ff_rx, ff_currcos);
                ff_y2      = ff_yc + MathFP.Mul(ff_ry, ff_currsin);
                if (i == 1)
                {
                    if (closed)
                    {
                        path.AddLineTo(new PointFP(ff_x1, ff_y1));
                    }
                    else
                    if (standalone)
                    {
                        path.AddMoveTo(new PointFP(ff_x1, ff_y1));
                    }
                }

                path.AddCurveTo(
                    new PointFP(ff_x1 - MathFP.Mul(ff_RXBETA, ff_lastsin), ff_y1 + MathFP.Mul(ff_RYBETA, ff_lastcos)),
                    new PointFP(ff_x2 + MathFP.Mul(ff_RXBETA, ff_currsin), ff_y2 - MathFP.Mul(ff_RYBETA, ff_currcos)),
                    new PointFP(ff_x2, ff_y2));
                ff_lastcos = ff_currcos;
                ff_lastsin = ff_currsin;
            }
            if (closed)
            {
                path.AddClose();
            }
            return(path);
        }
示例#6
0
文件: LineFP.cs 项目: nakijun/adasg
 private static bool IsZero(int ff_val)
 {
     return(MathFP.Abs(ff_val) < (1 << SingleFP.DecimalBits / 2));
 }
示例#7
0
    public override void OnSyncedUpdate()
    {
        base.OnSyncedUpdate();

        if (!m_IsActive || m_HoleIndex < 0)
        {
            return;
        }

        // Get Simulation info.

        int currentTick    = TrueSyncManager.ticksMain;
        int rollbackWindow = TrueSyncManager.rollbackWindowMain;

        // Check current collision

        TSVector2 myPosition = tsTransform2D.position;

        for (int targetIndex = 0; targetIndex < m_Targets.Count; ++targetIndex)
        {
            tnHoleTarget holeTarget = m_Targets[targetIndex];

            if (holeTarget == null)
            {
                continue;
            }

            TSTransform2D otherTransform = holeTarget.GetComponent <TSTransform2D>();

            if (otherTransform == null)
            {
                continue;
            }

            TSVector2 targetPosition = otherTransform.position;

            TSVector2 positionDelta = targetPosition - myPosition;

            FP distance2 = positionDelta.LengthSquared();
            if (distance2 < m_Threshold * m_Threshold)
            {
                // Notify collision.

                holeTarget.CollidingWithHole();

                // Add object to pending list.

                if (holeTarget.canEnterHole && !holeTarget.isTeleporting)
                {
                    Internal_CacheTarget(currentTick, holeTarget);
                }
            }
        }

        // Check pending objects.

        for (int index = 0; index < m_Pending.count; ++index)
        {
            int tick = m_Pending.GetKey(index);

            if (currentTick == tick + rollbackWindow)
            {
                List <tnHoleTarget> holeTargets = m_Pending.GetValue(tick);
                if (holeTargets != null)
                {
                    for (int targetIndex = 0; targetIndex < holeTargets.Count; ++targetIndex)
                    {
                        tnHoleTarget holeTarget = holeTargets[targetIndex];

                        if (holeTarget == null)
                        {
                            continue;
                        }

                        RespawnPoint respawnPoint = GetRandomSpawnPoint();

                        if (respawnPoint == null || respawnPoint.transform == null)
                        {
                            continue;
                        }

                        TSTransform2D targetTransform = holeTarget.tsTransform2D;
                        TSRigidBody2D targetRigidbody = holeTarget.GetComponent <TSRigidBody2D>();

                        // Snap position.

                        if (targetRigidbody != null)
                        {
                            targetRigidbody.MovePosition(tsTransform2D.position);
                        }
                        else
                        {
                            targetTransform.position = tsTransform2D.position;
                        }

                        // Set rigidbody velocity,

                        if (targetRigidbody != null)
                        {
                            targetRigidbody.velocity = TSVector2.zero;
                        }

                        // Eavluate force

                        TSVector2 forceDirection = respawnPoint.forceDirection;
                        forceDirection.Normalize();

                        if (MathFP.Abs(respawnPoint.errorAngle) > FP.Zero)
                        {
                            int random      = TSRandom.Range(0, 101);
                            FP  t           = ((FP)random) / 100;
                            FP  randomError = MathFP.Lerp(-respawnPoint.errorAngle, respawnPoint.errorAngle, t);
                            forceDirection = forceDirection.Rotate(randomError);
                        }

                        TSVector2 outForce = forceDirection * respawnPoint.forceIntensity;

                        // Teleport.

                        holeTarget.Teleport(m_HoleIndex, respawnPoint.respawnPosition, outForce, m_RespawnTime, m_InEffect, m_OutEffect);
                    }
                }
            }
        }

        // Remove old data from dictionary.

        for (int index = 0; index < m_Pending.count; ++index)
        {
            int tick          = m_Pending.GetKey(index);
            int executionTick = tick + rollbackWindow;

            bool isSafeTick = TrueSyncManager.IsTickOutOfRollbackMain(executionTick);
            if (isSafeTick)
            {
                m_Pending.Remove(tick);
                index = -1;
            }
        }
    }
示例#8
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Check to see a Value is zero.
         * @param ff_val
         * @return
         */
        private static bool IsZero(int ffVal)
        {
            return(MathFP.Abs(ffVal) < (1 << SingleFP.DECIMAL_BITS / 2));
        }
    public override void OnSyncedUpdate()
    {
        base.OnSyncedUpdate();

        if (!m_RunSyncedUpdate)
        {
            return;
        }

        // Get delta time.

        FP deltaTime = TrueSyncManager.deltaTimeMain;

        // Update movement direction.

        FP horizontalAxis;
        FP verticalAxis;

        if (m_EnableInputCompression)
        {
            int intX = TrueSyncInput.GetInt(m_HorizontalAxisCode);
            int intY = TrueSyncInput.GetInt(m_VerticalAxisCode);

            horizontalAxis = intX / (FP)s_InputPrecision;
            verticalAxis   = intY / (FP)s_InputPrecision;
        }
        else
        {
            horizontalAxis = TrueSyncInput.GetFP(m_HorizontalAxisCode);
            verticalAxis   = TrueSyncInput.GetFP(m_VerticalAxisCode);
        }

        FP horizontalAxisAbs = MathFP.Abs(horizontalAxis);
        FP verticalAxisAbs   = MathFP.Abs(verticalAxis);

        TSVector2 moveDirection = new TSVector2(horizontalAxis, verticalAxis);

        moveDirection.Normalize();

        m_MoveDirection = moveDirection;

        // Update player action.

        if (m_CooldownTimer > FP.Zero)
        {
            m_CooldownTimer -= deltaTime;

            if (m_CooldownTimer < FP.Zero)
            {
                m_CooldownTimer = FP.Zero;
            }
        }

        if (m_CooldownTimer == FP.Zero)
        {
            bool buttonPressed = (TrueSyncInput.GetByte(m_ButtonPressedCode) > 0);
            if (buttonPressed)
            {
                m_PressureTime += deltaTime;
                m_ChargeLevel   = MathFP.GetClampedPercentage(m_PressureTime, m_PressureTimeRange.min, m_PressureTimeRange.max);
            }
            else
            {
                if (m_PrevPressed)
                {
                    FP axisThreshold = FP.One / FP.Ten;

                    if (horizontalAxisAbs > axisThreshold || verticalAxisAbs > axisThreshold)
                    {
                        // Apply an insant force.

                        FP        requestForceMagnitude = MathFP.Lerp(m_ForceRange.min, m_ForceRange.max, m_ChargeLevel);
                        TSVector2 moveForce             = m_MoveDirection * requestForceMagnitude;
                        m_Rigidbody2D.AddForce(moveForce);

                        // Update cooldown timer.

                        m_CooldownTimer = MathFP.Lerp(m_CooldownRange.min, m_CooldownRange.max, m_ChargeLevel);
                    }
                    else
                    {
                        m_CooldownTimer = FP.Zero;
                    }
                }

                m_PressureTime = FP.Zero;
                m_ChargeLevel  = FP.Zero;
            }

            m_PrevPressed = buttonPressed;
        }
        else
        {
            m_PressureTime = FP.Zero;
            m_ChargeLevel  = FP.Zero;

            m_PrevPressed = false;
        }
    }