Example #1
0
        public override void PlayerControl(Input input)
        {
            swordNode.movement.active = false;
            //sword.body.velocity = Utils.AngleToVector(sword.body.orient + (float)Math.PI/2) * 100;
            swordNode.body.velocity = swordNode.body.effvelocity * nodeKnockback;
            Vector2R rightstick = input.GetRightStick().toV2R();

            if (rightstick.LengthSquared() > 0.9 * 0.9)
            {
                movingStick = true;
                target      = rightstick;
                //enabled = true;
                target.Normalize();
                target            *= distance;
                target            += parent.body.pos;
                swordNode.body.pos = Vector2R.Lerp(swordNode.body.pos, target, 0.1f);
                //sword.body.pos = target + parent.body.pos;
                Vector2R result = swordNode.body.pos - parent.body.pos;
                swordNode.body.SetOrientV2(result);
            }
            else
            {
                movingStick = false;
                //enabled = false;
                Vector2R restPos = new Vector2R(parent.body.radius, 0).Rotate(parent.body.orient) + parent.body.pos;
                swordNode.body.pos    = Vector2R.Lerp(swordNode.body.pos, restPos, 0.1f);
                swordNode.body.orient = GMath.AngleLerp(swordNode.body.orient, parent.body.orient, 0.1f);
            }
            //sword.body.pos = position;
        }
Example #2
0
        /// <summary> Returns a non-unit vector up to the radius specified.</summary>
        public override Vector2 GetRightStick(float radius, bool drawRing = false)
        {
            Vector2  mousePos  = new Vector2(newMouseState.X, newMouseState.Y);
            Vector2R playerPos = (player.node.body.pos - player.room.Camera.virtualTopLeft) * player.room.Camera.zoom +
                                 player.room.Camera.CameraOffsetVect;
            Vector2R dir    = new Vector2R(mousePos.X, mousePos.Y) - playerPos;
            float    lensqr = dir.LengthSquared();

            if (lensqr > radius * radius)
            {
                VMath.NormalizeSafe(ref dir);
                //dir = dir.NormalizeSafe() * radius;
            }
            else
            {
                dir /= radius;
            }
            if (drawRing)
            {
                float scale = (radius * 2f) / 128;//Todo:Assets.TextureDict[Textures.Ring].Width;
                float alpha = (((float)Math.Sin(OrbIt.Game.Time.TotalGameTime.TotalMilliseconds / 300f) + 1f) / 4f) + 0.25f;
                player.room.Camera.Draw(Textures.Ring, player.node.body.pos, player.pColor * alpha, scale, (int)Layers.Under2);
            }
            return(new Vector2(dir.X, dir.Y));
        }
Example #3
0
        public static bool CircletoCircle(Manifold m, Collider a, Collider b)
        {
            Circle   ca          = (Circle)a.shape;
            Circle   cb          = (Circle)b.shape;
            Vector2R normal      = b.pos - a.pos;
            float    distSquared = normal.LengthSquared();
            double   radius      = a.radius + b.radius;

            if (distSquared >= (float)(radius * radius))
            {
                m.contact_count = 0;
                return(false);
            }

            double distance = Math.Sqrt(distSquared);

            m.contact_count = 1;

            if (distance == 0)
            {
                m.penetration = ca.radius;
                m.normal      = new Vector2R(1, 0);
                m.contacts[0] = a.pos;
            }
            else
            {
                m.penetration = radius - distance;
                m.normal      = VMath.MultVectDouble(normal, 1.0 / distance);      //normal / distance;
                m.contacts[0] = VMath.MultVectDouble(m.normal, ca.radius) + a.pos; //m.normal * ca.radius + a.body.position;
            }
            return(true);
        }
Example #4
0
        ////////FUCKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
        public static bool CircletoCircleCheck(Collider a, Collider b)
        {
            Vector2R normal      = b.pos - a.pos;
            float    distSquared = normal.LengthSquared();
            double   radius      = a.radius + b.radius;

            return(distSquared < radius * radius);
        }
