public override double Height(double x)
        {
            double H  = _h + _offsetL;
            double ch = Chord;

            if (Math.Abs(x) == ch)
            {
                return(H);
            }
            else if (Math.Abs(x) > ch)
            {
                return(0);
            }
            else
            {
                double R = (_h * _h + ch * ch) / (2 * _h);
                double b = 2 * (R - _h);
                double c = x * x - 2 * R * _h + _h * _h;
                Tuple <double, double> r = BasicLib.Quadratic(1, b, c);
                if (r.Item1 > 0)
                {
                    return(H - r.Item1);
                }
                else
                {
                    return(H - r.Item2);
                }
            }
        }
Exemple #2
0
    protected new void Awake()
    {
        base.Awake();
        (_coll = GetComponent <CircleCollider2D>()).enabled = false;
        (_rend = GetComponent <SpriteRenderer>()).enabled   = false;

        CooldownTimer = 2.5f;

        this.DoActionInNextFrame(() =>
        {
            if (Holder.gameObject == ControlBase.PlayerGameObject)
            {
                _directionGUI = BasicLib.InstantiatePrefabTr("gui/" + typeof(DirectionInterface).Name, transform).GetComponent <DirectionInterface>();
                _directionGUI.gameObject.SetActive(false);
                _directionGUI.transform.localScale = new Vector3(0.15f, 0.15f);
            }
        });



        AttackOnAirState      s1 = new AttackOnAirState(_ASM, this);
        ChagnedDirectionState s2 = new ChagnedDirectionState(_ASM, this);

        s1.SetTargetStates(s2);
        _ASM.InitializeWithStates(new InactiveEnabledDisableAttackState(_ASM, this), s1);

        ClearCooldown();
    }
    private void SetChildren(int num)
    {
        if (num == transform.childCount)
        {
            return;
        }
        if (num > transform.childCount)
        {
            for (int i = transform.childCount; i < num; i++)
            {
                BasicLib.MyInstantiate(transform.GetChild(0), transform);
            }
        }
        else
        {
            for (int i = transform.childCount; i > num; i--)
            {
                Destroy(transform.GetChild(i).gameObject);
            }
        }
        int index = 0;

        foreach (Slot slot in _player)
        {
            var slotGUI = transform.GetChild(index).GetComponent <WeaponSlotGUI>();
            slotGUI.TextKeyComponent.text        = slot.KeyName;
            slotGUI.TextSlotNumberComponent.text = (index + 1).ToString();
            ++index;
        }
    }
Exemple #4
0
        internal async void SaveCode()
        {
            FolderPicker folderPicker = new FolderPicker();

            folderPicker.FileTypeFilter.Add("*");
            folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            StorageFolder folder = await folderPicker.PickSingleFolderAsync();

            string ext = (string)BasicLib.GetSetting(SettingsNames.GCODE_FILE_EXT);

            foreach (GcodeFile f in Code)
            {
                try
                {
                    if (System.IO.Path.GetExtension(f.FileName) != ext)
                    {
                        f.FileName = System.IO.Path.ChangeExtension(f.FileName, ext);
                    }

                    StorageFile file = await folder.CreateFileAsync(f.FileName, CreationCollisionOption.ReplaceExisting);

                    if (file != null)
                    {
                        await Windows.Storage.FileIO.WriteTextAsync(file, f.Code);
                    }
                }
                catch (Exception e)
                {
                    CoreWindowDialog dlg = new CoreWindowDialog(e.Message);
                    dlg.ShowAsync();
                }
            }
        }
