private void SetRoamState(Floor parent)
        {
            var myPosition = parent.Entities.Reverse[this];

            CurrentState = State.Roaming;
            var visible = VisiblePoints.ToArray();

            if (visible.Length != 0)
            {
                var roamPoint = visible[RandomHelper.Random.Next(0, visible.Length)];
                var path      = PathFinder.AStar(parent, myPosition, roamPoint);

                if (path != null)
                {
                    Path = path;
                    return;
                }
            }

            RandomMoveDirection.Shuffle();
            foreach (var direction in RandomMoveDirection)
            {
                if (parent.IsPointPassable(NewPosition(direction, myPosition)))
                {
                    MoveTo(parent, direction);
                    return;
                }
            }
            SetWaitState();
        }
Exemple #2
0
 public KnotStateChoose1(KnotData data)
 {
     this.data = data;
     //float floatShift = ((float)this.data.shift) / this.data.points.Count;
     //Func<Vector2, Vector2> uvTransformer = (uv) => new Vector2(uv.x, uv.y + floatShift);
     //this.knotMesh = MakeMesh.GetMesh(this.data.points, this.data.meridian, this.data.radius, true, uvTransformer);
     this.knotMesh      = this.data.GetWholeMesh();
     this.visiblePoints = new VisiblePoints(new List <Vector3>(), this.data.curve.radius * 2.0f);
 }
        private void SetVisiblePoints(string visiblePoints)
        {
            if (Enum.TryParse(visiblePoints, true, out VisiblePoints p) && p != _showPoints)
            {
                _showPoints = p;
                Invalidate();
            }

            _control.SetVisiblePoints(_showPoints);
        }
        private void CycleShowPoints()
        {
            var side = (int)_showPoints;

            side        = (side + 1) % (Enum.GetValues(typeof(VisiblePoints)).Length);
            _showPoints = (VisiblePoints)side;
            Invalidate();

            _control.SetVisiblePoints(_showPoints);
        }
        public void VisiblePointsDicionaryOutputTest()
        {
            var result = VisiblePoints.FromOrigin(origin, samplePoints, new List <Polygon> {
                boundary
            }, new List <Polygon> {
                obstacles
            });

            Assert.IsTrue(result.Keys.Contains("score"));
            Assert.IsTrue(result.Keys.Contains("visiblePoints"));
        }
        public void FromOriginTest()
        {
            var result = VisiblePoints.FromOrigin(origin, samplePoints, new List <Polygon> {
                boundary
            }, new List <Polygon> {
                obstacles
            });

            var visiblePointsScore = (double)result["score"];

            Assert.AreEqual(0.57, Math.Round(visiblePointsScore, 2));
        }
Exemple #7
0
        // FUNCTIONS //

        //abstract/override
        public override void HandleVisibility()
        {
            List <Creature> creatures = CurrentFloor >= 0 ? Program.WorldMap[WorldIndex.X, WorldIndex.Y].Dungeon.Floors[CurrentFloor].Creatures : Program.WorldMap[WorldIndex.X, WorldIndex.Y].Creatures;

            visibleCreatures = new List <Creature>();
            foreach (Creature c in creatures)
            {
                if (VisiblePoints.Exists(p => p.Equals(c.Position)))
                {
                    visibleCreatures.Add(c);
                }
            }
        }
        private void CheckForNearbyRivals(GameState state)
        {
            const int cooldown = 20;

            foreach (var character in state.CurrentFloor.Entities)
            {
                // TODO: Make monsters attack not only players
                if (character.Value is Player player && VisiblePoints.Contains(character.Key))
                {
                    RivalCharacter = player;
                    CurrentState   = State.Enraged;
                    Cooldown       = cooldown;
                    break;
                }
            }
        }
