当前位置: 首页>>代码示例>>C#>>正文


C# Vector2i.Equals方法代码示例

本文整理汇总了C#中Vector2i.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2i.Equals方法的具体用法?C# Vector2i.Equals怎么用?C# Vector2i.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector2i的用法示例。


在下文中一共展示了Vector2i.Equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main()
        {
            /*
            RenderWindow window = new RenderWindow(new VideoMode(200, 200), "SFML works!");

            Console.WriteLine("test");
            Console.ReadKey();
            */

            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML window");
            window.Closed += new EventHandler(OnClose);

            // Load a sprite to display
            Texture texture = new Texture("media/image/mario.png");
            Sprite sprite = new Sprite(texture);

            // Create a graphical text to display
            Font font = new Font("media/font/arial.ttf");
            Text text = new Text("Hello SFML", font, 50);

            // Load & play music
            Music music = new Music("media/sound/mario.ogg");
            music.Play();

            // starts the Stopwatch
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            // last mouse position
            Vector2i last_mouse_position = new Vector2i(0, 0);

            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                float speed = 0.1f * Convert.ToSingle(stopwatch.Elapsed.TotalMilliseconds);
                stopwatch.Reset();
                stopwatch.Start();

                if (Keyboard.IsKeyPressed(Keyboard.Key.Up))
                {
                    sprite.Position = new Vector2f(sprite.Position.X, sprite.Position.Y - speed);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Down))
                {
                    sprite.Position = new Vector2f(sprite.Position.X, sprite.Position.Y + speed);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Left))
                {
                    sprite.Position = new Vector2f(sprite.Position.X - speed, sprite.Position.Y);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
                {
                    sprite.Position = new Vector2f(sprite.Position.X + speed, sprite.Position.Y);
                }

                // only if its a new mouse position
                if (!last_mouse_position.Equals(Mouse.GetPosition()))
                {
                    if (Mouse.IsButtonPressed(Mouse.Button.Left))
                    {
                        Console.WriteLine("Klick Maustaste: Links; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                    if (Mouse.IsButtonPressed(Mouse.Button.Middle))
                    {
                        Console.WriteLine("Klick Maustaste: Mitte; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                    if (Mouse.IsButtonPressed(Mouse.Button.Right))
                    {
                        Console.WriteLine("Klick Maustaste: Rechts; X: " + Mouse.GetPosition().X
                            + "; Y: " + Mouse.GetPosition().X);
                        last_mouse_position = Mouse.GetPosition();
                    }
                }

                // Clear screen
                window.Clear();

                // Draw the sprite
                window.Draw(sprite);

                // Draw the string
                window.Draw(text);

                // Update the window
                window.Display();
            }
        }
开发者ID:Eisfuchs,项目名称:sfml_cs,代码行数:95,代码来源:main.cs

示例2: FindPath

        public List<Vector2i> FindPath(Vector2i start, Vector2i end, CostCallback costFn, Map map)
        {
            if (start.Equals (end)) {
                return new List<Vector2i> ();
            }
            // clear the lists
            openList = new Dictionary<ulong, Node> ();
            closedList = new Dictionary<ulong, Node> ();
            Node startNode = new Node (start);
            openList [startNode.Key] = startNode;
            bool pathfound = false;
            int searchCount = 0;
            while (!pathfound && openList.Count > 0 && searchCount < 500) {
                Node lowestCost = findLowestCost ();
                openList.Remove (lowestCost.Key);
                closedList[lowestCost.Key] = lowestCost;

                if (lowestCost.position.Equals (end)) {
                    pathfound = true;
                    break;
                }
                for (int i = 0; i < 4; i++) {

                    Vector2i neighborPosition = new Vector2i (lowestCost.position.x + Map.nDir [i, 0], lowestCost.position.y + Map.nDir [i, 1]);

                    int newCost = lowestCost.distanceCost + costFn (neighborPosition.x, neighborPosition.y);

                    if (map.IsOpenTile (neighborPosition.x, neighborPosition.y) && !openList.ContainsKey (Node.KeyFromPostion (neighborPosition))) {
                        Node newPosition = new Node (neighborPosition);
                        newPosition.heuristicCost = (int)Math.Abs (neighborPosition.x - end.x) + (int)Math.Abs (neighborPosition.y - end.y);
                        newPosition.distanceCost = newCost;
                        newPosition.parent = lowestCost;
                        openList[newPosition.Key] = newPosition;
                    } else if (openList.ContainsKey (Node.KeyFromPostion (neighborPosition)) && openList[Node.KeyFromPostion (neighborPosition)].distanceCost > newCost) {
                        openList [Node.KeyFromPostion (neighborPosition)].distanceCost = newCost;
                        openList [Node.KeyFromPostion (neighborPosition)].parent = lowestCost;
                    }
                }
                searchCount++;
            }
            Node nextn = null;
            // couldn't find a path to the end
            if (!closedList.ContainsKey (Node.KeyFromPostion (end))) {
                // just build a short list containing the neighbor tiles.
                // eventually this should find "as near as possible" type tiles to move towards
                // I guess it depends on the application though
                startNode = new Node (start);
                Node lowestCost = startNode;
                for (int i = 0; i < 4; i++) {
                    Vector2i neighborPosition = new Vector2i (lowestCost.position.x + Map.nDir [i, 0], lowestCost.position.y + Map.nDir [i, 1]);
                    int newCost = lowestCost.distanceCost + costFn (neighborPosition.x, neighborPosition.y);
                    if (map.IsOpenTile (neighborPosition.x, neighborPosition.y) && !openList.ContainsKey (Node.KeyFromPostion (neighborPosition))) {
                        Node newPosition = new Node (neighborPosition);
                        newPosition.heuristicCost = (int)Math.Abs (neighborPosition.x - end.x) + (int)Math.Abs (neighborPosition.y - end.y);
                        newPosition.distanceCost = newCost;
                        newPosition.parent = lowestCost;
                        openList [newPosition.Key] = newPosition;
                    }
                }
                nextn = findLowestCost ();
            } else {
                nextn = closedList [Node.KeyFromPostion (end)];
            }
            // build the step list
            List<Vector2i> returnList = new List<Vector2i> ();
            while (nextn != null) {
                returnList.Add (nextn.position);
                nextn = nextn.parent;
            }
            returnList.Reverse ();
            return returnList;
        }
开发者ID:jonbro,项目名称:nightmare_cooperative,代码行数:72,代码来源:Pathfinder.cs


注:本文中的Vector2i.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。