Пример #1
0
        public Projectile(Block[] blocks, int width, int height, Point startPoint, Point endPoint, Item item)
        {
            bool PlotPath(int x, int y)
            {
                if (new Point(x, y).Equals(startPoint))
                {
                    return(true);
                }
                if (x >= width || y >= height || x < 0 || y < 0 || blocks[x * width + y].Solid)
                {
                    if (blocks[x * width + y] is Creature)
                    {
                        path.Add(new Point(x, y));
                    }
                    return(false);
                }
                path.Add(new Point(x, y));
                return(true);
            }

            this.item = item;
            path      = new List <Point>();
            Bresenhams.Line(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, PlotPath);
            if (path.Count != 0)
            {
                position = path[0];
            }
            else
            {
                position = startPoint;
            }
        }
Пример #2
0
        private void RenderPath()
        {
            int   currentFloor = Program.Player.CurrentFloor;
            Point worldIndex   = Program.Player.WorldIndex;

            Block[] blocks = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Blocks : Program.WorldMap[worldIndex.X, worldIndex.Y].Blocks;
            Tile[]  tiles = currentFloor >= 0 ? Program.WorldMap[worldIndex.X, worldIndex.Y].Dungeon.Floors[currentFloor].Floor : Program.WorldMap[worldIndex.X, worldIndex.Y].Floor;
            int     width = Program.WorldMap.TileWidth, height = Program.WorldMap.TileHeight;

            Point startPoint = Program.Window.CalculateMapStartPoint();

            if (PlayerInput.AimingMode == false)
            {
                List <Point> guiPath = GUI.CalculatePath(startPoint, Program.Window.Width);
                if (guiPath != null)
                {
                    foreach (Point point in guiPath)
                    {
                        bool pointOutsideMapViewer = point.Y - startPoint.Y < 0 || point.Y - startPoint.Y >= Program.Window.Height ||
                                                     point.X - startPoint.X < 0 || point.X - startPoint.X >= Program.Window.Width - StatusPanel.Width;
                        if (pointOutsideMapViewer)
                        {
                            continue;
                        }

                        if (blocks[point.X * width + point.Y] is Air)
                        {
                            Program.Console.SetGlyph(point.X - startPoint.X, point.Y - startPoint.Y, tiles[point.X * width + point.Y].Graphic,
                                                     tiles[point.X * width + point.Y].ForeColor, Color.RoyalBlue);
                        }
                        else
                        {
                            Program.Console.SetGlyph(point.X - startPoint.X, point.Y - startPoint.Y, blocks[point.X * width + point.Y].Graphic,
                                                     blocks[point.X * width + point.Y].ForeColor, Color.RoyalBlue);
                        }
                    }
                }
            }
            else
            {
                Point mousePos = new Point(SadConsole.Global.MouseState.ScreenPosition.X / SadConsole.Global.FontDefault.Size.X,
                                           SadConsole.Global.MouseState.ScreenPosition.Y / SadConsole.Global.FontDefault.Size.Y);
                Point mapPos = new Point(startPoint.X + (mousePos.X), startPoint.Y + mousePos.Y);
                bool Plot(int x, int y)
                {
                    if (new Point(x, y).Equals(Program.Player.Position))
                    {
                        return(true);
                    }
                    if (x > width || y > height || x < 0 || y < 0 || !SadConsole.Global.MouseState.IsOnScreen || mousePos.X >= StatusPanel.StartX || blocks[x * width + y].Solid)
                    {
                        return(false);
                    }
                    Program.Console.SetGlyph(x - startPoint.X, y - startPoint.Y, new Point(x, y).Equals(mapPos) ? 88 : blocks[x * width + y].Graphic,
                                             new Point(x, y).Equals(mapPos) ? Color.DarkRed * 0.98F : blocks[x * width + y].ForeColor, Color.Red);
                    return(true);
                }

                Bresenhams.Line(Program.Player.Position.X, Program.Player.Position.Y, mapPos.X, mapPos.Y, Plot);
            }
        }