public static string GetAllRopesGEVA(List <Visual2D> comps)
        {
            String allRopesString = String.Empty;

            for (int i = 0; i < StaticData.EngineManager.SpringsManagerEngine.ListOfServices.Count; i++)
            {
                String        currentRopeString = String.Empty;
                SpringService cRope             = StaticData.EngineManager.SpringsManagerEngine.ListOfServices[i];
                if (comps.Contains(cRope.Masses[0]))
                {
                    if (cRope is CatchableRopeService)
                    {
                        currentRopeString = "catchable_rope(" + cRope.Masses[0].PositionXNA.X + ", " +
                                            cRope.Masses[0].PositionXNA.Y + "," + cRope.Length + ").";
                        allRopesString += currentRopeString + Environment.NewLine;
                    }
                    else
                    {
                        currentRopeString = "rope(" + cRope.Masses[0].PositionXNA.X + ", " +
                                            cRope.Masses[0].PositionXNA.Y + "," + cRope.Length + ").";
                        allRopesString += currentRopeString + Environment.NewLine;
                    }
                }
            }
            return(allRopesString);
        }
Пример #2
0
        private static void InitializeBasicRope()
        {
            int nrOfMasses = (100 / 15) - 1;

            if (nrOfMasses <= 0)
            {
                nrOfMasses = 2;
            }
            BasicRope = DefaultAdder.GetDefaultSpringRope(new Vector3(450, 40, 0),
                                                          StaticData.EngineManager.CookieRB.PositionXNA,
                                                          nrOfMasses,
                                                          20 * nrOfMasses,
                                                          10f,
                                                          0.1f,
                                                          RigidType.SphereRigid,
                                                          new Vector3(5, 5, 0), false,
                                                          SpringType.StrictRope);
            //BasicRope = DefaultAdder.GetDefaultSpringRope(new Vector3(450, 40, 0),
            //                                                    nrOfMasses,
            //                                                    500,
            //                                                    5f,
            //                                                    0.1f,
            //                                                    RigidType.SphereRigid,
            //                                                    new Vector3(10, 10, 0), false,
            //                                                    SpringType.StrictRope);
            BasicRope.ApplyServiceOnRigid(StaticData.EngineManager.CookieRB);
            StaticData.EngineManager.SpringsManagerEngine.AddNewService(BasicRope);
        }
Пример #3
0
        public static List <List <IntPoint> > GetRopePoly(SpringService service, EngineManager engineManager)
        {
            int verticalLineLength, halfFarWidth;

            SetProperHalfFarWidth(service, engineManager.CookieRB, out verticalLineLength, out halfFarWidth);
            var polySemiCircle = PolysHelper.GetShapeSemiCirclePoly(service.Masses[0].PositionXNACenter2D,
                                                                    ropeNearWidth,
                                                                    verticalLineLength,
                                                                    halfFarWidth);
            List <IntPoint> polyAdded = GetAddedGravityRectanglePoly(service, engineManager);
            var             polyFinal = EntraSolver.GetPolySolution(polySemiCircle, polyAdded, ClipType.ctUnion);

            // Cut upper rectangle
            int             cY   = (int)StaticData.EngineManager.CookieRB.PositionXNACenter2D.Y;
            List <IntPoint> poly = new List <IntPoint>()
            {
                new IntPoint(0, 0),
                new IntPoint(StaticData.LevelFarWidth, 0),
                new IntPoint(StaticData.LevelFarWidth, cY),
                new IntPoint(0, cY),
            };

            polyFinal = EntraSolver.GetPolySolution(polyFinal, poly, ClipType.ctDifference);
            return(polyFinal);
        }
        public static string GetAllRopesProlog()
        {
            String allRopesString = String.Empty;

            for (int i = 0; i < StaticData.EngineManager.SpringsManagerEngine.ListOfServices.Count; i++)
            {
                String        currentRopeString = String.Empty;
                SpringService cRope             = StaticData.EngineManager.SpringsManagerEngine.ListOfServices[i];
                if (cRope is CatchableRopeService)
                {
                    if (((CatchableRopeService)cRope).IsActivated == true)
                    {
                        currentRopeString = "rope(" + cRope.Id + ", " + cRope.Masses[0].PositionXNA.X + ", " +
                                            cRope.Masses[0].PositionXNA.Y + ", " + cRope.Length + ").";
                        allRopesString += currentRopeString + Environment.NewLine;
                    }
                    else
                    {
                        currentRopeString = "catchable_rope(" + cRope.Id + ", " + cRope.Masses[0].PositionXNA.X + ", " +
                                            cRope.Masses[0].PositionXNA.Y + ", " + cRope.Length + ").";
                        allRopesString += currentRopeString + Environment.NewLine;
                    }
                }
                else
                {
                    currentRopeString = "rope(" + cRope.Id + ", " + cRope.Masses[0].PositionXNA.X + ", " +
                                        cRope.Masses[0].PositionXNA.Y + ", " + cRope.Length + ").";
                    allRopesString += currentRopeString + Environment.NewLine;
                }
            }
            return(allRopesString);
        }
