Example #1
0
        protected override void Initialize()
        {
            tileMap = new TileMap(MAP_SEED, MAP_WIDTH, MAP_HEIGHT);
            tileMap.Generate(MAP_SMOOTHNESS);
            tileMap.Initialize();

            camera = new Camera(graphics.GraphicsDevice.Viewport);

            player = new Player(new Vector2(96, 96));

            base.Initialize();
        }
Example #2
0
        public void Update(GameTime theGameTime, KeyboardState currentKeyboardState, KeyboardState oldKeyboardState, 
                           List<Tile> tiles, MouseState mouseState, MouseState oldMouseState, Camera camera)
        {
            Vector2 destination = Vector2.Zero;

            if(mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton != ButtonState.Pressed)
            {
                 destination = new Vector2(mouseState.X + camera.Origin.X, mouseState.Y + camera.Origin.Y);
            }

            if (destination != Vector2.Zero)
            {
                Tile start = tiles.Where(tile => tile.TileRectangle.Intersects(PlayerRectangle2)).ToList()[0];
                Tile des = tiles.Where(tile => tile.TileRectangle.Intersects(new Rectangle((int)destination.X, (int)destination.Y, 2, 2))).ToList()[0];

                if (des.TileType != 1) return;

                path = PathFinder.FindPath(start, des, tiles.Where(tile => tile.TileType == 1).ToList());
            }

            if(path.Count > 0)
            {
                UpdateMovement(path, theGameTime);
            }

            oldMovingDirection = currentMovingDirection;
        }