コード例 #1
0
 public void Update(GameTime gameTime, MouseRectangle mouseRectangle, Map map)
 {
     for (int i = 0; i < Units.Count; i++)
     {
         Units[i].Update(gameTime, mouseRectangle, map, i, Units);
     }
 }
コード例 #2
0
        public Game1()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            map    = new Map();
            camera = new Camera();

            mouseRectangle = new MouseRectangle();
            unitManager    = new UnitManager();

            unitManager.Units.Add(new Unit(new Vector2(0, 0)));
            unitManager.Units.Add(new Unit(new Vector2(0, 32)));
            unitManager.Units.Add(new Unit(new Vector2(0, 64)));
            unitManager.Units.Add(new Unit(new Vector2(0, 96)));
            unitManager.Units.Add(new Unit(new Vector2(0, 128)));
        }
コード例 #3
0
        public void Update(GameTime gameTime, MouseRectangle mouseRectangle, Map map, int UnitID, List <Unit> Units)
        {
            rectangle = new Rectangle((int)Position.X, (int)Position.Y, (int)Size.X, (int)Size.Y);

            if (mouseRectangle.rectangle.Intersects(rectangle))
            {
                UnitState = State.Hovered;
            }
            else if (UnitState != State.Selected)
            {
                UnitState = State.Normal;
            }

            if (!mouseRectangle.rectangle.Intersects(rectangle) && MouseCursor.CurrentMouseState.LeftButton == ButtonState.Pressed && UnitState == State.Selected)
            {
                UnitState = State.Normal;
            }

            if (mouseRectangle.rectangle.Intersects(rectangle) && MouseCursor.CurrentMouseState.LeftButton == ButtonState.Released && UnitState == State.Hovered)
            {
                UnitState = State.Selected;
            }

            if (UnitState == State.Normal)
            {
                CurrentTexture = NormalTexture;
            }

            if (UnitState == State.Hovered)
            {
                CurrentTexture = HoveredTexture;
            }

            if (UnitState == State.Selected)
            {
                CurrentTexture = SelectedTexture;
            }

            Astar(gameTime, mouseRectangle, map, UnitID, Units);
        }
コード例 #4
0
        void Astar(GameTime gameTime, MouseRectangle mouseRectangle, Map map, int UnitID, List <Unit> Units)
        {
            if (MouseCursor.CurrentMouseState.RightButton == ButtonState.Pressed && MouseCursor.LastMouseState.RightButton == ButtonState.Released && UnitState == State.Selected)
            {
                astarThreadWorker = null;
                AstarManager.AddNewThreadWorker(new Node(new Vector2((int)Position.X / 16, (int)Position.Y / 16)),
                                                new Node(new Vector2((int)MouseCursor.CurrentMouseState.X / 16, (int)MouseCursor.CurrentMouseState.Y / 16)), map, false, UnitID);
            }

            AstarManager.AstarThreadWorkerResults.TryPeek(out astarThreadWorkerTemp);

            if (astarThreadWorkerTemp != null)
            {
                if (astarThreadWorkerTemp.WorkerIDNumber == UnitID)
                {
                    AstarManager.AstarThreadWorkerResults.TryDequeue(out astarThreadWorker);

                    if (astarThreadWorker != null)
                    {
                        wayPoint = new WayPoint();

                        WayPointsList = astarThreadWorker.astar.GetFinalPath();

                        for (int i = 0; i < WayPointsList.Count; i++)
                        {
                            WayPointsList[i] = new Vector2(WayPointsList[i].X * 16, WayPointsList[i].Y * 16);
                        }
                    }
                }
            }

            if (WayPointsList.Count > 0)
            {
                Avoidence(gameTime, Units, UnitID);
                wayPoint.MoveTo(gameTime, this, WayPointsList, Speed);
            }
        }
コード例 #5
0
ファイル: InputManager.cs プロジェクト: MSigma/ZooBurst
 public static bool MouseOver(Rectangle rectangle) => (MouseRectangle.Intersects(rectangle));
コード例 #6
0
ファイル: InputManager.cs プロジェクト: MSigma/ZooBurst
 public static bool MouseOver(int x, int y, int width, int height) => (MouseRectangle.Intersects(new Rectangle(x, y, width, height)));