Exemple #5
0
        void GenerateCodeInMultipleFiles()
        {
            // first generate subroutines or paths
            // then main program to call them
            StringBuilder sb = new StringBuilder();

            foreach (Shape s in _currentToolPaths.Shapes)
            {
                if (s is Polygon)
                {
                    GenerateSubFromPolygon(ref sb, (s as Polygon));
                }
                else if (s is Windows.UI.Xaml.Shapes.Path)
                {
                    GenerateSubFromPath(ref sb, (s as Windows.UI.Xaml.Shapes.Path));
                }

                string filename = string.Empty;
                string ext      = (string)BasicLib.GetSetting(SettingsNames.GCODE_FILE_EXT);
                // now deal with name and save in code list
                if ((bool)BasicLib.GetSetting(SettingsNames.USE_NAMED_O_WORDS))
                {
                    BindableCodeTemplate tmpl = _context.Templates.SubFilenameTemplate;
                    tmpl.DataContext = _context;
                    filename         = System.IO.Path.ChangeExtension(tmpl.Text, ext);
                }
                else
                {
                    filename = System.IO.Path.ChangeExtension(_context.SubPathName.ToString(), ext);
                }
                Code.Add(new GcodeFile(filename, sb.ToString()));
            }

            GenerateMain();
        }
        Point Interp(Point p1, double indx, Point p2)
        {
            double x = BasicLib.Linterp(p1.X, indx, p2.X);
            double y = BasicLib.Linterp(p1.Y, indx, p2.Y);

            return(new Point(x, y));
        }
Exemple #7
0
        Point Interp(double x1, double y1, double indx, double x2, double y2, double sa)
        {
            double x = BasicLib.Linterp(x1, indx, x2);
            double y = BasicLib.Linterp(y1, indx, y2);
            double r = Math.Sqrt(x * x + y * y);
            double a = sa + x * colAngle;

            return(new Point(r * Math.Cos(BasicLib.ToRadians * a),
                             r * Math.Sin(BasicLib.ToRadians * a)));
        }
Exemple #8
0
 /// <summary>
 /// These properties have been moved from the lattive
 /// </summary>
 public LayoutData()
 {
     _repeatX         = (int)BasicLib.GetSetting(SettingsNames.REPEAT_X);
     _repeatY         = (int)BasicLib.GetSetting(SettingsNames.REPEAT_Y);
     _toolposition    = (double)BasicLib.GetSetting(SettingsNames.TOOL_POSITION);
     _workPieceRadius = (double)BasicLib.GetSetting(SettingsNames.WORK_PIECE_RADIUS);
     _clipRange       = new Range(0, 0.001, _toolposition);
     _width           = (double)BasicLib.GetSetting(SettingsNames.WIDTH);
     _height          = (double)BasicLib.GetSetting(SettingsNames.HEIGHT);
     _margin          = (double)BasicLib.GetSetting(SettingsNames.MARGIN);
     _offsetX         = (double)BasicLib.GetSetting(SettingsNames.OFFSET_X);
     _offsetY         = (double)BasicLib.GetSetting(SettingsNames.OFFSET_Y);
     _clip            = (bool)BasicLib.GetSetting(SettingsNames.CLIP);
     _hypo            = (bool)BasicLib.GetSetting(SettingsNames.HYPO);
     _k = (double)BasicLib.GetSetting(SettingsNames.HYPO_K);
 }
