Пример #1
0
        public void ChangeDiodeMode()
        {
            Vector2R pos             = UserInterface.WorldMousePos;
            Node     found           = null;
            float    shortedDistance = Int32.MaxValue;

            for (int i = room.MasterGroup.fullSet.Count - 1; i >= 0; i--)
            {
                Node n = (Node)room.MasterGroup.fullSet.ElementAt(i);
                if (!n.HasComp <Diode>())
                {
                    continue;
                }
                // find node that has been clicked, starting from the most recently placed nodes
                float distsquared = Vector2R.DistanceSquared(n.body.pos, pos);
                //if (distsquared < n.body.radius * n.body.radius)
                //{
                if (distsquared < shortedDistance)
                {
                    found           = n;
                    shortedDistance = distsquared;
                }
                //}
            }
            if (found != null)
            {
                Diode d = found.Comp <Diode>();
                //int mode = (int)d.mode;
                //int countModes = Enum.GetValues(typeof(Diode.Mode)).Length;
                //d.mode = (Diode.Mode)((mode + 1) % countModes);
                found.body.orient += GMath.PI;
            }
        }
Пример #2
0
        public Node SelectNode(Vector2R pos)
        {
            Node  found           = null;
            float shortedDistance = Int32.MaxValue;

            for (int i = room.MasterGroup.fullSet.Count - 1; i >= 0; i--)
            {
                Node n = (Node)room.MasterGroup.fullSet.ElementAt(i);
                // find node that has been clicked, starting from the most recently placed nodes
                float distsquared = Vector2R.DistanceSquared(n.body.pos, pos);
                if (distsquared < n.body.radius * n.body.radius)
                {
                    if (distsquared < shortedDistance)
                    {
                        found           = n;
                        shortedDistance = distsquared;
                    }
                }
            }
            return(found);
        }
Пример #3
0
        public void AddTickets()
        {
            Vector2R pos             = UserInterface.WorldMousePos;
            Node     found           = null;
            float    shortedDistance = Int32.MaxValue;

            for (int i = room.MasterGroup.fullSet.Count - 1; i >= 0; i--)
            {
                Node n = (Node)room.MasterGroup.fullSet.ElementAt(i);
                if (!n.HasComp <Diode>())
                {
                    continue;
                }
                // find node that has been clicked, starting from the most recently placed nodes
                float distsquared = Vector2R.DistanceSquared(n.body.pos, pos);
                //if (distsquared < n.body.radius * n.body.radius)
                //{
                if (distsquared < shortedDistance)
                {
                    found           = n;
                    shortedDistance = distsquared;
                }
                //}
            }
            if (found != null)
            {
                Diode d = found.Comp <Diode>();

                if (!d.semaphore)
                {
                    d.semaphore  = true;
                    d.maxTickets = 1;
                }
                else
                {
                    d.maxTickets += 1;
                    d.maxTickets %= 4;
                }
            }
        }
Пример #4
0
        public override void AffectOther(Node other)
        {
            if (!active)
            {
                return;
            }
            if (exclusions.Contains(other))
            {
                return;
            }

            float distVects = Vector2R.DistanceSquared(other.body.pos, parent.body.pos);
            float r         = parent.body.radius * radiusScale;

            if (distVects < r * r)
            {
                float newX = (parent.body.pos.X - other.body.pos.X) * 2.05f;
                float newY = (parent.body.pos.Y - other.body.pos.Y) * 2.05f;
                other.body.pos.X += newX;
                other.body.pos.Y += newY;
            }
        }