Пример #5
0
        private static IEnumerable <Action> GetRopeActions(List <SpringService> ropes)
        {
            List <Action> actions = new List <Action>();

            for (int i = 0; i < ropes.Count; i++)
            {
                SpringService cRope = ropes[i];
                actions.Add(new RopeCut(cRope.Id));
            }
            return(actions);
        }
Пример #6
0
 public override void ExcecuteAction()
 {
     try
     {
         List <int> listOfIds = StaticData.EngineManager.SpringsManagerEngine.ListOfServices.Select(rope => rope.Id).ToList();
         if (listOfIds.Contains(RopeId))
         {
             RopeBeingCut = StaticData.EngineManager.SpringsManagerEngine.RemoveService(RopeId);
         }
     }
     catch (Exception)
     {}
 }
Пример #7
0
        public static SpringService GetDefaultSpringRope(Vector3 initialPosition, Vector3?targetPos, int nrOfMasses,
                                                         float springConstant, float normalLength, float springInnerFriction,
                                                         RigidType type, Vector3 rigidSize, bool isCollidable, SpringType springType)
        {
            List <RigidBody> masses = GetMassesRope(nrOfMasses, initialPosition, targetPos, rigidSize, normalLength, type,
                                                    isCollidable);
            SpringService springService = new SpringService(springConstant,      // springConstant In The Rope
                                                            normalLength,        // Normal Length Of Springs In The Rope
                                                            springInnerFriction, // Spring Inner Friction Constant
                                                            masses,
                                                            springType);

            return(springService);
        }