Exemple #9
0
    protected new void Awake()
    {
        base.Awake();
        AddcomponentOnDestroy = x => x.AddComponent <mainmenu>();
        if (hub == null)
        {
            hub = FindObjectOfType <Room>();
        }
        if (hub == null)
        {
            Background.SetBackgroundColor(Background.YellowishColor);
            Room.DoorType = "move";
            hub           = Floor.CreateSingleRoom(gameObject, 70f, 50f, new bool[] { false, false, true });
        }
        //Background.CreateBackgroundSquare(new Rect(hub.Position, hub.Size), Background.GreenishColor);

        SetPlayer(() => BasicLib.InitializePlayer(1000f, hub.SouthSideCentre, MyColorLib.teams[MyColorLib.green], SceneChanger.SwitchToMenu));
        MyInputs.InputsOff();
        MyCameraLib.SetCameraFollow(playerTr, CameraScript._REGULAR_ORTHOGRAPHIC_SIZE);

        var           trig    = EventObjectPlayerPosition.AddAsGameObject(hub.transform).GetComponent <EventObjectPlayerPosition>();
        BoxCollider2D boxColl = trig.AddCollider <BoxCollider2D>();

        boxColl.size        = new Vector2(Room.DoorWidth, 2f);
        trig.ActualPosition = hub.SouthSideOuter + new Vector3(0f, -boxColl.size.y / 2f);
        trig.AddAction(SceneChanger.SwitchToMenu);

        trig                = EventObjectPlayerPosition.AddAsGameObject(hub.transform).GetComponent <EventObjectPlayerPosition>();
        boxColl             = trig.AddCollider <BoxCollider2D>();
        boxColl.size        = new Vector2(Room.DoorWidth, 1f);
        trig.ActualPosition = hub.SouthSideInner + new Vector3(0f, boxColl.size.y / 2f);
        trig.AddAction(hub.OpenSouthDoor);
        trig.Once = false;

        trig                = EventObjectPlayerPosition.AddAsGameObject(hub.transform).GetComponent <EventObjectPlayerPosition>();
        boxColl             = trig.AddCollider <BoxCollider2D>();
        boxColl.size        = new Vector2(hub.Width, 3f);
        trig.ActualPosition = hub.SouthSideInner + new Vector3(0f, boxColl.size.y / 2f + 2f);
        trig.AddAction(hub.CloseSouthDoor);
        trig.Once = false;

        trig                = EventObjectPlayerPosition.AddAsGameObject(hub.transform).GetComponent <EventObjectPlayerPosition>();
        boxColl             = trig.AddCollider <BoxCollider2D>();
        boxColl.size        = new Vector2(10f, 10f);
        trig.ActualPosition = hub.SouthSideCentre;
        trig.AddAction(() => playerMoveComponent.StartFromScratchNewEndpos(hub.ProportionalPosition(0f, -0.75f)));
    }
Exemple #10
0
        public void TestQuadrant()
        {
            Assert.AreEqual(0, BasicLib.Quadrant(89.9));
            Assert.AreEqual(3, BasicLib.Quadrant(-89.9));

            Assert.AreEqual(1, BasicLib.Quadrant(179.9));
            Assert.AreEqual(2, BasicLib.Quadrant(-179.9));

            Assert.AreEqual(2, BasicLib.Quadrant(269.9));
            Assert.AreEqual(1, BasicLib.Quadrant(-269.9));

            Assert.AreEqual(3, BasicLib.Quadrant(719.9));
            Assert.AreEqual(0, BasicLib.Quadrant(-719.9));

            Assert.IsTrue(BasicLib.Quadrant3To0(719, 0));
            Assert.IsFalse(BasicLib.Quadrant0To3(719, 0));
        }
Exemple #11
0
        private void GenerateMain()
        {
            StringBuilder sb = new StringBuilder();

            Bind(ref sb, _context.Templates.Header_Template);
            Bind(ref sb, _context.Templates.Globals_Template);
            Bind(ref sb, _context.Templates.MainProgramTemplate);
            foreach (Shape s in _currentToolPaths.Shapes)
            {
                Bind(ref sb, _context.Templates.SubCallTemplate);
            }
            Bind(ref sb, _context.Templates.ProgramEndTemplate);

            string ext = (string)BasicLib.GetSetting(SettingsNames.GCODE_FILE_EXT);
            BindableCodeTemplate tmpl = _context.Templates.MainFilenameTemplate;

            tmpl.DataContext = _context;
            Code.Add(new GcodeFile(System.IO.Path.ChangeExtension(tmpl.Text, ext), sb.ToString()));
        }
Exemple #12
0
        private Point CircleLineIntersect(Point Inside, Point Outside, double r)
        {
            Tuple <int, Point, Point> intrsct = BasicLib.CircleLineIntersect(Inside, Outside, r);

            if ((intrsct.Item1 == 0) || (intrsct.Item1 == 1))
            {
                return(intrsct.Item2);
            }
            else
            {
                if (BasicLib.Between(Inside, intrsct.Item2, Outside))
                {
                    return(intrsct.Item2);
                }
                else
                {
                    return(intrsct.Item3);
                }
            }
        }
