示例#1
0
        protected override void Initialize()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), _spriteBatch);

            _map = new Map(7, 7, 50, this);
            _aStar = new AStarPathFinder(_map);

            Components.Add(_map);

            base.Initialize();
        }
示例#2
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                Exit();

            var keyboardState = Keyboard.GetState();

            if(keyboardState.IsKeyDown(Keys.P) && _previousKeyboardState.IsKeyDown(Keys.P) == false)
            {
                _aStar.CalculatePath();
            }

            if (keyboardState.IsKeyDown(Keys.R) && _previousKeyboardState.IsKeyDown(Keys.R) == false)
            {
                _map.Reset();
                _aStar = new AStarPathFinder(_map);
            }

            _previousKeyboardState = keyboardState;

            base.Update(gameTime);
        }