Exemple #9
0
        public VertexPointTool()
        {
            _vertices = new Dictionary <VertexSolid, VertexList>();

            States.Add(new WrapperDraggableState(GetDraggables));

            _boxState              = new BoxDraggableState(this);
            _boxState.BoxColour    = Color.Orange;
            _boxState.FillColour   = Color.FromArgb(64, Color.DodgerBlue);
            _boxState.DragStarted += (sender, args) =>
            {
                if (!KeyboardState.Ctrl)
                {
                    DeselectAll();
                }
            };

            States.Add(_boxState);

            _showPoints = VisiblePoints.All;
        }
Exemple #10
0
        /// <summary>
        /// Examine the provided octant and calculate the visible cells within it.
        /// </summary>
        /// <param name="pDepth">Depth of the scan</param>
        /// <param name="pOctant">Octant being examined</param>
        /// <param name="pStartSlope">Start slope of the octant</param>
        /// <param name="pEndSlope">End slope of the octance</param>
        protected void ScanOctant(int pDepth, int pOctant, double pStartSlope, double pEndSlope)
        {
            int visrange2 = VisualRange * VisualRange;
            int x         = 0;
            int y         = 0;

            switch (pOctant)
            {
            case 1:     //nnw
                y = player.Y - pDepth;
                if (y < 0)
                {
                    return;
                }

                x = player.X - Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (x < 0)
                {
                    x = 0;
                }

                while (GetSlope(x, y, player.X, player.Y, false) >= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)                       //current cell blocked
                        {
                            if (x - 1 >= 0 && map[x - 1, y] == 0) //prior cell within range AND open...
                                                                  //...incremenet the depth, adjust the endslope and recurse
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x - 0.5, y + 0.5, player.X, player.Y, false));
                            }
                        }
                        else
                        {
                            if (x - 1 >= 0 && map[x - 1, y] == 1)     //prior cell within range AND open...
                                                                      //..adjust the startslope
                            {
                                pStartSlope = GetSlope(x - 0.5, y - 0.5, player.X, player.Y, false);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    x++;
                }
                x--;
                break;

            case 2:     //nne

                y = player.Y - pDepth;
                if (y < 0)
                {
                    return;
                }

                x = player.X + Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (x >= map.GetLength(0))
                {
                    x = map.GetLength(0) - 1;
                }

                while (GetSlope(x, y, player.X, player.Y, false) <= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)
                        {
                            if (x + 1 < map.GetLength(0) && map[x + 1, y] == 0)
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x + 0.5, y + 0.5, player.X, player.Y, false));
                            }
                        }
                        else
                        {
                            if (x + 1 < map.GetLength(0) && map[x + 1, y] == 1)
                            {
                                pStartSlope = -GetSlope(x + 0.5, y - 0.5, player.X, player.Y, false);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    x--;
                }
                x++;
                break;

            case 3:

                x = player.X + pDepth;
                if (x >= map.GetLength(0))
                {
                    return;
                }

                y = player.Y - Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (y < 0)
                {
                    y = 0;
                }

                while (GetSlope(x, y, player.X, player.Y, true) <= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)
                        {
                            if (y - 1 >= 0 && map[x, y - 1] == 0)
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x - 0.5, y - 0.5, player.X, player.Y, true));
                            }
                        }
                        else
                        {
                            if (y - 1 >= 0 && map[x, y - 1] == 1)
                            {
                                pStartSlope = -GetSlope(x + 0.5, y - 0.5, player.X, player.Y, true);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    y++;
                }
                y--;
                break;

            case 4:

                x = player.X + pDepth;
                if (x >= map.GetLength(0))
                {
                    return;
                }

                y = player.Y + Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (y >= map.GetLength(1))
                {
                    y = map.GetLength(1) - 1;
                }

                while (GetSlope(x, y, player.X, player.Y, true) >= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)
                        {
                            if (y + 1 < map.GetLength(1) && map[x, y + 1] == 0)
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x - 0.5, y + 0.5, player.X, player.Y, true));
                            }
                        }
                        else
                        {
                            if (y + 1 < map.GetLength(1) && map[x, y + 1] == 1)
                            {
                                pStartSlope = GetSlope(x + 0.5, y + 0.5, player.X, player.Y, true);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    y--;
                }
                y++;
                break;

            case 5:

                y = player.Y + pDepth;
                if (y >= map.GetLength(1))
                {
                    return;
                }

                x = player.X + Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (x >= map.GetLength(0))
                {
                    x = map.GetLength(0) - 1;
                }

                while (GetSlope(x, y, player.X, player.Y, false) >= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)
                        {
                            if (x + 1 < map.GetLength(1) && map[x + 1, y] == 0)
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x + 0.5, y - 0.5, player.X, player.Y, false));
                            }
                        }
                        else
                        {
                            if (x + 1 < map.GetLength(1) &&
                                map[x + 1, y] == 1)
                            {
                                pStartSlope = GetSlope(x + 0.5, y + 0.5, player.X, player.Y, false);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    x--;
                }
                x++;
                break;

            case 6:

                y = player.Y + pDepth;
                if (y >= map.GetLength(1))
                {
                    return;
                }

                x = player.X - Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (x < 0)
                {
                    x = 0;
                }

                while (GetSlope(x, y, player.X, player.Y, false) <= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)
                        {
                            if (x - 1 >= 0 && map[x - 1, y] == 0)
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x - 0.5, y - 0.5, player.X, player.Y, false));
                            }
                        }
                        else
                        {
                            if (x - 1 >= 0 &&
                                map[x - 1, y] == 1)
                            {
                                pStartSlope = -GetSlope(x - 0.5, y + 0.5, player.X, player.Y, false);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    x++;
                }
                x--;
                break;

            case 7:

                x = player.X - pDepth;
                if (x < 0)
                {
                    return;
                }

                y = player.Y + Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (y >= map.GetLength(1))
                {
                    y = map.GetLength(1) - 1;
                }

                while (GetSlope(x, y, player.X, player.Y, true) <= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)
                        {
                            if (y + 1 < map.GetLength(1) && map[x, y + 1] == 0)
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x + 0.5, y + 0.5, player.X, player.Y, true));
                            }
                        }
                        else
                        {
                            if (y + 1 < map.GetLength(1) && map[x, y + 1] == 1)
                            {
                                pStartSlope = -GetSlope(x - 0.5, y + 0.5, player.X, player.Y, true);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    y--;
                }
                y++;
                break;

            case 8:     //wnw

                x = player.X - pDepth;
                if (x < 0)
                {
                    return;
                }

                y = player.Y - Convert.ToInt32((pStartSlope * Convert.ToDouble(pDepth)));
                if (y < 0)
                {
                    y = 0;
                }

                while (GetSlope(x, y, player.X, player.Y, true) >= pEndSlope)
                {
                    if (GetVisDistance(x, y, player.X, player.Y) <= visrange2)
                    {
                        if (map[x, y] == 1)
                        {
                            if (y - 1 >= 0 && map[x, y - 1] == 0)
                            {
                                ScanOctant(pDepth + 1, pOctant, pStartSlope, GetSlope(x + 0.5, y - 0.5, player.X, player.Y, true));
                            }
                        }
                        else
                        {
                            if (y - 1 >= 0 && map[x, y - 1] == 1)
                            {
                                pStartSlope = GetSlope(x - 0.5, y - 0.5, player.X, player.Y, true);
                            }

                            VisiblePoints.Add(new Point(x, y));
                        }
                    }
                    y++;
                }
                y--;
                break;
            }


            if (x < 0)
            {
                x = 0;
            }
            else if (x >= map.GetLength(0))
            {
                x = map.GetLength(0) - 1;
            }

            if (y < 0)
            {
                y = 0;
            }
            else if (y >= map.GetLength(1))
            {
                y = map.GetLength(1) - 1;
            }

            if (pDepth < VisualRange & map[x, y] == 0)
            {
                ScanOctant(pDepth + 1, pOctant, pStartSlope, pEndSlope);
            }
        }