Пример #5
0
        public void ProcessMouse()
        {
            mouseState = Mouse.GetState();

            //if (mouseState.XButton1 == ButtonState.Pressed)
            //    System.Console.WriteLine("X1");
            //
            //if (mouseState.XButton2 == ButtonState.Pressed)
            //    System.Console.WriteLine("X2");

            _mousePos     = new Vector2R(mouseState.X, mouseState.Y) - OrbIt.Game.Room.Camera.CameraOffsetVect;
            WorldMousePos = (_mousePos / room.Camera.zoom) + room.Camera.virtualTopLeft;
            //ignore mouse clicks outside window
            if (!IsPaused)
            {
                if (mouseState.X >= OrbIt.ScreenWidth || mouseState.X < 0 || mouseState.Y >= OrbIt.ScreenHeight ||
                    mouseState.Y < 0)
                {
                    return;
                }
            }

            //if (!keyManager.MouseInGameBox)
            //{
            if (ScrollAction != null)
            {
                if (mouseState.ScrollWheelValue < oldMouseState.ScrollWheelValue)
                {
                    ScrollAction(2);
                }
                else if (mouseState.ScrollWheelValue > oldMouseState.ScrollWheelValue)
                {
                    ScrollAction(-2);
                }
            }

            oldMouseState = mouseState;
            // return;
            //}

            if (!keyManager.MouseInGameBox)
            {
                return;
            }
            //game.processManager.PollMouse(mouseState, oldMouseState);
            int worldMouseX = (int)WorldMousePos.X;
            int worldMouseY = (int)WorldMousePos.Y;


            if (true) // || mouseState.LeftButton == ButtonState.Pressed)
            {
                bool found = false;
                for (int i = room.MasterGroup.fullSet.Count - 1; i >= 0; i--)
                {
                    Node n = room.MasterGroup.fullSet.ElementAt(i);
                    // find node that has been clicked, starting from the most recently placed nodes
                    if (Vector2R.DistanceSquared(n.body.pos, new Vector2R(worldMouseX, worldMouseY)) < n.body.radius * n.body.radius)
                    {
                        room.TargetNode = n;
                        found           = true;
                        break;
                    }
                }
                if (!found)
                {
                    room.TargetNode = null;
                }
            }

            if (mouseState.ScrollWheelValue < _oldMouseScrollValue)
            {
                room.Camera.zoom *= Zoomfactor;
            }
            else if (mouseState.ScrollWheelValue > _oldMouseScrollValue)
            {
                room.Camera.zoom /= Zoomfactor;
            }

            _oldMouseScrollValue = mouseState.ScrollWheelValue;
            oldMouseState        = mouseState;
        }
Пример #6
0
        //public bool EveryOther = false;
        //public int counter = 0;

        public override void AffectOther(Node other)
        {
            if (!active)
            {
                return;
            }
            if (exclusions.Contains(other))
            {
                return;
            }

            //if (EveryOther && counter++ % 2 == 0) return;

            if (AffectsOnlyGravity && !other.HasComp <Gravity>())
            {
                return;
            }

            float distVects = Vector2R.DistanceSquared(other.body.pos, parent.body.pos);
            Node  affector  = parent;
            Node  affected  = other;

            if (affectDirection == AffectDirection.OthersAffectThis)
            {
                affector = other;
                affected = parent;
            }

            if (distVects < radius * radius)
            {
                distVects = (float)Math.Sqrt(distVects);
                if (deadZone.enabled && distVects < deadZone.value)
                {
                    return;
                }
                if (distVects < lowerbound)
                {
                    distVects = lowerbound;
                }
                double angletemp = Math.Atan2((affector.body.pos.Y - affected.body.pos.Y),
                                              (affector.body.pos.X - affected.body.pos.X));

                float gravForce = (multiplier * affector.body.mass * affected.body.mass);

                switch (mode)
                {
                case Mode.Normal:
                    gravForce /= distVects * distVects;
                    break;

                case Mode.Strong:
                    gravForce /= distVects;
                    break;

                case Mode.ConstantForce:
                    gravForce /= 100; //#magicnumber
                    break;
                }
                if (Repulsive)
                {
                    gravForce *= -1;
                }

                if (angle != 0)
                {
                    angletemp = (angletemp + Math.PI + (Math.PI * (float)(angle / 180.0f)) % (Math.PI * 2)) - Math.PI;
                    //test for validity
                }

                //float gravForce = gnode1.GravMultiplier;
                float    velX  = (float)Math.Cos(angletemp) * gravForce;
                float    velY  = (float)Math.Sin(angletemp) * gravForce;
                Vector2R delta = new Vector2R(velX, velY);

                /*
                 *      delta /= other.transform.mass;
                 *      other.transform.velocity += delta;
                 *      //*/
                //*
                if (affectDirection == AffectDirection.Both)
                {
                    delta /= 2;
                    affected.body.velocity += delta * other.body.invmass;
                    affector.body.velocity -= delta * parent.body.invmass;
                }
                else
                {
                    affected.body.ApplyForce(delta);
                }

                if (ShowForceLines)
                {
                    room.Camera.DrawLine(other.body.pos, other.body.pos + (delta * 100), 2, parent.body.color, (int)Layers.Over4);
                }
                //other.body.velocity += delta;
                //other.body.velocity /= other.body.mass; //creates snakelike effect when put below increments
            }
        }
Пример #7
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;
        }