Exemple #13
0
        public PathFragment(List <Point> points)
            : base()
        {
            int    winding   = 0;
            double lastAngle = 0;

            foreach (Point p in points)
            {
                Cartesian c = new Cartesian(p.X, p.Y, 0, winding);
                if (BasicLib.Quadrant3To0(lastAngle, c.Angle))
                {
                    winding += 1;
                }
                else if (BasicLib.Quadrant0To3(lastAngle, c.Angle))
                {
                    winding -= 1;
                }
                c.WindingNumber = winding;
                Add(c);
                lastAngle = c.Angle;
            }
        }
Exemple #14
0
        public PathFragment(Windows.UI.Xaml.Media.PointCollection pointCollection)
            : base()
        {
            int    winding   = 0;
            double lastAngle = 0;

            foreach (Point p in pointCollection)
            {
                Cartesian c = new Cartesian(p.X, p.Y, 0, winding);
                if (BasicLib.Quadrant3To0(lastAngle, c.Angle))
                {
                    winding += 1;
                }
                else if (BasicLib.Quadrant0To3(lastAngle, c.Angle))
                {
                    winding -= 1;
                }
                c.WindingNumber = winding;
                Add(c);
                lastAngle = c.Angle;
            }
        }
    private GameObject SpawnNpc(Transform[] fightersgroup)
    {
        GameObject temp    = null;
        int        teamnum = 0;

        for (int i = 0; i < _characters.Length; i++)
        {
            if (_characters[i] == fightersgroup)
            {
                temp    = BasicLib.InstantiatePrefabGmbjct("mobs/npc", MyColorLib.teams[i].transform);
                teamnum = i;
                break;
            }
        }
        LifeComponent        life          = temp.SearchComponent <LifeComponent>();
        AI                   aivars        = temp.SearchComponent <AI>();
        BaseCharacterControl vars          = temp.GetCharacter();
        MoveComponent        MoveComponent = temp.SearchComponent <MoveComponent>();

        //MoveComponent.speed = 10f;

        MoveComponent.SetPosition(_centreSpawns[teamnum] + new Vector3(Random.Range(-10f, 10f), Random.Range(-10f, 10f)));
        aivars.SearchComponent <MoveAround_ChillMode>().CentrePosition = Vector3.zero;

        /*
         * foreach (Transform[] otherteam in fighters)
         * {
         *  if (otherteam != fightersgroup)
         *  {
         *      rules.addToCandoAndToOthers(otherteam, MoveComponent.transform, true, true);
         *  }
         * }
         */

        int rand = Random.Range(0, 5);

        if (rand == 0)
        {
            aivars.AddAttacks(new int[] { WeaponsStaticClass.fire });
            temp.AddComponent <AttackFromDistance_AttackMode>();
        }
        else if (rand == 1)
        {
            aivars.AddAttacks(new int[] { WeaponsStaticClass.ball });
            temp.AddComponent <BallCharge_AttackMode>();
        }
        else if (rand == 2)
        {
            aivars.AddAttacks(new int[] { WeaponsStaticClass.spray });
            temp.AddComponent <AttackFromDistance_AttackMode>();
        }
        else if (rand == 3)
        {
            aivars.AddAttacks(new int[] { WeaponsStaticClass.ball });
            BallChargeAttack ball = temp.SearchComponent <BallChargeAttack>();
            ball.Reach   = 30f;
            ball.MaxSize = 1f;
            ball.Speed   = 60f;
            temp.AddComponent <BallCharge_AttackMode>();
        }
        else if (rand == 4)
        {
            aivars.AddAttacks(WeaponsStaticClass.shield).SearchComponent <Shield>().SetUpAI();
        }
        return(temp);
    }
Exemple #16
0
        public virtual double Height(double x)
        {
            double f = (x - _range.Start) / _range.Length;

            return(BasicLib.Linterp(_offsetL, f, _offsetR));
        }
 private static DialogueComponent SetDialogue(this BaseCharacterControl mainSpeaker)
 {
     return(BasicLib.InstantiatePrefabTr("chatObject", mainSpeaker.MoveComponent.transform).GetComponent <DialogueComponent>());
 }
