コード例 #1
0
        /// <summary>
        /// identify the defined _shapes in this IShape
        /// </summary>
        /// <param name="shape">shape to be identified</param>
        public void Identify(IShape shape)
        {
            shape.IdentifiedShapes = new List <IDefinedShape>();
            _tempRecognized        = new List <RecognizedShape>();
            int count = 0;

            //Get each ShapeRecognized
            foreach (IDefinedShape defsh in _definedShapes)
            {
                _tempPrime = defsh as IPrimalShape;
                if (_tempPrime != null)
                {
                    count = _tempRecognized.Count;
                    _tempRecognized.AddRange(_tempPrime.Recognize(shape));
                }
            }

            int index = 0;

            //_remove Each Shape which is entirely consumed by another
            while (index < _tempRecognized.Count)
            {
                bool _removed = false;
                for (int i = index + 1; i < _tempRecognized.Count; i++)
                {
                    if (_tempRecognized.Count > i)
                    {
                        _tempIdent = IShapeMethods.Compare(_tempRecognized[index], _tempRecognized[i]);
                        if (_tempIdent.Count == 1 && !_removed)
                        {
                            if (!_tempIdent.Contains(_tempRecognized[index]))
                            {
                                _removed = true;
                            }
                            else if (!_tempIdent.Contains(_tempRecognized[i]))
                            {
                                _tempRecognized.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
                if (_removed)
                {
                    _tempRecognized.RemoveAt(index);
                }
                else
                {
                    index++;
                }
            }
            // Add _shapes to _shape's Identified List
            foreach (RecognizedShape rShape in _tempRecognized)
            {
                shape.IdentifiedShapes.Add(rShape.DefinedShape);
            }
            IShapeMethods.CalculateShapePriority(shape, _castPrefs);
        }
コード例 #2
0
        public static void CombineShape(IShape blank, IShape shapeA, IShape shapeB, int ConnectingPntA, int ConnectingPntB, List <Entity> entities, bool indexBInit)
        {
            if (!indexBInit)
            {
                if (shapeA.Target == null)
                {
                    CheckEntityCollision(shapeB, entities);
                }
            }

            Shapes.Add(IShapeMethods.Combine(blank, shapeA, shapeB, ConnectingPntA, ConnectingPntB));
            Shapes.Remove(shapeB);
            Shapes.Remove(shapeA);
        }
コード例 #3
0
        public static void CombineShape(IShape blank, int indexA, int indexB, int ConnectingPntA, int ConnectingPntB, List <Entity> entities, bool indexBInit)
        {
            if (!indexBInit)
            {
                if (Shapes[indexA].Target == null)
                {
                    CheckEntityCollision(_shapes[indexB], entities);
                }
            }

            Shapes.Add(IShapeMethods.Combine(blank, Shapes[indexA], Shapes[indexB], ConnectingPntA, ConnectingPntB));
            Shapes.RemoveAt(indexB);
            Shapes.RemoveAt(indexA);
        }
コード例 #4
0
        /// <summary>
        /// Update based on input
        /// </summary>
        /// <param name="input">input manager</param>
        /// <param name="mous">mous</param>
        /// <param name="cam">Camera</param>
        /// <param name="entities">all entities</param>
        public void InputUpdate(CompMouse mous, GameCam cam, List <Entity> entities)
        {
            if (InputManager.CheckButtonDown("Cast Spell", false, false) && _lastShapeClicked >= 0)
            {
                Identify(ShapeRegistry.Shapes[_lastShapeClicked]);
                ShapeRegistry.Cast(_lastShapeClicked);
                ShapeRegistry.Shapes.RemoveAt(_lastShapeClicked);
                _lastShapeClicked = _lastPointClicked = -1;
            }

            InputManager.CheckButtonDown("Open Magic Mode", false, false, true);
            _magicMode = InputManager.getToggle("Open Magic Mode");

            if (_movingPnt)
            {
                if (!InputManager.CheckButtonDown("Add/Select Spell Point", false, false))
                {
                    Identify(ShapeRegistry.Shapes[_lastShapeClicked]);
                    //if (!_heldControl)
                    //     _lastPointClicked = -1;
                    _movingPnt = false;
                    _moveWait  = 0;
                }
            }

            InputManager.CheckButtonDown("Speed Creation Mode", false, true);

            if (InputManager.CheckButtonDown("Add/Select Spell Point", false, false))
            {
                if (!_movingPnt)
                {
                    if (_lastPointClicked >= 0)
                    {
                        if (ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].intersects(mous, ShapeRegistry.PointSize, cam))
                        {
                            if (_moveWait < 5)
                            {
                                _moveWait++;
                            }
                            else
                            {
                                _moveWait     = 0;
                                _movingPnt    = true;
                                _lastMouseLoc = mous.Location;
                            }
                        }
                    }
                }
                else
                {
                    ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked]._location     -= _lastMouseLoc - mous.Location;
                    ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].MoveToLocation = ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked]._location;

                    if (ShapeRegistry.Shapes[_lastShapeClicked].Target == null)
                    {
                        foreach (Entity ent in entities)
                        {
                            if (ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].intersects(ent, ShapeRegistry.PointSize, cam))
                            {
                                ShapeRegistry.Shapes[_lastShapeClicked].Target          = ent;
                                ShapeRegistry.Shapes[_lastShapeClicked].PointAttachment = _lastPointClicked;
                            }
                        }
                    }
                    else
                    {
                        if (!ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].intersects(ShapeRegistry.Shapes[_lastShapeClicked].Target, ShapeRegistry.PointSize, cam) && ShapeRegistry.Shapes[_lastShapeClicked].PointAttachment == _lastPointClicked)
                        {
                            ShapeRegistry.Shapes[_lastShapeClicked].Target        = null;
                            (ShapeRegistry.Shapes[_lastShapeClicked]).FirstTarget = false;
                        }
                    }

                    _lastMouseLoc = mous.Location;
                }
            }

            if (InputManager.CheckButtonDown("Add/Select Spell Point", true, false) && _magicMode)
            {
                _clicked        = false;
                _curCombineShpe = -1;
                _curCombinePnt  = -1;
                foreach (IShape shpe in ShapeRegistry.Shapes)
                {
                    _temSh     = shpe;
                    _tempindex = ShapeRegistry.Shapes.IndexOf(shpe);
                    ShapeRegistry.isonscreen(shpe, cam);
                    if (ShapeRegistry.PointsOnScreen.Count > 0)
                    {
                        foreach (MagicPoint pnt in ShapeRegistry.PointsOnScreen)
                        {
                            if (pnt.intersects(mous, ShapeRegistry.PointSize, cam))
                            {
                                if (_lastPointClicked >= 0)
                                {
                                    if (_lastShapeClicked == ShapeRegistry.Shapes.IndexOf(shpe))
                                    {
                                        bool exists = false;

                                        if (shpe.Points[_lastPointClicked].Connections.Contains(pnt.ID))
                                        {
                                            exists = true;
                                        }

                                        if (!exists && _lastPointClicked != shpe.Points.IndexOf(pnt))
                                        {
                                            ShapeRegistry.AddInternalConnection(_lastPointClicked, pnt.ID, shpe);
                                            Identify(shpe);
                                            if (InputManager.isBeingHeld("Speed Creation Mode"))
                                            {
                                                _heldControl      = true;
                                                _lastPointClicked = pnt.ID;
                                            }
                                            else
                                            {
                                                _lastPointClicked = -1;
                                            }
                                        }
                                        else
                                        {
                                            _lastPointClicked = pnt.ID;
                                        }
                                    }
                                    else
                                    {
                                        _curCombineShpe = ShapeRegistry.Shapes.IndexOf(shpe);
                                        _curCombinePnt  = pnt.ID;
                                    }
                                }
                                else
                                {
                                    _lastPointClicked = pnt.ID;
                                    _lastShapeClicked = ShapeRegistry.Shapes.IndexOf(shpe);
                                }
                                _clicked = true;
                            }
                        }
                    }
                }
                if (_tempindex >= 0)
                {
                    ShapeRegistry.Shapes[_tempindex] = _temSh;
                }

                if (!_clicked)
                {
                    if (_heldControl && _lastPointClicked != -1)
                    {
                        ShapeRegistry.Addshape(mous.Location, _rand, entities, false);
                        ShapeRegistry.CombineShape(new Shape(true), _lastShapeClicked, ShapeRegistry.Shapes.Count - 1, _lastPointClicked, 0, entities, false);
                    }
                    else
                    {
                        ShapeRegistry.Addshape(mous.Location, _rand, entities, true);
                    }
                    _lastShapeClicked = ShapeRegistry.Shapes.Count - 1;
                    _lastPointClicked = 0;
                    Identify(ShapeRegistry.Shapes[_lastShapeClicked]);

                    if (InputManager.isBeingHeld("Speed Creation Mode"))
                    {
                        _heldControl      = true;
                        _lastPointClicked = ShapeRegistry.Shapes[_lastShapeClicked].Points.Count - 1;
                    }
                    else
                    {
                        _curCombinePnt = _curCombineShpe = _lastPointClicked = -1;
                    }
                }

                if (_lastShapeClicked != -1 && _lastPointClicked != -1 && _curCombinePnt != -1 && _curCombineShpe != -1)
                {
                    int i = _curCombinePnt + ShapeRegistry.Shapes[_lastShapeClicked].Points.Count;
                    ShapeRegistry.CombineShape(new Shape(true), ShapeRegistry.Shapes[_lastShapeClicked], ShapeRegistry.Shapes[_curCombineShpe], _lastPointClicked, _curCombinePnt, entities, true);

                    _lastShapeClicked = ShapeRegistry.Shapes.Count - 1;
                    if (InputManager.isBeingHeld("Speed Creation Mode"))
                    {
                        _heldControl      = true;
                        _lastPointClicked = i;
                        _curCombinePnt    = _curCombineShpe = -1;
                    }
                    else
                    {
                        _curCombinePnt = _curCombineShpe = _lastPointClicked = -1;
                    }
                    Identify(ShapeRegistry.Shapes[_lastShapeClicked]);
                }
            }

            if (InputManager.CheckButtonDown("Remove Spell Points/Connections", true, false) && _magicMode)
            {
                _clicked = false;
                foreach (IShape shpe in ShapeRegistry.Shapes)
                {
                    ShapeRegistry.isonscreen(shpe, cam);
                    if (ShapeRegistry.PointsOnScreen.Count > 0)
                    {
                        foreach (MagicPoint pnt in ShapeRegistry.PointsOnScreen)
                        {
                            if (pnt.intersects(mous, ShapeRegistry.PointSize, cam))
                            {
                                _removePnt   = pnt.ID;
                                _removeShape = ShapeRegistry.Shapes.IndexOf(shpe);
                                Identify(shpe);


                                _clicked = true;
                            }
                        }
                    }
                }

                if (_removePnt != -1)
                {
                    ShapeRegistry.Shapes[_removeShape] = ShapeRegistry.RemovePoint(_removePnt, ShapeRegistry.Shapes[_removeShape]);
                }
                if (ShapeRegistry.Shapes[_removeShape].Points.Count == 0)
                {
                    if (_lastShapeClicked == _removeShape)
                    {
                        _lastShapeClicked = -1;
                    }
                    _lastPointClicked = -1;
                    ShapeRegistry.Shapes.RemoveAt(_removeShape);
                }

                if (_removePnt != -1)
                {
                    if (_lastPointClicked == _removePnt && _lastShapeClicked == _removeShape)
                    {
                        _lastPointClicked = -1;
                    }
                    _movingPnt = false;
                    _moveWait  = 0;
                    _removePnt = -1;
                }

                if (!_clicked)
                {
                    int temin = -1;
                    foreach (Shape shpe in ShapeRegistry.Shapes)
                    {
                        int  rem   = -1;
                        int  pntID = -1;
                        bool done  = false;
                        foreach (MagicPoint pnt in shpe.Points)
                        {
                            foreach (int i in pnt.Connections)
                            {
                                if (!done)
                                {
                                    if (IShapeMethods.intersectCon(mous, shpe.Points[pnt.ID]._location, shpe.Points[i]._location, ShapeRegistry.PointSize, cam))
                                    {
                                        _temSh            = shpe;
                                        temin             = ShapeRegistry.Shapes.IndexOf(_temSh);
                                        rem               = i;
                                        _clicked          = true;
                                        _lastPointClicked = -1;
                                        _movingPnt        = false;
                                        _moveWait         = 0;
                                        pntID             = pnt.ID;
                                        if (InputManager.CheckButtonDown("Spell Separation", false, false))
                                        {
                                            _lastShapeClicked = -1;
                                        }
                                        done = true;
                                    }
                                }
                            }
                        }

                        if (InputManager.CheckButtonDown("Spell Separation", false, false) && temin > -1)
                        {
                            _pointsInShape.RemoveAll(RemoveAllin);
                            _pointsInShape.Add(rem);
                            foreach (int i in shpe.Points[rem]._connections)
                            {
                                _pointsInShape.Add(rem);
                            }

                            if (_pointsInShape.Count > 1)
                            {
                                CheckforSeparation(_pointsInShape, _temSh, 1, rem);
                            }

                            if (_pointsInShape.Count < _temSh.Points.Count)
                            {
                                _pntDic = new Dictionary <int, int>();
                                _sh     = new Shape(true);
                                foreach (int i in _pointsInShape)
                                {
                                    _sh.Points.Add(_temSh.Points[i]);
                                }

                                for (int i = 0; i < _pointsInShape.Count; i++)
                                {
                                    _pntDic.Add(_pointsInShape[i], _sh.Points.IndexOf(_temSh.Points[_pointsInShape[i]]));
                                }

                                for (int i = 0; i < _pointsInShape.Count; i++)
                                {
                                    _temSh.Points.RemoveAt(_pointsInShape[i]);
                                    for (int n = i; n < _pointsInShape.Count; n++)
                                    {
                                        if (_pointsInShape[n] > _pointsInShape[i])
                                        {
                                            _pointsInShape[n]--;
                                        }
                                    }
                                }
                            }
                        }
                        if (rem != -1)
                        {
                            ShapeRegistry.removeConnection(rem, pntID, _temSh);
                        }
                    }
                    if (temin > -1)
                    {
                        ShapeRegistry.Shapes[temin] = _temSh;
                        Identify(_temSh);
                        if (InputManager.CheckButtonDown("Spell Separation", false, false) && _sh != null)
                        {
                            Identify(_sh);
                            ShapeRegistry.Shapes.Add(_sh);
                        }
                    }
                }

                if (!_clicked)
                {
                    _lastPointClicked = _lastShapeClicked = -1;
                }
                else
                {
                    if (_removeShape != -1)
                    {
                        ShapeRegistry.Shapes.RemoveAt(_removeShape);
                    }
                    _removeShape = -1;
                }
            }

            if (InputManager.CheckButtonDown("Clear Spells", true, false) && _magicMode)
            {
                _clicked = false;
                foreach (Shape shpe in ShapeRegistry.Shapes)
                {
                    ShapeRegistry.isonscreen(shpe, cam);
                    if (ShapeRegistry.PointsOnScreen.Count > 0)
                    {
                        foreach (MagicPoint pnt in ShapeRegistry.PointsOnScreen)
                        {
                            if (pnt.intersects(mous, ShapeRegistry.PointSize, cam))
                            {
                                _removeShape = ShapeRegistry.Shapes.IndexOf(shpe);
                                _clicked     = true;
                            }
                        }
                    }
                }

                if (!_clicked)
                {
                    foreach (Shape shpe in ShapeRegistry.Shapes)
                    {
                        _temSh     = shpe;
                        _tempindex = ShapeRegistry.Shapes.IndexOf(shpe);
                        ShapeRegistry.isonscreen(shpe, cam);
                        if (ShapeRegistry.PointsOnScreen.Count > 0)
                        {
                            foreach (MagicPoint pnt in shpe.Points)
                            {
                                foreach (int i in pnt.Connections)
                                {
                                    if (IShapeMethods.intersectCon(mous, shpe.Points[pnt.ID]._location, shpe.Points[i]._location, ShapeRegistry.PointSize, cam))
                                    {
                                        _conClicked = true;
                                        _clicked    = true;
                                    }
                                }
                            }
                            if (_conClicked)
                            {
                                _conClicked = false;
                            }
                        }
                    }
                    if (_tempindex >= 0)
                    {
                        ShapeRegistry.Shapes[_tempindex] = _temSh;
                    }
                }

                if (!_clicked)
                {
                    ShapeRegistry.Shapes = new List <IShape>();
                    _lastShapeClicked    = _lastPointClicked = -1;
                }
                else if (_removeShape != -1)
                {
                    ShapeRegistry.Shapes.RemoveAt(_removeShape);
                    if (_removeShape == _lastShapeClicked)
                    {
                        _lastShapeClicked = _lastPointClicked = -1;
                    }
                    _removeShape = -1;
                    _movingPnt   = false;
                    _moveWait    = 0;
                }
            }
            _tempindex = -1;
        }