Пример #8
0
        public static bool CircletoPolygonCheck(Collider a, Collider b)
        {
            Circle  A = (Circle)a.shape;
            Polygon B = (Polygon)b.shape;

            //m.contact_count = 0;

            // Transform circle center to Polygon model space
            Vector2R center = a.pos;

            center = B.u.Transpose() * (center - b.pos);

            // Find edge with minimum penetration
            // Exact concept as using support points in Polygon vs Polygon
            double separation = -float.MaxValue;
            int    faceNormal = 0;

            for (int i = 0; i < B.vertexCount; ++i)
            {
                double s = Vector2R.Dot(B.normals[i], center - B.vertices[i]);

                if (s > A.radius)
                {
                    return(false);
                }

                if (s > separation)
                {
                    separation = s;
                    faceNormal = i;
                }
            }

            // Grab face's vertices
            Vector2R v1 = B.vertices[faceNormal];
            int      i2 = faceNormal + 1 < B.vertexCount ? faceNormal + 1 : 0;
            Vector2R v2 = B.vertices[i2];

            // Check to see if center is within polygon
            if (separation < GMath.EPSILON)
            {
                //m.contact_count = 1;
                //m.normal = -(B.u * B.normals[faceNormal]);
                //m.contacts[0] = VMath.MultVectDouble(m.normal, A.radius) + a.pos;
                //m.penetration = A.radius;
                return(true);
            }

            // Determine which voronoi region of the edge center of circle lies within
            double dot1 = Vector2R.Dot(center - v1, v2 - v1);
            double dot2 = Vector2R.Dot(center - v2, v1 - v2);

            //m.penetration = A.radius - separation;

            // Closest to v1
            if (dot1 <= 0.0f)
            {
                if (Vector2R.DistanceSquared(center, v1) > A.radius * A.radius)
                {
                    return(false);
                }
                //m.contact_count = 1;
                //Vector2 n = v1 - center;
                //n = B.u * n;
                //n.Normalize();
                //m.normal = n;
                //v1 = B.u * v1 + b.pos;
                //m.contacts[0] = v1;
            }
            // Closest to v2
            else if (dot2 <= 0.0f)
            {
                if (Vector2R.DistanceSquared(center, v2) > A.radius * A.radius)
                {
                    return(false);
                }

                //m.contact_count = 1;
                //Vector2 n = v2 - center;
                //v2 = B.u * v2 + b.pos;
                //m.contacts[0] = v2;
                //n = B.u * n;
                //n.Normalize();
                //m.normal = n;
            }
            // Closest to face
            else
            {
                Vector2R n = B.normals[faceNormal];
                if (Vector2R.Dot(center - v1, n) > A.radius)
                {
                    return(false);
                }

                //n = B.u * n;
                //m.normal = -n;
                //m.contacts[0] = VMath.MultVectDouble(m.normal, A.radius) + a.pos;
                //m.contact_count = 1;
            }
            return(true);
        }
Пример #9
0
        //used for NearestN or FurthestN
        public void NearestN()
        {
            if (link.sources != null)
            {
                //not effecient if NearestNValue == 1 because it sorts the entire list of distances
                HashSet <Node> AlreadyInhabited = new HashSet <Node>();

                link.sources.ToList().ForEach(delegate(Node source) {
                    AffectionSets[source]        = new ObservableHashSet <Node>();
                    ObservableHashSet <Node> set = AffectionSets[source];

                    List <Tuple <float, Node> > DistancesList = new List <Tuple <float, Node> >();
                    Comparison <Tuple <float, Node> > comparer;
                    if (FormationType == formationtype.NearestN)
                    {
                        comparer = delegate(Tuple <float, Node> first, Tuple <float, Node> second) {
                            if (first.Item1 < second.Item1)
                            {
                                return(-1);
                            }
                            else if (first.Item1 > second.Item1)
                            {
                                return(1);
                            }
                            return(0);
                        };
                    }
                    else if (FormationType == formationtype.FurthestN)
                    {
                        comparer = delegate(Tuple <float, Node> first, Tuple <float, Node> second) {
                            if (first.Item1 > second.Item1)
                            {
                                return(-1);
                            }
                            else if (first.Item1 < second.Item1)
                            {
                                return(1);
                            }
                            return(0);
                        };
                    }
                    else
                    {
                        return;
                    }

                    link.targets.ToList().ForEach(delegate(Node target) {
                        if (source == target)
                        {
                            return;
                        }
                        DistancesList.Add(
                            new Tuple <float, Node>(
                                Vector2R.DistanceSquared(
                                    source
                                    .body
                                    .pos,
                                    target
                                    .body
                                    .pos),
                                target));
                    });

                    DistancesList.Sort(comparer);

                    int min = Math.Min(NearestNValue, DistancesList.Count);

                    /*
                     * for (int i = 0; i < min; i++)
                     * {
                     * set.Add(DistancesList.ElementAt(i).Item2);
                     * }
                     */
                    int count = 0;
                    int it    = 0;
                    while (count < min)
                    {
                        if (it >= DistancesList.Count)
                        {
                            break;
                        }
                        Node nn = DistancesList.ElementAt(it).Item2;
                        if (Uninhabited)
                        {
                            if (AlreadyInhabited.Contains(nn))
                            {
                                it++;
                                continue;
                            }
                            else
                            {
                                AlreadyInhabited.Add(nn);
                            }
                        }

                        set.Add(nn);
                        count++;
                        it++;
                    }
                });
            }
        }