Exemple #18
0
        private Windows.UI.Xaml.Shapes.Shape MkPath(int indx, int indy, double inc)
        {
            double innerR = Math.Abs(ld.Layout.ClipRange.Start);
            double outerR = Math.Abs(ld.Layout.ClipRange.End);

            double startX = indx * ld.Layout.Width + ld.Layout.OffsetX * colWidth;
            double startY = indy * ld.Layout.Height + ld.Layout.OffsetY * rowHeight;

            Path path = new Path();

            path.Stroke = new SolidColorBrush(Colors.Red);
            path.Name   = string.Format("Lattice{0}_{1}", indx, indy);
            GeometryGroup g = new GeometryGroup();

            path.Data = g;
            PathGeometry pg = new PathGeometry();

            g.Children.Add(pg);
            PathFigure pf;
            Point      origin = new Point(0, 0);

            foreach (Line2D ll in ld.Lines)
            {
                double x1 = startX + ll.X1 * colWidth;
                double x2 = startX + ll.X2 * colWidth;
                double y1 = startY + ll.Y1 * rowHeight;
                double y2 = startY + ll.Y2 * rowHeight;


                Point p1 = new Point(x1, y1);
                Point p2 = new Point(x2, y2);
                if (ld.Layout.Hyper)
                {
                    Hypo(ref p1);
                    Hypo(ref p2);
                }

                Point intrsct;

                if (ld.Layout.Clip)
                {
                    double d1     = p1.Radius();
                    double d2     = p2.Radius();
                    Point  pstart = (d1 < d2) ? p1 : p2;
                    Point  pend   = (d1 < d2) ? p2 : p1;
                    pf = null;
                    if (innerR > 0)
                    {
                        d1 = pstart.Radius();
                        d2 = pend.Radius();
                        // must clip against both inner and outer radii
                        // first clip against inner
                        if ((d1 > outerR) && (d2 > outerR))
                        {
                            Tuple <int, Point, Point> intrscts = BasicLib.CircleLineIntersect(pstart, pend, outerR);
                            if (intrscts.Item1 == 1)
                            {
                            }
                            else if (intrscts.Item1 == 2)
                            {
                                if (BasicLib.Between(pstart, intrscts.Item2, pend) &&
                                    BasicLib.Between(pstart, intrscts.Item3, pend))
                                {
                                    pf = GeneratePathFigure(intrscts.Item2, intrscts.Item3);
                                    pg.Figures.Add(pf);
                                }
                            }
                        }
                        else if ((d1 < innerR) && (d2 < innerR))
                        {
                            // do nothing
                        }

                        else if ((d1 < innerR) && (d2 >= innerR) && (d2 <= outerR))
                        {
                            if (BasicLib.IsVertical(pstart, pend))
                            {
                                double y = BasicLib.Sgn(pstart.Y) * Math.Sqrt(innerR * innerR - pstart.X * pstart.X);
                                Point  p = new Point(pstart.X, y);
                                pf = GeneratePathFigure(p, pend);
                            }
                            else if (BasicLib.IsHorizontal(pstart, pend))
                            {
                                double x = BasicLib.Sgn(pstart.X) * Math.Sqrt(innerR * innerR - pstart.Y * pstart.Y);
                                Point  p = new Point(x, pstart.Y);
                                pf = GeneratePathFigure(p, pend);
                            }
                            else
                            {
                                intrsct = CircleLineIntersect(pstart, pend, innerR);
                                pf      = GeneratePathFigure(intrsct, pend);
                            }
                        }
                        else if ((d1 >= innerR) && (d1 <= outerR) && (d2 >= innerR))
                        {
                            if (d2 <= outerR)
                            {
                                if (BasicLib.IsDiagonal(pstart, pend))
                                { // need to check if there is an intersection
                                    Tuple <int, Point, Point> intrscts = BasicLib.CircleLineIntersect(pstart, pend, innerR);
                                    if ((intrscts.Item1 == 0) || (intrscts.Item1 == 1))
                                    { // tangent so plot
                                        pf = GeneratePathFigure(pstart, pend);
                                    }
                                    else if (intrscts.Item1 == 2)
                                    {
                                        if (BasicLib.Between(pstart, intrscts.Item2, pend) &&
                                            BasicLib.Between(pstart, intrscts.Item3, pend))
                                        {
                                            Vector2 v1 = new Vector2(pstart, intrscts.Item2);
                                            Vector2 v2 = new Vector2(pstart, intrscts.Item3);
                                            if (v1.Length < v2.Length)
                                            {
                                                pf = GeneratePathFigure(pstart, intrscts.Item2);
                                                pg.Figures.Add(pf);
                                                pf = GeneratePathFigure(intrscts.Item3, pend);
                                            }
                                            else
                                            {
                                                pf = GeneratePathFigure(pstart, intrscts.Item3);
                                                pg.Figures.Add(pf);
                                                pf = GeneratePathFigure(intrscts.Item2, pend);
                                            }
                                        }
                                        else
                                        {
                                            pf = GeneratePathFigure(pstart, pend);
                                        }
                                    }
                                }
                                else
                                {
                                    pf = GeneratePathFigure(pstart, pend);
                                }
                            }
                            else  // here d2 lies outside outerR
                            {
                                if (BasicLib.IsVertical(pstart, pend))
                                {
                                    double y = BasicLib.Sgn(pstart.Y) * Math.Sqrt(outerR * outerR - pstart.X * pstart.X);
                                    pf = GeneratePathFigure(pstart, new Point(pstart.X, y));
                                }
                                else if (BasicLib.IsHorizontal(pstart, pend))
                                {
                                    double x = BasicLib.Sgn(pstart.X) * Math.Sqrt(outerR * outerR - pstart.Y * pstart.Y);
                                    pf = GeneratePathFigure(pstart, new Point(x, pstart.Y));
                                }
                                else
                                {
                                    intrsct = CircleLineIntersect(pstart, pend, outerR);
                                    pf      = GeneratePathFigure(pstart, intrsct);
                                }
                            }
                        }
                        if (pf != null)
                        {
                            try
                            {
                                if (pg.Figures.Contains(pf))
                                {
                                    pg.Figures.Remove(pf);
                                }
                                pg.Figures.Add(pf);
                            }
                            catch
                            {
                            }
                        }
                    }
                    else  // ignore innerR
                    #region Ignore innerR
                    {
                        if ((d1 > outerR) && (d2 > outerR))
                        {
                            pf = null;
                        }
                        else if ((d1 <= outerR) && (d2 <= outerR))
                        {
                            pf = GeneratePathFigure(pstart, pend);
                        }
                        else // one point lies either side
                        { // outerR must lie between d2 - d1
                            // need to start from inner not nearest
                            pstart = (d1 < outerR) ? p1 : p2;
                            pend   = (d1 < outerR) ? p2 : p1;

                            if (BasicLib.IsVertical(p1, p2))
                            {
                                double y = Math.Sign(pstart.Y) * Math.Sqrt(outerR * outerR - pstart.X * pstart.X);
                                pf = GeneratePathFigure(pstart, new Point(pstart.X, y));
                            }
                            else if (BasicLib.IsHorizontal(p1, p2))
                            {
                                double x = Math.Sign(pstart.X) * Math.Sqrt(outerR * outerR - pstart.Y * pstart.Y);
                                pf = GeneratePathFigure(pstart, new Point(x, pstart.Y));
                            }
                            else
                            {
                                intrsct = CircleLineIntersect(pstart, pend, outerR);
                                pf      = GeneratePathFigure(pstart, intrsct);
                            }
                        }

                        if (pf != null)
                        {
                            pg.Figures.Add(pf);
                        }
                    }
                    #endregion
                }
                else
                {
                    pf = GeneratePathFigure(p1, p2);
                    pg.Figures.Add(pf);
                }
            }
            return(path);
        }