Example #5
0
        public override void AffectOther(Node other)
        {
            Vector2R dir = other.body.pos - parent.body.pos;

            if (link != null)
            {
                if (FollowMode != followMode.FollowNone)
                {
                    TurnTowardsDirection(parent, dir, flee, LerpPercent);
                }
                if (LeadMode != leadMode.LeadNone)
                {
                    TurnTowardsDirection(other, dir, !flee, LerpPercent);
                }
                return;
            }

            float distSquared = dir.LengthSquared();

            if (distSquared > radius * radius)
            {
                return;
            }
            if (FollowMode == followMode.FollowNearest)
            {
                if (distSquared < nearestDistSqrd)
                {
                    nearestDistSqrd = distSquared;
                    nearestNode     = other;
                }
            }
            else if (FollowMode == followMode.FollowAll)
            {
                directions.Add(dir.NormalizeSafe());
            }
            if (LeadMode == leadMode.LeadAll)
            {
                TurnTowardsDirection(other, dir, !flee, LerpPercent);
            }
            else if (LeadMode == leadMode.LeadNearest)
            {
                if (distSquared < nearestDistSqrd)
                {
                    nearestDistSqrd = distSquared;
                    nearestNode     = other;
                }
            }
        }
Example #6
0
        public override void PlayerControl(Input input)
        {
            Vector2R stick  = input.GetLeftStick().toV2R();
            Vector2R stick2 = input.GetRightStick().toV2R();

            //if (node != bigtony) node.collision.colliders["trigger"].radius = body.radius * 1.5f;
            //else node.collision.colliders["trigger"].radius = body.radius * 1.2f;
            //bool clicked = false;
            //clicked = hc.newHalfPadState.Btn3 == ButtonState.Pressed || hc.newHalfPadState.Btn1 == ButtonState.Pressed;
            //
            //if (clicked)
            //{
            //    SwitchPlayer(stick);
            //}


            if (stick2.LengthSquared() > 0.6f * 0.6f)
            {
                v = VMath.VectorToAngle(stick2).between0and2pi();
                if (v == 0f)
                {
                    v = 0.00001f;
                }
            }
            else if (stick.LengthSquared() > 0.6f * 0.6f)
            {
                v = VMath.VectorToAngle(stick).between0and2pi();
                if (v == 0f)
                {
                    v = 0.00001f;
                }
            }
            float result = GMath.AngleLerp(parent.body.orient, v, 0.1f);

            parent.body.orient = (result);

            stick *= 0.4f;
            stick *= absaccel;
            if ((parent.body.velocity.X != 0 || parent.body.velocity.Y != 0))
            {
                stick += parent.body.velocity * -friction;
            }
            stick *= parent.body.mass;
            //todo: update maxvel?
            parent.body.ApplyForce(stick);
        }
Example #7
0
 public static Vector2R ProjectOnto(this Vector2R source, Vector2R target)
 {
     return((Vector2R.Dot(source, target) / target.LengthSquared()) * target);
 }