Пример #8
0
        private bool IsActionOnComponent(Component component, Action action)
        {
            switch (action.AType)
            {
            case ActionType.BlowerPress:
            {
                Blower        item    = ((Blower)component);
                BlowerService service = ((BlowerPress)action).BlowerPressed;
                return(item.X == service.PositionXNA.X && item.Y == service.PositionXNA.Y);
            }
            break;

            case ActionType.RopeCut:
            {
                Rope          item    = ((Rope)component);
                SpringService service = ((RopeCut)action).RopeBeingCut;
                return(item.X == service.Masses[0].PositionXNA.X && item.Y == service.Masses[0].PositionXNA.Y);
            }
            break;

            case ActionType.VoidAction:
                break;

            case ActionType.BubblePinch:
            {
                Bubble        item    = ((Bubble)component);
                BubbleService service = ((BubblePinch)action).BubblePinched;
                return(item.X == service.PositionXNAInitial.X && item.Y == service.PositionXNAInitial.Y);
            }
            break;

            case ActionType.TerminateBranch:
                break;

            case ActionType.RocketPress:
            {
                Rocket item = ((Rocket)component);
                RocketCarrierService service = ((RocketPress)action).RocketPressed;
                return(item.X == service.PositionXNAInitial.X && item.Y == service.PositionXNAInitial.Y);
            }
            break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(false);
        }
Пример #9
0
 private void ManipulateAddingRopes()
 {
     if (mouseState.LeftButton == ButtonState.Pressed)
     {
         if (_rope == null)
         {
             _rope = AddRopesToEngine();
         }
     }
     else
     {
         if (_rope != null && mouseState.LeftButton == ButtonState.Released)
         {
             _rope = null;
         }
     }
 }
Пример #10
0
        public static void SetProperHalfFarWidth(SpringService rope, CookieRB cookieRb,
                                                 out int verticalLineLength,
                                                 out int halfFarWidth)
        {
            var ropeVec       = rope.Masses[0].PositionXNACenter2D;
            var cookieVec     = cookieRb.PositionXNACenter2D;
            var hypotenuseVec = Vector2.Subtract(cookieVec, ropeVec);

            hypotenuseVec.Normalize();
            Vector2 verticalLine  = new Vector2(0, 1);
            float   angleRopeHead =
                MathHelper.ToDegrees(MathHelperModule.GetAngleBetweenTwoVectors(verticalLine, hypotenuseVec)) - 9;

            angleRopeHead = angleRopeHead < 0 ? 1 : angleRopeHead;
            float angleElse           = 180 - 90 - angleRopeHead;
            int   hypotenuseVecLength = 2000;

            verticalLineLength = (int)(hypotenuseVecLength * (angleElse / 90));
            halfFarWidth       = (int)Math.Sqrt(Math.Pow(hypotenuseVecLength, 2) - Math.Pow(verticalLineLength, 2));
        }
Пример #11
0
        private SpringService AddRopesToEngine()
        {
            int nrOfMasses = (100 / 15) - 1;

            if (nrOfMasses <= 0)
            {
                nrOfMasses = 2;
            }
            SpringService springService = DefaultAdder.GetDefaultSpringRope(new Vector3(mouseState.X, mouseState.Y, 0),
                                                                            StaticData.EngineManager.CookieRB.PositionXNA,
                                                                            nrOfMasses, 20 * nrOfMasses,
                                                                            10f, 0.1f,
                                                                            RigidType.SphereRigid,
                                                                            new Vector3(5, 5, 0), false,
                                                                            SpringType.StrictRope);

            springService.ApplyServiceOnRigid(StaticData.EngineManager.CookieRB);
            StaticData.EngineManager.SpringsManagerEngine.AddNewService(springService);
            return(springService);
        }
Пример #12
0
 private void TryRopeCut(Vector2 posPressed, Vector2 posReleased)
 {
     try
     {
         for (int i = 0; i < StaticData.EngineManager.SpringsManagerEngine.ListOfServices.Count; i++)
         {
             SpringService cService     = StaticData.EngineManager.SpringsManagerEngine.ListOfServices[i];
             Vector2       posRopeStart = new Vector2(cService.Masses[0].PositionXNA.X, cService.Masses[0].PositionXNA.Y);
             Vector2       posRopeEnd   = new Vector2(cService.Masses[cService.Masses.Count - 1].PositionXNA.X,
                                                      cService.Masses[cService.Masses.Count - 1].PositionXNA.Y);
             if (MathHelperModule.IsIntersecting(posPressed, posReleased, posRopeStart, posRopeEnd))
             {
                 if (!(cService is CatchableRopeService))
                 {
                     StaticData.EngineManager.SpringsManagerEngine.RemoveService(cService);
                     i--;
                 }
                 else
                 {
                     if ((cService as CatchableRopeService).IsActivated)
                     {
                         StaticData.EngineManager.SpringsManagerEngine.RemoveService(cService);
                         i--;
                     }
                 }
             }
             //if (!((posPressed.Y < posRopeStart.Y && posReleased.Y < posRopeStart.Y)
             //    || (posPressed.Y > posRopeEnd.Y && posReleased.Y > posRopeEnd.Y)))
             //{
             //    StaticData.EngineManager.SpringsManagerEngine.RemoveService(cService);
             //}
         }
     }
     catch (Exception)
     {
     }
 }
Пример #13
0
        private static List <IntPoint> GetAddedGravityRectanglePoly(SpringService service, EngineManager engineManager)
        {
            List <IntPoint> polyAdded;
            Vector2         pinP   = service.Masses[0].PositionXNACenter2D;
            Vector2         cPReal = engineManager.CookieRB.PositionXNACenter2D;
            //Vector2 cPImg = engineManager.CookieRB.PositionXNACenter2D;
            //cPImg.X = pinP.X - (cPReal.X - pinP.X);
            Vector2 pWithPlane1 = new Vector2(1000, 1000);

            IntersectionWithThreePlanes(pinP, cPReal, out pWithPlane1);

            Vector2 pRefWithPlane2, pWithPlane2, interP;
            int     halfRectWidth = (int)Math.Abs(pWithPlane1.X - pinP.X);
            int     rectWidth     = halfRectWidth * 2;

            if (pinP.X > pWithPlane1.X)
            {
                pRefWithPlane2 = new Vector2(pWithPlane1.X + rectWidth, pWithPlane1.Y);
            }
            else
            {
                pRefWithPlane2 = new Vector2(pWithPlane1.X - rectWidth, pWithPlane1.Y);
            }
            IntersectionWithThreePlanes(pinP, pRefWithPlane2, out pWithPlane2);

            int rectLength;

            if (pWithPlane1.Y > pWithPlane2.Y)
            {
                interP     = pWithPlane1;
                rectLength = (int)Math.Abs(interP.X - pWithPlane2.X);
            }
            else
            {
                interP     = pWithPlane2;
                rectLength = (int)Math.Abs(interP.X - pWithPlane1.X);
            }


            if (pinP.X > interP.X)
            {
                return(new List <IntPoint>()
                {
                    new IntPoint((int)interP.X, (int)interP.Y),
                    new IntPoint((int)interP.X + rectLength, (int)interP.Y),
                    new IntPoint((int)interP.X + rectLength, (int)interP.Y + 900),
                    new IntPoint((int)interP.X, (int)interP.Y + 900)
                });
            }
            else
            {
                return(new List <IntPoint>()
                {
                    new IntPoint((int)interP.X - rectLength, (int)interP.Y),
                    new IntPoint((int)interP.X, (int)interP.Y),
                    new IntPoint((int)interP.X, (int)interP.Y + 900),
                    new IntPoint((int)interP.X - rectLength, (int)interP.Y + 900)
                });
            }


            //var poly = new ClockwiseSorter(pointsArea).Sort();
            //EntraDrawer.DrawIntoFile(new Polygons() { poly });
        }