Example #8
0
        public override void PlayerControl(Input input)
        {
            //fistNode.movement.active = false;
            //fistNode.body.velocity = fistNode.body.effvelocity * nodeKnockback;
            Vector2R newstickpos = input.GetRightStick().toV2R();
            Vector2R relVel      = newstickpos - oldstickpos;

            if (state == fistmode.ready)
            {
                fistNode.body.pos    = parent.body.pos;
                fistNode.body.orient = parent.body.orient;
                //if stick is moving away from center of stick
                if (newstickpos.LengthSquared() > oldstickpos.LengthSquared())
                {
                    //if stick is moving fast enough
                    float len = relVel.Length();
                    if (relVel.Length() > 0.2f) //deadzone
                    {
                        state = fistmode.punching;
                        float power = (float)Math.Log((double)len + 2.0, 2.0) / 2f;
                        //Console.WriteLine(power);
                        VMath.NormalizeSafe(ref relVel);
                        relVel *= power;
                        //Console.WriteLine(relVel.X + " : " + relVel.Y);
                        //fistNode.body.ApplyForce(relVel);
                        fistNode.body.velocity = relVel * 10f;
                        fistNode.body.orient   = VMath.VectorToAngle(relVel);
                    }
                }
            }
            else if (state == fistmode.punching)
            {
                //check if fully punched.
                if (Vector2R.Distance(fistNode.body.pos, parent.body.pos) > fistReach)
                {
                    state = fistmode.retracting;
                }
            }
            else if (state == fistmode.retracting)
            {
                //fistNode.body.pos = Vector2.Lerp(fistNode.body.pos, parent.body.pos, 0.1f);

                //Vector2 vel = (parent.body.pos - fistNode.body.pos);
                //VMath.NormalizeSafe(ref vel);
                //vel *= 1;
                //fistNode.body.velocity = vel;

                Vector2R vel = (parent.body.pos - fistNode.body.pos);
                //if (vel.Length() < 5)
                //{
                VMath.NormalizeSafe(ref vel);
                vel *= 20;
                //}
                fistNode.body.velocity = vel;
                if (Vector2R.DistanceSquared(fistNode.body.pos, parent.body.pos) < 50 * 50)
                {
                    state = fistmode.ready;
                }
            }
            //if (state != fistmode.ready)
            //    Console.WriteLine(state);
            oldstickpos = newstickpos;
        }
Example #9
0
        public void Set(Vector2R[] verts, int count)
        {
            //no hulls with less than 3 verticies (ensure actual polygon)
            //Debug.Assert(count > 2 && count < MaxPolyVertexCount);
            count = Math.Min(count, MaxPolyVertexCount);

            //find the right most point in the hull
            int    rightMost     = 0;
            double highestXCoord = verts[0].X;

            for (int i = 1; i < count; i++)
            {
                double x = verts[0].X;
                if (x > highestXCoord)
                {
                    highestXCoord = x;
                    rightMost     = i;
                }
                //if matching x then take farthest negative y
                else if (x == highestXCoord && verts[i].Y < verts[rightMost].Y)
                {
                    rightMost = i;
                }
            }

            int[] hull      = new int[MaxPolyVertexCount];
            int   outCount  = 0;
            int   indexHull = rightMost;

            for (;;)
            {
                hull[outCount] = indexHull;
                // search for next index that wraps around the hull
                // by computing cross products to find the most counter-clockwise
                // vertex in the set, given the previous hull index
                int nextHullIndex = 0;
                for (int i = 1; i < count; i++)
                {
                    //skip if same coordinate as we need three unique
                    //points in the set to perform a cross product
                    if (nextHullIndex == indexHull)
                    {
                        nextHullIndex = i;
                        continue;
                    }
                    // cross every set of three unquie verticies
                    // record each counter clockwise third vertex and add
                    // to the output hull
                    Vector2R e1 = verts[nextHullIndex] - verts[hull[outCount]];
                    Vector2R e2 = verts[i] - verts[hull[outCount]];
                    double   c  = VMath.Cross(e1, e2);
                    if (c < 0.0f)
                    {
                        nextHullIndex = i;
                    }

                    // Cross product is zero then e vectors are on same line
                    // therefor want to record vertex farthest along that line
                    if (c == 0.0f && e2.LengthSquared() > e1.LengthSquared())
                    {
                        nextHullIndex = i;
                    }
                }
                outCount++;
                indexHull = nextHullIndex;
                //conclude algorithm upon wraparound
                if (nextHullIndex == rightMost)
                {
                    vertexCount = outCount;
                    break;
                }
            }
            float maxDist = 0;

            // Copy vertices into shape's vertices
            for (int i = 0; i < vertexCount; ++i)
            {
                vertices[i] = verts[hull[i]];
                float dist = Vector2R.Distance(Vector2R.Zero, vertices[i]);
                if (dist > maxDist)
                {
                    maxDist = dist;
                }
            }
            polyReach = maxDist * 2;

            ComputeNormals();
        }